bsuir.info
БГУИР: Дистанционное и заочное обучение
(файловый архив)
Вход (быстрый)
Регистрация
Категории каталога
Другое [157]
АВС [6]
КПиЯП [80]
ОАиП [305]
ОКТ [79]
СиСПО [8]
Форма входа
Логин:
Пароль:
Поиск
Статистика

Онлайн всего: 1
Гостей: 1
Пользователей: 0
Файловый архив
Файлы » ПОИТ » КПиЯП

Контрольная работа №1 В5 files competition
Подробности о скачивании 02.02.2010, 12:10
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <list>

#define MAX 50

using namespace std;

enum Instruments {guitar = 1, piano, violin, violoncello};

struct Competitors
{
char fio[255];
int year;
char country[255];
Instruments instrum;
int place;
};

Instruments ChooseInst(int);
char* PrintInstrum(int);

void sort(list<struct Competitors> * arr)
{
list<struct Competitors>::iterator it, it2;
for(it = arr->begin(); it != arr->end(); it++)
{
for(it2 = (++arr->begin()); it2 != arr->end(); it2++)
if (it->place > it2->place)
{
char str[1024];
strcpy(str,it->fio);
strcpy(it->fio,it2->fio);
strcpy(it2->fio,str);

strcpy(str,it->country);
strcpy(it->country,it2->country);
strcpy(it2->country,str);

int i = it->place;
it->place = it2->place;
it2->place = i;

i = it->year;
it->year = it2->year;
it2->year = i;

i = (int)it->instrum;
it->instrum = it2->instrum;
it2->instrum = (Instruments)i;
}
}

for(it = arr->begin(); it != arr->end(); it++)
{
for(it2 = (++arr->begin()); it2 != arr->end(); it2++)
if (it->place <= it2->place)
{
if (it->instrum > it2->instrum)
{
char str[1024];
strcpy(str,it->fio);
strcpy(it->fio,it2->fio);
strcpy(it2->fio,str);

strcpy(str,it->country);
strcpy(it->country,it2->country);
strcpy(it2->country,str);

int i = it->place;
it->place = it2->place;
it2->place = i;

i = it->year;
it->year = it2->year;
it2->year = i;

i = (int)it->instrum;
it->instrum = it2->instrum;
it2->instrum = (Instruments)i;
}
}
}
}

int _tmain(int argc, _TCHAR* argv[])
{
list<struct Competitors> lCompetitor;
int count = 0;

Competitors pCompetitor;
bool next = true;
try
{
while (next)
{
char str[1024];
cout << "Enter fullname: ";
scanf("%s",&str);
strcpy(pCompetitor.fio,str);
cout << "Enter country: ";
scanf("%s",&str);
strcpy(pCompetitor.country,str);
cout << "Enter year of a birth: ";
cin >> pCompetitor.year;
cout << "Choose instrum (1-guitar, 2-piano, 3-violin, 4-violoncello): ";
int k;
cin >> k;
pCompetitor.instrum = ChooseInst(k);

cout << "\n" << "Do you want enter next competitor?[Y\\N]";
char ch;
cin >> ch;
lCompetitor.push_back(pCompetitor);
if ((ch == 'N') || (ch == 'n'))
break;

}
list<struct Competitors>::iterator it;

int i = 1;

for(it = lCompetitor.begin();it != lCompetitor.end();it++)
{
printf("Competitor %s get place number: ",it->fio);
cin >> it->place;
printf("Congratulation with place number: %d\n\n",it->place);
}
int year;
printf("Enter year limit: ");
scanf("%d",&year);
printf("Result:\n");
sort(&lCompetitor);
printf("Place| Full name |Year| Country | Instrument |\n");
for(it = lCompetitor.begin();it != lCompetitor.end();it++)
{
if (it->year <= year)
{
printf("%5d|",it->place);
printf("%26s|",it->fio);
printf("%4d|",it->year);
printf("%17s|",it->country);
printf("%20s|\n",PrintInstrum(it->instrum));
}
}
}
catch(char * str )
{
cout << "Exception raised: " << str << '\n';
}
return 0;
}

Instruments ChooseInst(int idx)
{
switch(idx)
{
case guitar:
return guitar;
case piano:
return piano;
case violin:
return violin;
case violoncello:
return violoncello;
}
return (Instruments)0;
}

char* PrintInstrum(int idx)
{
switch(idx)
{
case guitar:
return "guitar";
case piano:
return "piano";
case violin:
return "violin";
case violoncello:
return "violoncello";
default:
return "none";
}
}

Категория: КПиЯП | Добавил: CTARIK
Просмотров: 954 | Загрузок: 14
Всего комментариев: 0
Добавлять комментарии могут только зарегистрированные пользователи.
[ Регистрация | Вход ]