Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Cell.h"
- #include <fstream>
- int menu();
- void AddCell(Cell cell[],int &nrOfCells);
- void showAll(Cell cell[],int nrOfCells);
- int showExp(Cell cell[],int nrOfCells);
- int showAllTouch(Cell cell[],int nrOfCells);
- int showDesigns(Cell cell[],int nrOfCells);
- void showModelsSorted(Cell cell[],int nrOfCells);
- void saveToFile(Cell cell[],int nrOfCells);
- void showTouch();
- void showDesign();
- int main()
- {
- _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
- Cell *cell=NULL;
- int capacity=0, choice=0;
- int nrOfCells=0;
- cell=new Cell[capacity];
- cout<<"How many phone slots do you need?";
- cin>>capacity;
- choice=menu();
- while(choice!=0)
- {
- switch (choice)
- {
- case 1: AddCell(cell, nrOfCells);
- break;
- case 2: showAll(cell,nrOfCells);
- break;
- case 3: showExp(cell, nrOfCells);
- break;
- case 4: showAllTouch(cell, nrOfCells);
- break;
- case 5: showDesigns(cell, nrOfCells);
- break;
- case 6: showModelsSorted(cell, nrOfCells);
- break;
- case 7: saveToFile(cell, nrOfCells);
- break;
- }
- }
- return 0;
- }
- void AddCell(Cell cell[],int &nrOfCells)
- {
- string theName="";
- string theDesign="";
- string theTouch="";
- int thePrice=0;
- cout<<"Model: ";
- cin>>theName;
- cout<<"Design: ";
- cin>>theDesign;
- cout<<"Touch: ";
- cin>>theTouch;
- cout<<"Price: ";
- cin>>thePrice;
- cell[nrOfCells]=Cell(theName,thePrice,theDesign,theTouch);
- nrOfCells++;
- }
- void showAll(Cell cell[], int nrOfCells)
- {
- for(int i=0; i<nrOfCells;i++)
- {
- cell[i].show();
- }
- }
- int showExp(Cell cell[], int nrOfCells)
- {
- int expPos=0;
- int highPrice=0;
- for(int i=0;i<nrOfCells;i++)
- {
- if(cell[i].getPrice()>highPrice)
- {
- highPrice=cell[i].getPrice();
- expPos=i;
- }
- }
- return expPos;
- }
- int showAllTouch(Cell cell[],int nrOfCells)
- {
- string touch="yes";
- cout<<"The following cellphones have touch";
- for(int i=0;i<nrOfCells;i++)
- {
- if(cell[i].getTouch()==touch)
- {
- showTouch();
- }
- }
- }
- int showDesigns(Cell cell[], int nrOfCells)
- {
- string choice=" ";
- cout<<"What design are you interested in? (slide, standard, flip)";
- cin>>choice;
- for(int i=0;i<nrOfCells;i++)
- {
- if(cell[i].getDesign()==choice)
- showDesign;
- }
- }
- void showModelSorted(Cell cell[], int nrOfCells)
- {
- Cell temp;
- int i;
- for(i=1;i<nrOfCells;i++)
- {
- temp=cell[i];
- int j;
- for(j=i-1;j>=0 && temp<cell[j];j--)
- {
- cell[j+1]=cell[j];
- }
- cell[j+1]=temp;
- }
- for(i=0;i<nrOfCells;i++)
- {
- cout<<cell[i].getName()<<" ";
- }
- cout<<endl;
- }
- void saveToFile(Cell cell[], int nrOfCells)
- {
- ofstream outputFile;
- outputFile.open("Cellphones.txt");
- outputFile<<cell;
- outputFile.close();
- cout<<"The Cell Phones have been saved to Cellphones.txt";
- }
- int menu()
- {
- cout<<"1. Add new Cellphone. ";
- cout<<"2. Show all Cellphones. ";
- cout<<"3. Show the most expensive one.";
- cout<<"4. Show all phones with touch screen. ";
- cout<<"5. Show the design of the phones. ";
- cout<<"6. Show all phones sorted in alphabetical order. ";
- cout<<"7. Save to file. ";
- cout<<"0. Quit. ";
- cin<<choice;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement