Company ABC Sdn Bhd is planning to develop a program to summarize their employees’ salary information. Each of the employee is required to register the name, IC number, ID number (in format 123456) and salary data. Identify the data needs for the program. Design the simple flow to allow the registration process for one employee. And finally deploy your analysis and design to build a complete program.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Employee
{
public:
Employee(int id, string name, double salary);
void Display();
double GetSalary() { return salary; }
private:
int id;
string name;
double salary;
};
Employee::Employee(int id_, string name_, double salary_) : id(id_), name(name_), salary(salary_)
{
}
void Employee::Display()
{
cout << id << " " << name << " $" << salary << endl;
}
int main()
{
int choice;
vector<Employee> Team;
cout << "Welcome to Company ABC Sdn Bhd menu!" << endl;
while (true)
{
cout << "1. Enter new Employee." << endl;
cout << "2. Display all Employees." << endl;
cout << "3. Display all Employees salary." << endl;
cout << "4. Exit." << endl;
cout << "Enter your choice: ";
cin >> choice;
if (choice == 4) break;
switch (choice)
{
case 1:
{
string name;
int id;
double salary;
cout << "Enter name: "; cin >> name;
cout << "Enter id: "; cin >> id;
cout << "Enter salary $: "; cin >> salary;
Team.push_back(Employee(id, name, salary));
cout << endl;
break;
}
case 2:
{
for (int i = 0; i < Team.size(); i++)
{
Team[i].Display();
}
cout << endl;
break;
}
case 3:
{
double sum = 0;
for (int i = 0; i < Team.size(); i++)
{
sum += Team[i].GetSalary();
cout << "Salary of all Emploees is: $" << sum << endl << endl;
}
break;
}
default:
cout << "Enter wrong value." << endl << endl;
}
}
system("pause");
return 0;
}
Comments
Leave a comment