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

Автор работы: Пользователь скрыл имя, 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.fill('-');

     cout<<setw(61)<<"-" << endl;

     cout.fill(' ');

}

  

  

int main (void)

{

    Product prod, *tek;

    Meat z1;

    Milk z2;

    Broat z3;

    Drink z4;

    Tinned z5;

    string n, s;

    int pl, pt;

    int a, b, c, i, k, num, ans, kol=0;

   

    list<Product> spis;

list<Product>::iterator pos,vsp;

 

    while (1)

    {

          Menu ();

          cout << "\nChange action: " ;

          cin >> num;

          switch (num)

          {

                 case 0:

                      {

                           exit(0);

                      };

                 case 1:

                      {

                           system("cls");

                           cout << setw(65) << "***Creating new BD***" << endl;

                           while (1)

                           {

                                 cout << "\nEnter the name: " ;

                                 cin >> n;

                                 prod.addName(n);

                                 cout << "Enter price: " ;

                                 cin >> pl;

                                 prod.addSale(pl);

                                 cout << "Enter number of product: " ;

                                 cin >> pt;

                                 prod.addNum(pt);

                                 do

                                 {

                                                   cout << "1 - Meat, 2 - Milk, 3 - Broat, 4-Drink, 5-Tinned: " ;

                                                   cin >> i;

                                 }  while (   !((i>0)&&(i<6))  ) ;

                           

                                 if (i==1) prod.addGroup(z1.getGroup());

                                 if (i==2) prod.addGroup(z2.getGroup());

                                 if (i==3) prod.addGroup(z3.getGroup());

                                 if (i==4) prod.addGroup(z4.getGroup());

                                 if (i==5) prod.addGroup(z5.getGroup());

                                 tek = new Product(n, pl, pt, i);

                                 spis.push_back(*tek);

                                 kol++;

                                 cout << "Continue? (1 - Yes/ 2 - No)? " ;

                                 cin >> ans;

                                 if (ans==2)  break;

                           }

                           break;

                      };

                 case 2:

                      {

                          system("cls");

                          string str, str1;

                          ifstream file("Product.csv");

                          if (!file)

                          {

                                     cout << "!File not found!" ;

                                     getch();

                                     break;

                          }

                                     else

                                     {

                                       while(!file.eof()) 

                                       {

                                                           getline(file,str);

                                                           if (str=="") break;

                                                           str1=(str.substr(0,str.find(";")));                        

                                                           n=str1.c_str();                                          

                                                           str.erase(0,str.find(";")+1);                            

                                                           str1=str.substr(0,str.find(";"));                          

                                                           pl=atoi(str1.c_str());                                       

                                                           str.erase(0,str.find(";")+1);

                                                           str1=str.substr(0,str.find(";"));                         

                                                           pt=atoi(str1.c_str());                                       

                                                           str.erase(0,str.find(";")+1);

                                                           str1=str.substr(0,1);                                       

                                                           i=atoi(str1.c_str());                                           

                                                           tek = new Product(n, pl, pt, i);

                                                           spis.push_back(*tek);

                                                           kol++;

                                       }

                                     }

                                    

                                    

                                      

                          file.close();

                          cout << "Complete!";

                          getch();

                          break;

                      }

                 case 3:

                      {

                           system("cls");

                           if (spis.empty())

                              {

                                   cout << "!!!Records not found!!!" ;

                                   getch();

                                   break;

                                   }

                                   else

                                        {

                                                 ofstream file("Product.csv");

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

                                                 {

                                                      file << pos->getName() << ";" << pos->getSale() << ";" << pos->getNum() << ";" << pos->getGroup() << endl;

                                                 }

                                                 cout << "Done!" ;

                                                 file.close();

                                                 getch();

                                                 break;

                                    }

                      };

                 case 4:

                      {

                           system("cls");

                           if (spis.empty())

                           {

                               cout << "!!!Records not found!!!" ;

                               getch();

                              break;

                           }

                                     else

                                     {

                                         cout << "\nYou want delete all? (1 - Yes/ 2 - No)? " ;

                                         cin >> ans;

                                         if (ans==1) spis.clear();

                                         cout << "!!!Complete!!!";

                                         getch();

                                         break;

                                         }

                      };

                 case 5:

                      {

                           system("cls");

                           if ((spis.empty()) || (kol==0))

                           {

                               cout << "Records not found" ;

                               getch();

                               break;

                           }

                                     else

                                     {

                                         Line();

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

                                     Line();

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

                                             {

                                             k=pos->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 << pos->getName() << "|" << setw(6) << right << pos->getSale() << " |" << setw(8)  << pos->getNum() << " | " << setw(15)<<left<< s << "|" << endl;

                                             Line();

                                             }

                                      };

                           getch();

                           break;

                      };

                case 6:

                      {

                           system("cls");

                           pos=spis.end();

                           while (1)

                           {

                                cout << "\nEnter the name: " ;

                                 cin >> n;

                                 prod.addName(n);

                                 cout << "Enter price: " ;

                                 cin >> pl;

                                 prod.addSale(pl);

                                 cout << "Enter number of product: " ;

                                 cin >> pt;

                                 prod.addNum(pt);

                                 do

                                 {

                                                   cout << "1 - Meat, 2 - Milk, 3 - Broat, 4-Drink, 5-Tinned: " ;

                                                   cin >> i;

                                 }  while (   !((i>0)&&(i<6))  ) ;

                           

                                 if (i==1) prod.addGroup(z1.getGroup());

                                 if (i==2) prod.addGroup(z2.getGroup());

                                 if (i==3) prod.addGroup(z3.getGroup());

                                 if (i==4) prod.addGroup(z4.getGroup());

                                 if (i==5) prod.addGroup(z5.getGroup());

                                 tek = new Product(n, pl, pt, i);

                                 spis.push_back(*tek);

                                 kol++;

                                 cout << "Continue? (1 - Yes/ 2 - No)? " ;

                                 cin >> ans;

                                 if (ans==2)  break;

                           }

                           break;

                      };

                 case 7:

                       {

                            if (spis.empty())

                           {

                               system("cls");

                               cout << "Records not found!" ;

                               getch();

                               break;

                           }

                            else

                            {

                            while (1)

                            {

                                  system("cls");

                                  pos=spis.begin();

                                  cout << "Enter number of record: " ;

                                  cin >> i;

                                  if (i>kol)  cout << "Not found" << endl;

                                     else

                                          {

                                              cout << endl;

                                              advance(pos, i-1);          //переход на элемент pos

                                              Line();

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

                                          Line();

                                               k=pos->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 << pos->getName() << "|" << setw(6) << right << pos->getSale() << " |" << setw(8)  << pos->getNum() << " | " << setw(15)<<left<< s << "|" << endl;

                                             Line();

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