Разработка программы с функцией сортировки данных. Введение в программу класс функций, конструктор, деструктор и перегрузку функций, страница 3

                              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];

                              }

}

               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 mestn#x zakonhivwix wkoly: " << endl;

               func.vivod(mstud, new_number_of_students);

func.operator +=  ( new_number_of_students);

               func.s (mstud,new_number_of_students);

               cout << endl << endl << "Spisok otsortirovannbIi po yb#vaniu :" << 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<<"              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].finish=='s') &&  (std[i].from=='s'))

                                                           {

                                                                  mstud[n]=std[i];

                                                                          n++;

                                                           }

               }

 *new_number_of_students=n;

}

void Func::operator +=  ( int new_number_of_students)

{int i,j;

  students *mstud;

for(i= 0; i <new_number_of_students; i++ )

               {

               mstud[i].summ_marks=0;

                              for( j= 0; j < 4; j++ )

                              {

                                            mstud[i].summ_marks += mstud[i].marks[j];

                   }

  cout<<mstud[i].summ_marks<<endl;

               }

}

void Func::s (students mstud[], int new_number_of_students)

{students st;

               int i, j;

               for(i=0; i < new_number_of_students; i++ )

               {

                      for(j=i+1; j<new_number_of_students-1;j++)

                      {       if(mstud[j-1].summ_marks>mstud[j].summ_marks);

                                            {             st=mstud[i];

                                                           mstud[i]=mstud[j];

                                                           mstud[j]=st;

                                            }

                      }

                  }

               }

Задание№4:Наследование

Создается класс bokal в нем описывается переменные vlitr, material и функция void litrazh, создаем класс

Model (переменная vid и функция void vbIvid с переменной у), из класса Model создается производный класс boc(добавляется переменные cvet, ryhka), после создается последний производный класс got(из класса Model и bokal),

В котором выполняется функция считающай цену продукта и функция вывода.

Программа:

#include<IOSTREAM.h>

#include <string.h>

#include<iomanip.h>

#include<conio.h>

class bokal

{

public:

               void litrazh(int x);

int vlitr(){return litri;}

char material[15];

               int litri;

};

class model

{

public:

void vbIvid(int y);

int vid;

} ;

class boc: public model

{

public:

               char [7];

char ryhka[5];

};

class got: public boc, public bokal

{

public: int cena;

void stoim()

{

int x,y,z;

cena=0;

x = *ryhka=='y' ? 8 : 0;

y = *material=='s' ?  70 : 100;

cena= x+y;

};

void vivod(){   cout<<"bokal"<<endl;

cout<<"| cvet: "<<cvet<<" | vid: "<<vvid()<<" | ryhka: "<<ryhka<<" | Material: "<<material<<" | Emkost: "<<vlitr()<<"ml"<<" |"<<endl;

cout<<"stoimost prodykta:"<<cena<<"rub"<<endl;

}

};

void main()

{

got bok;

int x,y,ryhka,material1;

               clrscr();

               cout<<"Cvet:";

               cin>>bok.cvet;

cout<<"vid:";

               cin>>y;

               bok.vbIvid(y);

               cout<<"ryhka:";

               cin>>bok.ryhka;

               cout<<"Material:";

               cin>>bok.material;

               //strcpy(mine.material,material1);

               cout<<"Emcost:";

               cin>>x;

               bok.litrazh(x);

               cout<<" "<<endl;

               bok.stoim();

               bok.vivod();

               getch();

}

void bokal::litrazh(int x)

{litri=x;}

void model::vbIvid(int y){vid=y;}