dsdeep

FunC++

May 4th, 2021
525
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. void printList(vector<int>);
  7. void get_average(vector<int>);
  8. void smallest_data(vector<int>);
  9. void largest_data(vector<int>);
  10. void show_menu();
  11.  
  12. int main(){
  13.    
  14.     vector<int> list {1,2,3,4};
  15.    
  16.     bool run = true;
  17.    
  18.     show_menu();
  19.     while(run){
  20.         char data {};
  21.         cout << "\tChoose Any : ";
  22.         cin >> data;
  23.         data = tolower(data);
  24.         switch(data){
  25.             case 'p':
  26.                 printList(list);
  27.                 break;
  28.             case 'a':
  29.                 cout << "Enter The Data : ";
  30.                 int number;
  31.                 cin >> number;
  32.                 list.push_back(number);
  33.                 cout << number << " Added\n";
  34.                 break;
  35.             case 'm':
  36.                 get_average(list);
  37.                 break;
  38.             case 's':
  39.                 smallest_data(list);
  40.                 break;
  41.             case 'l':
  42.                 largest_data(list);
  43.                 break;
  44.             case 'q':
  45.                 cout << "GoodBye" <<endl;
  46.                 run = false;
  47.                 break;
  48.             default :
  49.                 cout << "Unknown Selection!! Please Try Again...." << endl;
  50.                 show_menu();
  51.                 break;
  52.         }
  53.     }
  54.     return 0;
  55. }
  56.  
  57. void show_menu(){
  58.     cout << "P - Print Numbers\nA - Add Numbers\nM - Display Mean Of The Numbers\n" <<
  59.     "S - Display The Smallest Number\nL - Display The Largest Number\n" <<
  60.     "Q - Quit\n";
  61. }
  62.  
  63. void printList(vector<int> my_list){
  64.     if(my_list.size() == 0){
  65.         cout << "[] - the list is empty" << endl;
  66.         return;
  67.     }
  68.     cout << "[ ";
  69.     for(auto int_data : my_list){
  70.         cout << int_data <<" ";
  71.     }
  72.     cout << "]\n";
  73. }
  74.  
  75. void get_average(vector<int> my_list){
  76.     if(my_list.size() == 0){
  77.         cout << "Unable To Calculate Mean - No Data" << endl;
  78.         return;
  79.     }
  80.    
  81.     int sum {0};
  82.     for(auto int_data : my_list){
  83.         sum += int_data;
  84.     }
  85.     cout << "Average = " << static_cast<double>(sum) / my_list.size() << endl;
  86. }
  87.  
  88. void smallest_data(vector<int> my_list){
  89.     if(my_list.size() == 0){
  90.         cout << "Unable To Determine The Smallest Number - List Is Empty" << endl;
  91.         return;
  92.     }
  93.     int temp {my_list.at(0)};
  94.     for(auto int_data : my_list){
  95.         if(int_data < temp)
  96.             temp = int_data;
  97.     }
  98.     cout << "Smallest Number Is " << temp << endl;
  99. }
  100.  
  101. void largest_data(vector<int> my_list){
  102.     if(my_list.size() == 0){
  103.         cout << "Unable To Determine The Largest Number - List Is Empty" << endl;
  104.         return;
  105.     }
  106.     int temp {my_list.at(0)};
  107.     for(auto int_data : my_list){
  108.         if(int_data > temp)
  109.             temp = int_data;
  110.     }
  111.     cout << "Largest Number Is " << temp << endl;
  112. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×