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

Страницы работы

8 страниц (Word-файл)

Содержание работы

Санкт-Петербургский государственный университет

Аэрокосмического приборостроения

Кафедра №41

Работу проверил

преподователь:                                                                                            Козенко С.Л.

Отчет :

О лабораторных работах

По курсу “Лингвистическое и программное обеспечение САПР”

САПР230104.11

Работу выполнил

студент гр1617                                                                                             Семенов С.В.

Санкт Петербург

2008

Работа №1:Ввести исходный список людей, отобрать иногородних женщин. Упорядочить их по убыванию суммы баллов.

Программа:

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

               int summ_marks;

} ;

void print_spisok( students  mstud[], int new_number_of_students);

void main()

{

               int i, j, number_of_students, new_number_of_students;

               students  std[20],  mstud[20],  st;

               clrscr();

               cout<< "Enter number of students in group: ";

               cin>> number_of_students ;

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

               {       for(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];

                              }

               }

         cout<< " v#vodim spisok:"<<endl;

 print_spisok( std, number_of_students);

new_number_of_students=0;

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

               {

               if((std[i].gender=='f') &&  (std[i].from=='i'))

               {

                                                                          mstud[new_number_of_students]=std[i];

                                                                          new_number_of_students++;

               }

   }

cout<< " otobrannbIi spisok:"<<endl;

               print_spisok( mstud, new_number_of_students);

               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;

                                            }

                      {

               }

        cout<< " otsortirovann#i spisok:"<<endl;

print_spisok( mstud, new_number_of_students);

 getch();

               return;

       }

    }

}

void print_spisok( 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();

               }

  }

Задание№2:Ввести в предыдущей программе класс функций, конструктор, деструктор и перегрузку функций.

Программа:

#include <iostream.h>

#include <iomanip.h>

#include <conio.h>

#include <string.h>

class date

{

               public:

               int year, month, day;

} ;

  class students

{

               public:

               int idx;

               char name[20], gender, finish,from;

               date  born;

               int marks[4];

               students(){cout << "Constructor"<< endl;};

               ~students();

               void

               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 s (students mstud[], int new_number_of_students);

               }fun;

void main()

{       clrscr();

Похожие материалы

Информация о работе