Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- MUHAMMAD HILMI BIN KAMARUL'AZMI
- 01DDT20F1122
- LAB ACTIVITY 3B.2
- PLEASE REFER LINE 27 FOR UPDATED ANSWER QUESTION 3B.2 PART 2
- */
- #include <iostream>
- #include <vector>
- using namespace std;
- // used to find staff ID in vector staffID
- int staffIDContainer(int sID);
- // used to input staff salary
- void staffInputContainer(int x);
- // used to check staff income
- void staffCheckIncome();
- // used to print all income of available staff
- void staffPrintAllIncome();
- // used to created 200 staff (Question 3B.2)
- void create200Staff();
- // used to input all staff with same salary (Question 3B.2)
- void staffInputAllSame();
- // used to input all staff one by one until 200 staff (Question 3B.2)
- void staffInputOneByOne();
- // used to find average of ten staff (Question 3B.2 PART 2)
- void findAverageOfTen();
- static vector<float> staffTotalIncome;
- static vector<int> staffID;
- int main()
- {
- create200Staff();
- bool isTrue{ true };
- while (isTrue) {
- int selector{ 0 };
- 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:";
- cin >> selector;
- if (selector == 1)
- {
- staffCheckIncome();
- }
- else if (selector == 2)
- {
- staffInputContainer(0);
- }
- else if (selector == 3)
- {
- staffPrintAllIncome();
- }
- else if (selector == 4)
- {
- staffInputAllSame();
- }
- else if (selector == 5)
- {
- staffInputOneByOne();
- }
- else if(selector == 6)
- {
- findAverageOfTen();
- }
- else if (selector == 7)
- {
- cout << "BYE BYE!" << endl;
- return 0;;
- }
- else { cout << "ERROR! : Is that the real input? "; return 0; }
- }
- return 0;
- }
- void create200Staff()
- {
- for (int i = 0; i < 200; i++)
- {
- staffID.push_back(1000 + i);
- staffTotalIncome.push_back(0);
- }
- }
- void staffCheckIncome()
- {
- int sID{ 0 };
- cout << "Check Staff Income [Enter Staff ID] :";
- cin >> sID;
- cout << "[RESULT]Total Income for staff [" << sID << "] : RM";
- cout << staffTotalIncome.at(staffIDContainer(sID));
- cout << endl;
- cout << "-----------------------------------------------------------------";
- cout << endl;
- }
- void staffInputContainer(int x)
- {
- int currentID{ 0 };
- int sID{ 0 };
- if (x == 0)
- {
- cout << "Please enter STAFF ID : ";
- cin >> sID;
- }
- else { sID = x; }
- currentID = staffIDContainer(sID);
- cout << "STAFF ID [" << sID << "] |id :" << currentID << endl;
- float grossIncome{ 0.0 };
- cout << "Enter gross income : RM";
- cin >> grossIncome;
- float allowance{ 0.0 };
- cout << "Enter allowance : RM";
- cin >> allowance;
- float overtime{ 0.0 };
- cout << "Enter overtime : RM";
- cin >> overtime;
- float incomeTax{ 0.0 };
- cout << "Enter income tax : RM";
- cin >> incomeTax;
- float loan{ 0.0 };
- cout << "Enter loan : RM";
- cin >> loan;
- float totalIncome{ 0.0 };
- totalIncome = (grossIncome + allowance + overtime) - (incomeTax + loan);
- cout << "[RESULT] Total Income for [" << sID << "] : RM" << totalIncome;
- staffTotalIncome.at(currentID) = totalIncome;
- cout << endl;
- cout << "-----------------------------------------------------------------";
- cout << endl;
- }
- int staffIDContainer(int sID)
- {
- int count{ 0 };
- for (size_t i = 0; i < staffID.size(); i++)
- {
- if (sID == staffID.at(i))
- {
- break;
- }
- count++;
- }
- return count;
- }
- void staffPrintAllIncome()
- {
- cout << "-------- [ALL] --------" << endl;
- int counter{ 0 };
- for (size_t i = 0; i < staffID.size(); i++)
- {
- cout << "-|" <<staffID.at(i) << " -> RM" << staffTotalIncome.at(i) << "|- ";
- if (counter == 5)
- {
- counter = 0;
- cout << endl;
- }
- counter++;
- }
- cout << endl;
- }
- void staffInputAllSame()
- {
- float value{ 0 };
- cout << "Value to set all " << staffID.size() << " staff : RM";
- cin >> value;
- for (size_t i = 0; i < staffID.size(); i++)
- {
- staffTotalIncome.at(i) = value;
- }
- }
- void staffInputOneByOne()
- {
- for (size_t i = 0; i < staffID.size(); i++)
- {
- staffInputContainer(staffID.at(i));
- }
- }
- void findAverageOfTen()
- {
- float average{ 0 };
- for (size_t i = 0; i < 10; i++)
- {
- int id{ 0 };
- cout << i + 1 << "| STAFF ID :";
- cin >> id;
- average += staffTotalIncome.at(staffIDContainer(id));
- }
- cout << "Average of ten choosen staff : RM" << average / 10 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement