Управление массивом указателей средствами объектно-ориентированного программирования

Автор работы: Пользователь скрыл имя, 21 Мая 2013 в 09:55, курсовая работа

Краткое описание

Целью данной курсовой работы является формирование массива указателей и последующая работа с ними. Для того, чтобы выполнить задание необходимо разработать программный комплекс по обработке множества данных (товары в продуктовом магазине).

Содержание

Введение 3
1 Структура программы и описание модулей 4
1.1 Описание главной функции программы и перечень модулей 4
1.1.1 Функция void Line() 4
1.2 Модуль cls1.cpp 4
1.3 Модуль cls2.cpp 6
2 Работа программы по контрольному примеру 8
2.1 Запуск программы 8
2.2 Пункт меню “New BD” 8
2.3 Просмотр данных “Full view” 9
2.4 Добавление элементов «Add data» 9
2.5 Просмотр элемента по номеру “Show by number” 10
2.6 Выбор минимального элемента «Show minimal». 11
2.7 Поиск максимального элемента «Show maximal» 12
2.8 Сохранение данных на компьютер “Save in file” 12
2.9 Удаление всех данных “Delete data” 12
2.10 Открытие данных, сохраненных на компьютере “Open database” 13
Заключение 14

Прикрепленные файлы: 1 файл

Otchet_1.doc

— 774.50 Кб (Скачать документ)

                                         }

                                  cout << "\nContinue searching? (1 - Yes/ 2 - No)? " ;

                                  cin >> ans;

                                  if (ans==2)   break;

                                  }

                            break;

                            }

                      };

                 case 8:

                      {

                            system("cls");

                            int min, vsp1;

                            if (spis.empty())

                           {

                               system("cls");

                               cout << "Records not found!" ;

                               getch();

                               break;

                           }

                            else

                            {

                                  pos=spis.begin();

                                  min=pos->getNum();

                                  for (pos=spis.begin(),a=1; pos!=spis.end(); pos++,a++ )

                                             {

                                                             vsp1=pos->getNum();

                                                             if (min>vsp1)

                                                             {

                                                                          min=vsp1;

                                                                          vsp=pos;

                                                             };

                                             };

                                  cout<<"Minimal element by number :"<<endl;

                                   Line();

                                   cout << "|Num| Name                | Sale  | Number  | Group          |" << endl;

                                   Line();

                                   k=vsp->getGroup();

                                   if(k==1) s=z1.getGr();

                               if(k==2) s=z2.getGr();

                               if(k==3) s=z3.getGr();

                               if(k==4) s=z4.getGr();

                              if(k==5) s=z5.getGr();

                                   cout << "|" << setw(3)<<left  << a <<"| " << setw(20) << left << vsp->getName() << "|" << setw(6) << right << vsp->getSale() << " |" << setw(8)  << vsp->getNum() << " | " << setw(15)<<left<< s << "|" << endl;

                                   Line();

                            };

                            getch();

                            break;

                      };

 

                      case 9:

                           {

                              system("cls");

                              int max, vsp1;

                              if (spis.empty())

                              {

                               system("cls");

                               cout << "Records not found!" ;

                               getch();

                               break;

                               }

                            else

                            {

                                  pos=spis.begin();

                                  max=pos->getNum();

                                  for (pos=spis.begin(),a=1; pos!=spis.end(); pos++,a++ )

                                             {

                                                             vsp1=pos->getNum();

                                                             if (max<vsp1)

                                                             {

                                                                          max=vsp1;

                                                                          vsp=pos;

                                                             };

                                             };

                                  cout<<"Maximal element by number :"<<endl;

                                   Line();

                                   cout << "|Num| Name                | Sale  | Number  | Group          |" << endl;

                                   Line();

                                   k=vsp->getGroup();

                                   if(k==1) s=z1.getGr();

                               if(k==2) s=z2.getGr();

                               if(k==3) s=z3.getGr();

                               if(k==4) s=z4.getGr();

                               if(k==5) s=z5.getGr();

                                   cout << "|" << setw(3)<<left  << a <<"| " << setw(20) << left << vsp->getName() << "|" << setw(6) << right << vsp->getSale() << " |" << setw(8)  << vsp->getNum() << " | " << setw(15)<<left<< s << "|" << endl;

                                   Line();

                            };

                            getch();

                            break;

                            };

                           

                 default:

                         {

                                   cout << "\n EROR IN ACTION!" ;

                                   getch();

                         }

          };

    };

};

 

 

//модуль Cls1.cpp

#include <iostream>

#include <stdio.h>

#include <string>

#define MAX 30

 

using namespace std;

 

class Product

{

      private:

              string name;

              int  sale;

              int num;

              int group;

      public:

             Product ()

             {

                  name="none";

                  sale=0;

                  num=0;

                  group=0;

             }

           

             Product (string name, int sale, int  num, int group)

             {

                  this->name=name;

                  this->sale=sale;

                  this->num=num;

                  this->group=group;

             }

 

             virtual ~Product(){};       

            

      virtual void addName(string name)

{

this->name=name;

}

 

        virtual void addSale(int sale)

{

this->sale=sale;

}

 

        virtual void addNum(int num)

{

this->num=num;

}

 

        virtual void addGroup(int group)

{

this->group=group;

}

 

        virtual string getName()

{

return name;

}

virtual int getSale()

{

return sale;

}

virtual int getNum()

{

return num;

}

int getGroup()

{

            return group;

            }

 

};     

                 

class Meat : public Product

{

private:

string name;

int sale;

int num;

int group;

string gr1;

public:

Meat()

{

name="none";

            sale=0;

            num=0;

gr1="Meat";

}

 

        Meat(string name, int sale, int num)

{

this->name=name;

this->sale=sale;

this->num=num;

}

 

        virtual int getGroup()

{

return 1;

}

 

virtual string getGr()

{

return gr1;

}

 

};           

 

class Milk : public Product

{

private:

string name;

int sale;

int num;

int group;

string gr2;

public:

Milk()

{

name="none";

            sale=0;

            num=0;

gr2="Milk";

}

 

        Milk(string name, int sale, int num)

{

this->name=name;

this->sale=sale;

this->num=num;

}

 

        virtual int getNum()

{

return 2;

}

 

virtual string getGr()

{

return gr2;

}

 

};

 

class Broat : public Product

{

private:

string name;

int sale;

int num;

int group;

string gr3;

public:

Broat()

{

name="none";

            sale=0;

            num=0;

gr3="Broat";

}

 

         Broat(string name, int sale, int num)

{

this->name=name;

this->sale=sale;

this->num=num;

}

 

        virtual int getGroup()

{

return 3;

}

 

virtual string getGr()

{

return gr3;

}

  };

  class Drink : public Product

{

private:

string name;

int sale;

int num;

int group;

string gr4;

public:

Drink()

{

name="none";

            sale=0;

            num=0;

gr4="Drink";

}

 

        Drink(string name, int sale, int num)

{

this->name=name;

this->sale=sale;

this->num=num;

}

 

        virtual int getGroup()

{

return 4;

}

 

virtual string getGr()

{

return gr4;

}

  };

  class Tinned : public Product

{

private:

string name;

int sale;

int num;

int group;

string gr5;

public:

Tinned()

{

name="none";

            sale=0;

            num=0;

gr5="Tinned";

}

 

        Tinned (string name, int sale, int num)

{

this->name=name;

this->sale=sale;

this->num=num;

}

 

        virtual int getGroup()

{

return 5;

}

 

virtual string getGr()

{

return gr5;

}

  };

 

Приложение В

Ниже на рисунке 3 представлена диаграмма отношения классов.

 

Рисунок 15  – Диаграмма


Информация о работе Управление массивом указателей средствами объектно-ориентированного программирования