Advertisement
Guest User

Untitled

a guest
Dec 27th, 2010
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 KB | None | 0 0
  1. #include "Cell.h"
  2. #include <fstream>
  3.  
  4. int menu();
  5.  
  6. void AddCell(Cell cell[],int &nrOfCells);
  7. void showAll(Cell cell[],int nrOfCells);
  8. int showExp(Cell cell[],int nrOfCells);
  9. int showAllTouch(Cell cell[],int nrOfCells);
  10. int showDesigns(Cell cell[],int nrOfCells);
  11. void showModelsSorted(Cell cell[],int nrOfCells);
  12. void saveToFile(Cell cell[],int nrOfCells);
  13. void showTouch();
  14. void showDesign();
  15. int main()
  16. {
  17.     _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  18.     Cell *cell=NULL;
  19.     int capacity=0, choice=0;
  20.     int nrOfCells=0;
  21.     cell=new Cell[capacity];
  22.  
  23.  
  24.     cout<<"How many phone slots do you need?";
  25.     cin>>capacity;
  26.  
  27.  
  28.     choice=menu();
  29.  
  30.     while(choice!=0)
  31.     {
  32.        
  33.     switch (choice)
  34.     {
  35.     case 1: AddCell(cell, nrOfCells);
  36.         break;
  37.     case 2: showAll(cell,nrOfCells);
  38.         break;
  39.     case 3: showExp(cell, nrOfCells);
  40.         break;
  41.     case 4: showAllTouch(cell, nrOfCells);
  42.         break;
  43.     case 5: showDesigns(cell, nrOfCells);
  44.         break;
  45.     case 6: showModelsSorted(cell, nrOfCells);
  46.         break;
  47.     case 7: saveToFile(cell, nrOfCells);
  48.         break;
  49.     }
  50.  
  51.     }
  52.  
  53.         return 0;
  54.     }
  55.  
  56. void AddCell(Cell cell[],int &nrOfCells)
  57. {
  58.     string theName="";
  59.     string theDesign="";
  60.     string theTouch="";
  61.     int thePrice=0;
  62.  
  63.     cout<<"Model: ";
  64.     cin>>theName;
  65.     cout<<"Design: ";
  66.     cin>>theDesign;
  67.     cout<<"Touch: ";
  68.     cin>>theTouch;
  69.     cout<<"Price: ";
  70.     cin>>thePrice;
  71.     cell[nrOfCells]=Cell(theName,thePrice,theDesign,theTouch);
  72.     nrOfCells++;
  73. }
  74.  
  75.  
  76. void showAll(Cell cell[], int nrOfCells)
  77. {
  78.     for(int i=0; i<nrOfCells;i++)
  79.     {
  80.         cell[i].show();
  81.     }
  82. }
  83.  
  84. int showExp(Cell cell[], int nrOfCells)
  85. {
  86.     int expPos=0;
  87.     int highPrice=0;
  88.     for(int i=0;i<nrOfCells;i++)
  89.     {
  90.         if(cell[i].getPrice()>highPrice)
  91.         {
  92.             highPrice=cell[i].getPrice();
  93.             expPos=i;
  94.         }
  95.     }
  96.     return expPos;
  97. }
  98.        
  99. int showAllTouch(Cell cell[],int nrOfCells)
  100. {
  101.     string touch="yes";
  102.     cout<<"The following cellphones have touch";
  103.     for(int i=0;i<nrOfCells;i++)
  104.     {
  105.         if(cell[i].getTouch()==touch)
  106.         {
  107.             showTouch();
  108.         }
  109.     }
  110. }
  111.  
  112. int showDesigns(Cell cell[], int nrOfCells)
  113. {
  114.     string choice=" ";
  115.     cout<<"What design are you interested in? (slide, standard, flip)";
  116.     cin>>choice;
  117.     for(int i=0;i<nrOfCells;i++)
  118.     {
  119.         if(cell[i].getDesign()==choice)
  120.             showDesign;
  121.     }  
  122. }
  123.  
  124. void showModelSorted(Cell cell[], int nrOfCells)
  125. {
  126.     Cell temp;
  127.     int i;
  128.     for(i=1;i<nrOfCells;i++)
  129.     {
  130.         temp=cell[i];
  131.         int j;
  132.         for(j=i-1;j>=0 && temp<cell[j];j--)
  133.         {
  134.             cell[j+1]=cell[j];
  135.         }
  136.     cell[j+1]=temp;
  137.     }
  138.     for(i=0;i<nrOfCells;i++)
  139.     {
  140.         cout<<cell[i].getName()<<" ";
  141.     }
  142.         cout<<endl;
  143.    
  144. }
  145.  
  146. void saveToFile(Cell cell[], int nrOfCells)
  147. {
  148.     ofstream outputFile;
  149.     outputFile.open("Cellphones.txt");
  150.     outputFile<<cell;
  151.     outputFile.close();
  152.     cout<<"The Cell Phones have been saved to Cellphones.txt";
  153. }
  154.  
  155. int menu()
  156. {
  157.     cout<<"1. Add new Cellphone. ";
  158.     cout<<"2. Show all Cellphones. ";
  159.     cout<<"3. Show the most expensive one.";
  160.     cout<<"4. Show all phones with touch screen. ";
  161.     cout<<"5. Show the design of the phones. ";
  162.     cout<<"6. Show all phones sorted in alphabetical order. ";
  163.     cout<<"7. Save to file. ";
  164.     cout<<"0. Quit. ";
  165.     cin<<choice;
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement