Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [![введите сюда описание изображения][1]][1]
- > #include<stdio>
- > #include<conio>
- > #include<cstdio>
- > #include<string>
- > #include<stdlib>
- > #include<iostream>
- > #include<fstream>
- > #include<string>
- >
- > /* Написать программу, в которой необходимо создать структуру, элементами которой являются фамилия студента и оценки. Объявить
- > массив данных о студентах группы типа структуры и ввести значения его
- > элементов. Рассортировать массив структур в алфавитном порядке
- > фамилий, входящих в структуру, перемещая указатели структуры.
- > Предусмотреть меню. Результаты работы программы записать в файл.
- > */
- >
- > struct student{ std::string familia; int estimation;
- >
- > }student_[3];
- >
- > void sortFam(student *stud[]){ int i, j, len, s; student *ran= ( student *) malloc (sizeof(student)); for(i=0; i<3-1; i++) for(j=i+1; j<3; j++){
- > if(stud[i]->familia.length() < stud[j]->familia.length()) len=stud[i]->familia.length(); //Определяем короткое слово
- > else len=stud[j]->familia.length();
- > for(s=0; s<len; s++){
- > if(stud[i]->familia.substr(s, s+1) > stud[j]->familia.substr(s, s+1)){ ran = stud[i];
- > stud[i]=stud[j];
- > stud[j]=ran;
- > break;
- > }
- > else if(stud[i]->familia.substr(s, s+1) == stud[j]->familia.substr(s, s+1)){ continue;
- > }else{ break;
- > }
- > } } } void print_stud(student *stud[]){ int i; for(i=0; i<3; i++)
- > std::cout<<stud[i]->familia<<"n"; } int getFamili(student *stud[], char *fam){ int i; for(i=0; i<3; i++){ if(strcmp(stud[i]->familia.c_str(), fam)) {
- > return 1; } } return 0; }
- >
- > int main(int argc, char* argv[]) { student **stud = new student*[3]; char fam[7], adress[24]={0}; std::string ssd =
- > "C:/test/test.txt" ; int est, i, j, n=1;
- >
- > for(i=0; i<3; i++) {
- > student_[i].familia=""; //Обнуляем
- > student_[i].estimation=0; //Обнуляем
- > std::cout<<"Vvedite Familiu: ";
- > std::cin>>student_[i].familia;
- > std::cout<<"Vvedite ocenku: ";
- > std::cin>>student_[i].estimation;
- > stud[i]=&student_[i]; }
- >
- > std::cout<<"VVedite adres faila: (ne bolee 23 simvolov)"; std::cin>>adress;
- >
- > std::fstream out(adress, std::ios::out | std::ios::binary); if(!out){ std::cout<<"Net takogo faila :("; std::cout<<"Nagmite
- > 0 dlia vihoda:"; std::cin>>n;
- > if(n==0) return 1; }
- >
- >
- > //Менюха while(n!=0){
- > std::cout<<"Vvedite 0 dlia vihoda: n";
- > std::cout<<"Vvedite 1 dlia vivoda dannih: n";
- > std::cout<<"Vvedite 2 dlia sortirovki n";
- > std::cout<<"Vvedite 3 dlia poiska: n";
- > std::cin>>n;
- > switch(n){
- > case 0:
- > return 1;
- > break;
- > case 1:
- > print_stud(stud);
- > break;
- > case 2:
- > sortFam(stud);
- > break;
- > case 3: std::cout<<"Vvedite familiu studenta:";
- > std::cin>>fam;
- > if(getFamili(stud, fam))
- > std::cout<<"Takogo studenta ne obarujeno:";
- > break;
- > default:
- > break;
- > } } for(i=0; i<3; i++){
- > delete [] stud[i]; } delete [] stud;
- >
- > getch();
- > return 0; }
- >
- >
- > [1]: http://i.stack.imgur.co
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement