Today I had this question in my exam:
write a program in C++ that covers the next points:
-a company needs to enter its employees' data into the computer
-each emplyee has (ID-Job Code-Division Code-Salary)
-should be done using struct
-Input/Output functions should be inside the struct
-use the struct to input a user-defined number of employees (max 50)
-after inputing the employees make sure that the company can enter a division code and the result would be the information about employees in that division.
my answer was the next
and I've got only 40% on it, what did I do wrong, If you please can point out my mistakes
#include<iostream>
using namespace std;
struct employee
{
int ID;
int salary;
int division_code;
int job_code;
void input(employee emp[], int i)
{
cout << "Employee number "<<i+1<<endl;
cout << "ID"<<endl;
cin>>emp[i].name;
cout << "Job Code"<<endl;
cin >> emp[i].job_code;
cout << "Division Code"<<endl;
cin >> emp[i].division_code;
cout << "Salary"<<endl;
cin >> emp[i].salary;
}
void output(employee emp[],int i)
{
cout <<"ID: "<<emp[i].name<<endl;
cout <<"Job: #"<<emp[i].job_code<<endl;
cout <<"Div: #"<<emp[i].division_code<<endl;
cout <<"Salary: $"<<emp[i].salary<<endl;
}
};
int main()
{
employee emp[50];
int division,n;
cout<<"Enter the number of employees"<<endl;
cin>>n;
for (int i=0;i<n;i++)
emp[i].input(emp,i);
cout <<"Enter Division code to find the employees working in it"<<endl;
cin >>division;
for (i=0;i<n;i++)
{
if (emp[i].division_code==division)
{
emp[i].output(emp,i);
}
}
return 0;
}