Advertisement
davsank

Untitled

Apr 24th, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.18 KB | None | 0 0
  1. #include "StatArr.h"
  2. using namespace std;
  3.  
  4.  
  5. int main(void)
  6. {
  7.     int menuChoice,whatObject,arr_size,arr_size2,inputArray[15],
  8.         sortMethod,searchValue,searchIndex,numberToInsert;
  9.     /*
  10.     menuChoice:     holds the menu choice made by the user.
  11.     whatObject:     usually a nseted variable in switch clauses which are entered from the menuChoice variable,
  12.                     holds the number of object on which the operation will be carried out.
  13.     arr_size:       Holds the length for the 2nd object.
  14.     arr_size2:      Holds the length for the 3rd object.
  15.     inputArray:     Holds the array that is copied into the third object.
  16.     sortMethod:     keeps the sorting method for the arrSort method
  17.     searchValue:    keeps the value that is searched in an object.
  18.     searchIndex:    keeps the index that is looked for in an object.
  19.     numberToInsert: keeps the number that is to be inserted into an object.
  20.     */
  21.     cout<<"Welcome to the program! \n\n\nBefor we can begin, I must intianlize the Objects with your help.\nFirst Object is made of 15 randomly selected numbers.\n Program will no radomize numbers for you, One moment please.\n";
  22.     StatArr S1;
  23.     cout<<"Complete!\nFor the second Object, The program will create an array with the size you choose (non negative and no bigger than "<<StatArr::getMaxSize()<<")\n The first element being the one you entered as size, and going down to 1.\n Please enter now:\n";
  24.     cin>>arr_size;
  25.     while ((arr_size<0)||(arr_size>StatArr::getMaxSize()))
  26.     {
  27.         cout<<"You provided with an errounous size. Size must be non negative\nand no bigger than "<<StatArr::getMaxSize()<<" Please enter again:\n";
  28.         cin>>arr_size;
  29.     }
  30.     StatArr S2(arr_size);
  31.     cout<<"Complete!\nFor the last object You need to fill up an array, the size is up to you, and I'll do the rest..   So, what size of an array would you like to fill? (non negative and no bigger than "<<StatArr::getMaxSize()<<").";
  32.     cin>>arr_size2;
  33.     while ((arr_size2<0)||(arr_size2>StatArr::getMaxSize()))
  34.     {
  35.         cout<<"You provided with an errounous size. Size must be non negative\nand no bigger than "<<StatArr::getMaxSize();cout<<" Please enter again:\n";
  36.         cin>>arr_size2;
  37.     }
  38.  
  39.     for(int i=0;i<arr_size2;i++)
  40.     {
  41.         cout<<"Please enter a number:\n";
  42.         cin>>inputArray[i];
  43.     }
  44.  
  45.     StatArr S3(inputArray,arr_size2);
  46.  
  47.  
  48.    
  49.     do
  50.     {
  51.     cout<<"Please choose what would you like to do:\n";
  52.     cout<<"1)\tSort an array in an object.\n2)\tPrint an array.\n3)\tSearch for a number in an array.\n4)\tGet the number at a certain index.\n5)\tFind the most frequently occuring number in an array.\n6)\tChange a number in a certain index.\n7)\tChange the last member of the array.\n8)\tGet the legth of an array.\n9)\tExit.\n";
  53.     cin>>menuChoice;
  54.     system("cls");
  55.     switch(menuChoice)
  56.     {
  57.     case 1:
  58.         do
  59.         {
  60.             cout<<"which object do you want to sort? (1/2/3)\n";
  61.             cin>>whatObject;
  62.             switch(whatObject)
  63.             {
  64.             case 1:
  65.                 cout<<"Please choole how to sort (1-ascending / 0- descending)\n";
  66.                 cin>>sortMethod;
  67.                 switch(sortMethod)
  68.                 {
  69.                 case 0:
  70.                     S1.arrSort(false);
  71.                     break;
  72.                 case 1:
  73.                     S1.arrSort(true);
  74.                 default:
  75.                     cout<<"no such sorting method!";
  76.                     break;
  77.                 }//closes the switch clause
  78.                 break;
  79.             case 2:
  80.                 cout<<"Please choole how to sort (1-ascending / 0- descending)\n";
  81.                 cin>>sortMethod;
  82.                 switch(sortMethod)
  83.                 {
  84.                 case 0:
  85.                     S2.arrSort(false);
  86.                     break;
  87.                 case 1:
  88.                     S2.arrSort(true);
  89.                 default:
  90.                     cout<<"no such sorting method!";
  91.                     break;
  92.                 }
  93.                 break;
  94.             case 3:
  95.                 cout<<"Please choole how to sort (1-ascending / 0- descending)\n";
  96.                 cin>>sortMethod;
  97.                 switch(sortMethod)
  98.                 {
  99.                 case 0:
  100.                     S3.arrSort(false);
  101.                     break;
  102.                 case 1:
  103.                     S3.arrSort(true);
  104.                     break;
  105.                 default:
  106.                     cout<<"no such sorting method!";
  107.                     break;
  108.                 }
  109.                 break;
  110.             default:
  111.                 cout<<"No such object!";
  112.             }
  113.         }while((whatObject !=1)&&(whatObject !=2)&&(whatObject !=3));
  114.         break;
  115.     case 2:
  116.         do
  117.         {
  118.             cout<<"Whaich object do you want to print?(1/2/3)\n";
  119.             cin>>whatObject;
  120.             switch (whatObject)
  121.             {
  122.             case 1:
  123.                 S1.arrPrint();
  124.                 break;
  125.             case 2:
  126.                 S2.arrPrint();
  127.                 break;
  128.             case 3:
  129.                 S3.arrPrint();
  130.                 break;
  131.             default:
  132.                 cout<<"no such object, Please input again\n";
  133.             }
  134.         }while((whatObject !=1)&&(whatObject !=2)&&(whatObject !=3));
  135.         break;
  136.     case 3:
  137.         do
  138.         {
  139.             cout<<"What number are you looking for?\n";
  140.             cin>>searchValue;
  141.             cout<<"in what object should the search be conducted?(1/2/3)\n";
  142.             cin>>whatObject;
  143.             switch (whatObject)
  144.             {
  145.             case 1:
  146.                 cout<<"The number "<<searchValue<<" Was found at index "<<S1.isAvailable(searchValue)<<"\n";
  147.                 break;
  148.             case 2:
  149.                 cout<<"The number "<<searchValue<<" Was found at index "<<S2.isAvailable(searchValue)<<"\n";
  150.                 break;
  151.             case 3:
  152.                 cout<<"The number "<<searchValue<<" Was found at index "<<S3.isAvailable(searchValue)<<"\n";
  153.                 break;
  154.             default:
  155.                 cout<<"no such object, Please input again\n";
  156.             }
  157.         }while((whatObject !=1)&&(whatObject !=2)&&(whatObject !=3));
  158.         break;
  159.     case 4:
  160.         do
  161.         {
  162.             cout<<"Retreive number from what index?\n";
  163.             cin>>searchIndex;
  164.             cout<<"in what object should the search be conducted?(1/2/3)\n";
  165.             cin>>whatObject;
  166.             switch (whatObject)
  167.             {
  168.             case 1:
  169.                 cout<<"The number "<<searchIndex<<" Was found at index "<<S1.getIndex(searchIndex)<<"\n";
  170.                 break;
  171.             case 2:
  172.                 cout<<"The number "<<searchValue<<" Was found at index "<<S2.getIndex(searchIndex)<<"\n";
  173.                 break;
  174.             case 3:
  175.                 cout<<"The number "<<searchValue<<" Was found at index "<<S3.getIndex(searchIndex)<<"\n";
  176.                 break;
  177.             default:
  178.                 cout<<"no such object, Please input again\n";
  179.             }
  180.         }while((whatObject !=1)&&(whatObject !=2)&&(whatObject !=3));
  181.         break;
  182.     case 5:
  183.         do
  184.         {
  185.             cout<<"Search the most frequent number in what object(1/2/3)\n";
  186.             cin>>whatObject;
  187.             switch(whatObject)
  188.             {
  189.             case 1:
  190.                 cout<<"The number appearing most requently is "<<S1.mostFrequent()<<" and it's index is: "<<S1.isAvailable(S1.mostFrequent())<<"\n";
  191.                 break;
  192.             case 2:
  193.                 cout<<"The number appearing most requently is "<<S2.mostFrequent()<<" and it's index is: "<<S2.isAvailable(S2.mostFrequent())<<"\n";
  194.                 break;
  195.             case 3:
  196.                 cout<<"The number appearing most requently is "<<S3.mostFrequent()<<" and it's index is: "<<S3.isAvailable(S3.mostFrequent())<<"\n";
  197.                 break;
  198.             }
  199.         }while((whatObject !=1)&&(whatObject !=2)&&(whatObject !=3));
  200.         break;
  201.     case 6:
  202.         do
  203.         {
  204.             cout<<"What is the number you want to insert?\n";
  205.             cin>>numberToInsert;
  206.             cout<<"In what index?\n";
  207.             cin>>searchIndex;
  208.             cout<<"In what object?(1/2/3)\n";
  209.             cin>>whatObject;
  210.             switch (whatObject)
  211.             {
  212.             case 1:
  213.                 S1.setIndex(searchIndex,numberToInsert);
  214.                 cout<<"done!\n";
  215.                 break;
  216.             case 2:
  217.                 S2.setIndex(searchIndex,numberToInsert);
  218.                 cout<<"done!\n";
  219.                 break;
  220.             case 3:
  221.                 S3.setIndex(searchIndex,numberToInsert);
  222.                 cout<<"done!\n";
  223.                 break;
  224.             default:
  225.                 cout<<"no such object, please try again\n";
  226.             }
  227.         }while((whatObject !=1)&&(whatObject !=2)&&(whatObject !=3));
  228.         break;
  229.     case 7:
  230.         do
  231.         {
  232.             cout<<"Insert what number?\n";
  233.             cin>>numberToInsert;
  234.             cout<<"In which object?(1/2/3)\n";
  235.             cin>>whatObject;
  236.             switch(whatObject)
  237.             {
  238.             case 1:
  239.                 S1.setLast(numberToInsert);
  240.                 cout<<"done!\n";
  241.                 break;
  242.             case 2:
  243.                 S2.setLast(numberToInsert);
  244.                 cout<<"done!\n";
  245.                 break;
  246.             case 3:
  247.                 S3.setLast(numberToInsert);
  248.                 cout<<"done!\n";
  249.                 break;
  250.             default:
  251.                 cout<<"No such object, Please try again.\n";
  252.             }
  253.         }while((whatObject !=1)&&(whatObject !=2)&&(whatObject !=3));
  254.         break;
  255.     case 8:
  256.         do
  257.         {
  258.             cout<<"Get the length of which array? (1/2/3)\n";
  259.             cin>>whatObject;
  260.             switch(whatObject)
  261.             {
  262.             case 1:
  263.                 cout<<"The legth of the object is "<<S1.arrLength()<<"\n";
  264.                 break;
  265.             case 2:
  266.                 cout<<"The legth of the object is "<<S2.arrLength()<<"\n";
  267.             case 3:
  268.                 cout<<"The legth of the object is "<<S3.arrLength()<<"\n";
  269.                 break;
  270.             default:
  271.                 cout<<"No such object, Please try again.\n";
  272.             }
  273.         }while((whatObject !=1)&&(whatObject !=2)&&(whatObject !=3));
  274.         break;
  275.     case 9:
  276.         system("cls");
  277.         cout<<"Good bye!\n";
  278.         exit(0);
  279.         break;
  280.     }
  281.     }while (menuChoice!=9);
  282.     return 0;
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement