Advertisement
enkacang

LAB 3B - HILMI PART 3

Apr 21st, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.90 KB | None | 0 0
  1. /*
  2. MUHAMMAD HILMI BIN KAMARUL'AZMI
  3. 01DDT20F1122
  4. LAB ACTIVITY 3B.2
  5.  
  6. PLEASE REFER LINE 27 FOR UPDATED ANSWER QUESTION 3B.2 PART 2
  7.  
  8. */
  9. #include <iostream>
  10. #include <vector>
  11.  
  12. using namespace std;
  13. // used to find staff ID in vector staffID
  14. int staffIDContainer(int sID);
  15. // used to input staff salary
  16. void staffInputContainer(int x);
  17. // used to check staff income
  18. void staffCheckIncome();
  19. // used to print all income of available staff
  20. void staffPrintAllIncome();
  21. // used to created 200 staff (Question 3B.2)
  22. void create200Staff();
  23. // used to input all staff with same salary (Question 3B.2)
  24. void staffInputAllSame();
  25. // used to input all staff one by one until 200 staff (Question 3B.2)
  26. void staffInputOneByOne();
  27. // used to find average of ten staff (Question 3B.2 PART 2)
  28. void findAverageOfTen();
  29.  
  30. static vector<float> staffTotalIncome;
  31.  
  32. static vector<int> staffID;
  33.  
  34. int main()
  35. {
  36.  
  37.     create200Staff();
  38.  
  39.  
  40.     bool isTrue{ true };
  41.     while (isTrue) {
  42.         int selector{ 0 };
  43.         cout << "|1|- Check Employee income |2|- Enter Employee Income |3|- Print all result [END]\n|4| - Auto Input All |5| - Input One-By-One |6| - Average Of Ten |7| - END \nNUM:";
  44.         cin >> selector;
  45.  
  46.         if (selector == 1)
  47.         {
  48.             staffCheckIncome();
  49.         }
  50.         else if (selector == 2)
  51.         {
  52.             staffInputContainer(0);
  53.         }
  54.         else if (selector == 3)
  55.         {
  56.             staffPrintAllIncome();
  57.         }
  58.         else if (selector == 4)
  59.         {
  60.             staffInputAllSame();
  61.         }
  62.         else if (selector == 5)
  63.         {
  64.             staffInputOneByOne();
  65.         }
  66.         else if(selector == 6)
  67.         {
  68.             findAverageOfTen();
  69.         }
  70.         else if (selector == 7)
  71.         {
  72.             cout << "BYE BYE!" << endl;
  73.             return 0;;
  74.         }
  75.         else { cout << "ERROR! : Is that the real input? "; return 0; }
  76.     }
  77.  
  78.  
  79.     return 0;
  80. }
  81.  
  82. void create200Staff()
  83. {
  84.     for (int i = 0; i < 200; i++)
  85.     {
  86.         staffID.push_back(1000 + i);
  87.         staffTotalIncome.push_back(0);
  88.     }
  89. }
  90.  
  91.  
  92. void staffCheckIncome()
  93. {
  94.     int sID{ 0 };
  95.     cout << "Check Staff Income [Enter Staff ID] :";
  96.     cin >> sID;
  97.  
  98.     cout << "[RESULT]Total Income for staff [" << sID << "] : RM";
  99.     cout << staffTotalIncome.at(staffIDContainer(sID));
  100.  
  101.     cout << endl;
  102.     cout << "-----------------------------------------------------------------";
  103.     cout << endl;
  104.  
  105. }
  106.  
  107. void staffInputContainer(int x)
  108. {
  109.     int currentID{ 0 };
  110.     int sID{ 0 };
  111.     if (x == 0)
  112.     {
  113.         cout << "Please enter STAFF ID : ";
  114.         cin >> sID;
  115.     }
  116.     else { sID = x; }
  117.  
  118.     currentID = staffIDContainer(sID);
  119.  
  120.     cout << "STAFF ID [" << sID << "] |id :" << currentID << endl;
  121.  
  122.     float grossIncome{ 0.0 };
  123.     cout << "Enter gross income : RM";
  124.     cin >> grossIncome;
  125.  
  126.     float allowance{ 0.0 };
  127.     cout << "Enter allowance : RM";
  128.     cin >> allowance;
  129.  
  130.     float overtime{ 0.0 };
  131.     cout << "Enter overtime : RM";
  132.     cin >> overtime;
  133.  
  134.     float incomeTax{ 0.0 };
  135.     cout << "Enter income tax : RM";
  136.     cin >> incomeTax;
  137.  
  138.     float loan{ 0.0 };
  139.     cout << "Enter loan : RM";
  140.     cin >> loan;
  141.  
  142.     float totalIncome{ 0.0 };
  143.     totalIncome = (grossIncome + allowance + overtime) - (incomeTax + loan);
  144.  
  145.     cout << "[RESULT] Total Income for [" << sID << "] : RM" << totalIncome;
  146.  
  147.     staffTotalIncome.at(currentID) = totalIncome;
  148.  
  149.     cout << endl;
  150.     cout << "-----------------------------------------------------------------";
  151.     cout << endl;
  152. }
  153.  
  154. int staffIDContainer(int sID)
  155. {
  156.     int count{ 0 };
  157.  
  158.     for (size_t i = 0; i < staffID.size(); i++)
  159.     {
  160.         if (sID == staffID.at(i))
  161.         {
  162.             break;
  163.         }
  164.         count++;
  165.     }
  166.     return count;
  167. }
  168.  
  169. void staffPrintAllIncome()
  170. {
  171.     cout << "-------- [ALL] --------" << endl;
  172.     int counter{ 0 };
  173.     for (size_t i = 0; i < staffID.size(); i++)
  174.     {
  175.         cout << "-|" <<staffID.at(i) << " -> RM" << staffTotalIncome.at(i) << "|- ";
  176.  
  177.         if (counter == 5)
  178.         {
  179.             counter = 0;
  180.             cout << endl;
  181.         }
  182.         counter++;
  183.     }
  184.  
  185.     cout << endl;
  186.  
  187. }
  188.  
  189. void staffInputAllSame()
  190. {
  191.     float value{ 0 };
  192.     cout << "Value to set all " << staffID.size() << " staff : RM";
  193.     cin >> value;
  194.     for (size_t i = 0; i < staffID.size(); i++)
  195.     {
  196.         staffTotalIncome.at(i) = value;
  197.     }
  198.  
  199. }
  200.  
  201. void staffInputOneByOne()
  202. {
  203.     for (size_t i = 0; i < staffID.size(); i++)
  204.     {
  205.         staffInputContainer(staffID.at(i));
  206.     }
  207. }
  208.  
  209. void findAverageOfTen()
  210. {
  211.     float average{ 0 };
  212.  
  213.     for (size_t i = 0; i < 10; i++)
  214.     {
  215.         int id{ 0 };
  216.         cout << i + 1 << "| STAFF ID :";
  217.         cin >> id;
  218.  
  219.         average += staffTotalIncome.at(staffIDContainer(id));
  220.     }
  221.  
  222.     cout << "Average of ten choosen staff : RM" << average / 10 << endl;
  223. }
  224.  
  225.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement