Advertisement
enkacang

LAB 3B - HILMI PART 2

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