C++ II LAB II Structures
1. Write a structure that collects array of students like First Name, Middle
Name, Last Name, Student ID, Sex, Department, Faculity/College, Year etc
and prints the result as the following example.
Full Name: Megibaru Andargie Sinishaw
ID: 6574/02
Sex: M
Department: Communications Engineering
Faculity: Engineering and Technology
Year: 2nd
Full Name: Asnake Markos Mulugeta
ID: 90345/02
Sex: M
Department: Computer Engineering
Faculity: Engineering and Technology
Year: 2nd
2. Employee Payroll System of Anonymous Organization
#include<iostream.h>
struct employee
{
char name[100];
char employee_ID[20];
char sex;
float salary;
float tax;
float netpay;
float pension;
float dam_contribution;
};
int main()
{
float tax;
employee emp[100];
int size;
cout<<"How many Employees do you want to calculate payroll? ";
cin>>size;
1
for (int i=0; i<size;i++)
{
cout<<"Record "<<i+1<<" : \n";
cout<<"Employee Name: ";
cin>>emp[i].name;
cout<<"Employee ID: ";
cin>>emp[i].employee_ID;
cout<<"Sex: ";
cin>>emp[i].sex;
cout<<"Salary: ";
cin>>emp[i].salary;
cout<<"\n\n\n";
}
cout<<" Payroll Calculation result:\n";
cout<<"___________________________________________________________\n";
cout<<"Name\t\tID\t\tSex\t\tSalary\t\tTax\t\tPension\t\tDam Cont.\t\
tNet Pay\n";
for(int j=0; j<size; j++)
{
if(emp[j].salary<=150)
{
emp[j].tax=0;
}
else if(emp[j].salary<=500)
{
emp[j].tax=emp[j].salary*0.05;
}
else if(emp[j].salary<=1000)
{
emp[j].tax=emp[j].salary*0.1;
}
else if(emp[j].salary<=1500)
{
emp[j].tax=emp[j].salary*0.15;
}
else if(emp[j].salary<=2500)
{
emp[j].tax=emp[j].salary*0.2;
}
else if(emp[j].salary<=4500)
{
emp[j].tax=emp[j].salary*0.25;
}
2
else if(emp[j].salary<=5000)
{
emp[j].tax=emp[j].salary*0.3;
}
else
{
emp[j].tax=emp[j].salary*0.35;
}
emp[j].pension=(emp[j].salary)*0.07;
emp[j].dam_contribution=(emp[j].salary)/12;
emp[j].netpay=emp[j].salary-
(emp[j].pension+emp[j].tax+emp[j].dam_contribution);
cout<<emp[j].name<<"\t\t"<<emp[j].employee_ID<<"\t\t"<<emp[j].sex<<"\
t\t"<<emp[j].salary<<"\t\t"<<emp[j].tax<<"\t\t"<<emp[j].pension<<"\t\
t"<<emp[j].dam_contribution<<"\t\t"<<emp[j].netpay<<endl;
}
cout<<"___________________________________________________________\n";
return 0;
}