| 
 | 
| פתרון/* Module: tr3_q4.cpp Author: Yariv Amar What? This program calculates worker salary Input : Worker level (from a,b or c) Workers regular hours Workers night hours Output: Gross worker's salary. Assumptions on input: Valid How? Algorithm: getting data from the user, using "switch" for the worker level, then calculating the salary according to the table given in the question. */ #include <iostream.h> void main()
{
	char Level ; //declering on worker's level
	double Reg_hours , Night_hours ; //declering on hours type
	double Salary; //declering on Salaryconst double REG_C = 20; //*************************************** const double REG_B = 35; // defining Regular salary per hour const double REG_A = 70; // const double NIGHT_C = 25; // const double NIGHT_B = 45; // defining Night salary per hour const double NIGHT_A = 250; // const int PRES_C = 20; // const int PRES_B = 15; // defining Extra % after 25 night hours const int PRES_A = 10; //*************************************** cout<<"Please enter worker Level (from a-c):"; cin>>Level; cout<<"\nPlease enter number of REGULAR hours:"; cin>>Reg_hours; cout<<"\nPlease enter number of NIGHT hours:"; cin>>Night_hours; 	switch (Level)
	{
	case 'a': 
		//calculating salary by adding Regular hours and then checking
		//the Night hours for Extra payment
		Salary = Reg_hours*REG_A;
		if (Night_hours<=25) Salary = Salary + Night_hours*NIGHT_A;
		else
			Salary = Salary + 25*NIGHT_A + 
			(Night_hours - 25)*NIGHT_A*(100+PRES_A)/100;
		cout<<"\nThe worker salary is: "<<Salary<<"\n";
		break;
	case 'b':
		Salary = Reg_hours*REG_B;
		if (Night_hours<=25) Salary = Salary + Night_hours*NIGHT_B;
		else
			Salary = Salary + 25*NIGHT_B + 
			(Night_hours - 25)*NIGHT_B*(100+PRES_B)/100;
		cout<<"\nThe worker salary is: "<<Salary<<"\n";
		break;
	case 'c':
		Salary = Reg_hours*REG_C;
		if (Night_hours<=25) Salary = Salary + Night_hours*NIGHT_C;
		else
			Salary = Salary + 25*NIGHT_C + 
			(Night_hours - 25)*NIGHT_C*(100+PRES_C)/100;
		cout<<"\nThe worker salary is: "<<Salary<<"\n";
		break;
	default: //when user didn't type correct level
		cout<<"\nYou have entered invalid Level , please try again.\n";
	}
}
 פלטים מיצגיםפלט לדוגמה: 
 
 
 | 
| © Copyright YAProductions 2000 |