int number_of_students, new_number_of_students;
students std[20], mstud[20];
getch();
clrscr();
cout<< "Enter number of students in group: "<<endl;
cin>> number_of_students ;
for(int i= 0; i < number_of_students; i++ )
{ for(int j=0;j<20;j++)
std[i].name[j]=' ';
cout<< "Name: ";
cin>> std[i].name;
cout<< "Gender: " ;
cin>> std[i].gender ;
cout<< "Finish: ";
cin>>std[i].finish;
cout<< "From: " ;
cin>>std[i].from ;
cout<< "Birth date (dd mm yyyy): " <<endl;
cout<<" day ";
cin>>std[i].born.day;
cout<< " month ";
cin>> std[i].born.month;
cout<<" year ";
cin>>std[i].born.year;
std[i].summ_marks=0;
cout<< "Enter marks (4 integers from 3 to 5): " ;
for( j= 0; j < 4; j++ )
{ cin>> std[i].marks[j];
std[i].summ_marks += std[i].marks[j];
}
}
Func func;
clrscr();
cout<<endl<<"ishodnbIi spisok"<<endl;
func.vivod(std, number_of_students);
func.s (std, mstud, number_of_students, &new_number_of_students);
cout << endl << endl <<"Spisok inogorodnix zhenshin: " << endl;
func.vivod(mstud, new_number_of_students);
func.s (mstud,new_number_of_students);
cout << endl << endl << "Spisok otsortirovannbIi po vozrostaniu:" << endl;
func.vivod(mstud, new_number_of_students);
getch();
clrscr();
void Func::vivod( students mstud[], int new_number_of_students)
{
if (new_number_of_students!=0)
{ cout<<"| Name |gender|finish|from |born(dd mm yyyy)|marks( 1 2 3 4 )|"<<endl;
cout<<"|____________________|______|______|_____|_______________|________________|"<<endl;
for(int i=0; i<new_number_of_students;i++)
{ cout<<"|"
<<setw(15)<< mstud[i].name
<<setw(6)<<"|"<<mstud[i].gender <<setw(6)<<"|"<< mstud[i].finish <<setw(6)<<"|"<< mstud[i].from <<setw(5)<<"|"<< mstud[i].born.day<<setw(2)<<" "<<mstud[i].born.month <<setw(2)<<" "<<mstud[i].born.year <<setw(4)<<"|"<<mstud[i].marks[0] <<setw(2)<<" "<<mstud[i].marks[1] <<setw(2)<<" "<<mstud[i].marks[2] <<setw(2)<<" "<<mstud[i].marks[3]<<setw(7)<<"|"<<endl;
}
}
else{
cout<<"\n spisok pyst "<<endl;
getch();
}
}
void Func::s (students std[], students mstud[], int number_of_students, int *new_number_of_students)
{
int i, n;
n=0;
for( i= 0; i < number_of_students; i++ )
{
if((std[i].gender=='f') && (std[i].from=='i'))
{
mstud[n]=std[i];
n++;
}
}
*new_number_of_students=n;
}
void Func::s (students mstud[], int new_number_of_students)
{students st;
int i, j;
for(i=0; i < new_number_of_students-1; i++ )
{
for(j=i+1; j<new_number_of_students;j++)
{ if(mstud[j].summ_marks<mstud[j].summ_marks);
{ st=mstud[i];
mstud[i]=mstud[j];
mstud[j]=st;
}
{
}
}
Задание№3;перегрузка оператора+=
Программа:
include <iostream.h>
#include <iomanip.h>
#include <conio.h>
#include <string.h>
class date
{
public:
int year, month, day;
} ;
class students
{public:
char name[20], gender, finish,from;
date born;
int marks[4];
students(){cout << "Constructor"<< endl;};
~students(){};
int summ_marks;
} ;
class Func
{
public:
void vivod (students mstud[], int new_number_of_students);
void s (students std[], students mstud[], int number_of_students, int *new_number_of_students);
void operator += (int new_number_of_students);
void s (students mstud[], int new_number_of_students);
}fun;
void main()
{ clrscr();
int number_of_students, new_number_of_students;
students std[20], mstud[20];
getch();
clrscr();
cout<< "Enter number of students in group: "<<endl;
cin>> number_of_students ;
for(int i= 0; i < number_of_students; i++ )
{ for(int j=0;j<20;j++)
std[i].name[j]=' ';
cout<< "Name: ";
cin>> std[i].name;
cout<< "Gender: " ;
cin>> std[i].gender ;
cout<< "Finish: ";
cin>>std[i].finish;
cout<< "From: " ;
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.