السلام عليكــم ورحمـة الله وبركاتــه
لوسمحتوا حبيت اشوف هذا التمرين ينحل بطريقه ثانيه اولا
حليته بس قالولي فيه طريقه فيها مهاره احسن وبديت اغير بس يطلع لي ايرور
شوفوا
السؤال
Define class called Wage_ Calculator which has the following:
1. Define the following data member:
a. Num_hour indicates number of hour worked.
b. Hour_wage indicates hourly wage.
c. Total_wage indicates the wage.
2. Set and Get member functions which allow assigning and returning data member except Total_wage in the class.
[Hint: in set function of wage you should use Validate(float) member function]
3. A Constructor function that initializes the data member by using set function.
4. Define member function Validate(float) that validate the float if it is positive or not; if not, prompt the user to reenter it again and then return the correct positive number.
[Hint: Validate(float) should used by set member functions before setting data members to any value – use While loop]
5. Define a member function called calculate_wage that use the number of hours worked and wage per hour to calculate and return the wage.
6. Define a member function called num_overtime that calculate and return the number of overtime hours worked.
7. Define a member function called overtime_pay that calculate and return over time payment by using the previous function.
8. Define a member function called total_wage that calculate and return the total wage.
9. Test your function in the main function.
10. The program should contains Two files
§ Header file:- which contain declaration of private (data members) and public (member functions) with its definitions.
§ Source File: - which contain the main function
Note:
§ Wage = number of hours worked (maximum of 40) * wage per hour.
§ Number of overtime hours worked = number of hours worked - 40.
§ Overtime pay = number of overtime hours worked * (1.5 * wage per hour).
§ Total wages = wages for up to the first 40 hours + overtime pay
اما الكود هو:
حاولت ادرج الكود بس ماضبط معاي مو عارفه ليش؟؟!!
header:
#include<iostream>
#include<string>
using namespace std;
class Wage_Calculator
{private:
int Num_hour;
float Hour_wage;
float Total_wage;
public:
Wage_Calculator(int hour,float wage){setNum_hour(hour);setHour_wage(wage);}
void setNum_hour(int hour)
{Num_hour=hour;}
int getNum_hour()
{return Num_hour;}
void setHour_wage(float wage)
{Hour_wage=Validate(wage);}
float getHour_wage()
{return Hour_wage;}
float Validate(float wage)
{while(wage<=0)
{cout<<"incorrect input";
cin>>wage;}
return wage;}
float calculate_wage()
{ float calwage;
if(getNum_hour()>40)
calwage=40*getHour_wage();
else
calwage=getNum_hour()*getHour_wage();
return calwage;
}
int num_overtime()
{
if(getNum_hour()>40)
return(getNum_hour()-40);
else
return 0;
}
float overtime_pay()
{return num_overtime()*1.5*getHour_wage();}
float total_wage()
{Total_wage=overtime_pay()+calculate_wage();
return Total_wage;}
};
Cpp:
#include<iostream>
#include<string>
using namespace std;
#include"sha2.h"
int main()
{int hour;
float wage;
cout<<"your hour";
cin>>hour;
cout<<"the wage per hour";
cin>>wage;
Wage_Calculator emp(hour,wage);
cout<<"\nyourwage "<<emp.calculate_wage()<<endl;
cout<<"\nyour over time payment for hour "<<emp.num_overtime()<<"is "<<emp.overtime_pay()<<endl;
cout<<"\n the total payment is"<<emp.total_wage();
return 0;
}
وفي نفس الكود اطبق
Class Wage_ Calculator:
• Update the member function Validate(float) , so it validate the float if it is positive or not; if not, prompt the user to reenter it again without any return value.
• Put a default value for the parameters in the constructor.
• Convert calculate_wage () to global function instead of member function and make your changes that you need
Overload calculate_wage () function to receive the wage as integer or float.
Test your program.
بس مافهمت وش تبي بالضبط
وكاون شاكره لكم