Write a class called CustomerProject. It should have three double fields called
ID: 3671215 • Letter: W
Question
Write a class called CustomerProject. It should have three double fields called hours(the number of hours the project took), materials (the cost of materials) and transportation (transportation costs), in that order. It should have get and set methods for each field. It should have a constructor that takes as parameters the values for each field and calls the set methods to initialize them. It should have a pure virtual function called billAmount that takes no parameters and returns a double.
Write two classes that inherit from CustomerProject: RegularProject and PreferredProject. Both should have a constructor that takes three doubles and passes them to the base class constructor. RegularProject should override billAmount to return the sum of the materials costs, the transportation costs, and $80 times the number of hours. PreferredProject (for preferred customers) should override billAmount to return the sum of 85% of the materials costs, 90% of the transportation costs, and $80 times the number of hours up to a maximum of 100 hours (any hours beyond 100 are free).
Hint: You can access the member data of the base class either of two ways: 1) make that member data protected in the base class, or 2) simply use the get methods, which the derived classes have inherited.
There are no input validation or output formatting requirements.
The files must be called: CustomerProject.hpp, CustomerProject.cpp, RegularProject.hpp, RegularProject.cpp, PreferredProject.hpp, and PreferredProject.cpp.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
int main()
{
double amount,amount1;
CustomerProject cp; \creating object for class CustomerProject
cp.geth(); \calling geth()
cp.getm(); \calling getm()
cp.gett(); \calling gett()
RegularProject rp;
amount=rp.billAmount();
cout<<"Total Bill Amount for regular customers is"<<amount;
PreferredProject pp;
amount1=pp.billAmount();
cout<<"Total Bill Amount for preferred customers is<<amount1";
}
class CustomerProject
{
public:
double hours,materials,transportation;
void geth() \for taking value of hours from the user
{
double h;
cout<<"Enter the number of hours the project took ";
cin>>h;
}
void getm() \for taking value of materials from the user
{
double m;
cout<<"Enter the the cost of materials";
cin>>m;
}
void gett() \for taking value of transportation from the user
{
double t;
cout<<"Enter transportation costs";
cin>>t;
}
CustomerProject(double h1, double m1, double t1)
{
seth(h1); \calling seth()
setm(m1); \calling setm()
sett(t1); \calling sett()
}
void seth(double h2)
hours=h2;
void setm(double m2)
materials=m2;
void sett(double t2)
transportation=t2;
virtual double billAmount()=0; \virtual function
};
class RegularProject:public CustomerProject
{
double total;
double bh=h,bm-m,bt=t; \storing the three values whose values were obtained from above get functions.
\these can be accessed easily as the base class is inherited publicly
RegularProject(bh,bm,bt) : CustomerProject(bh,bm,bt) \passing values to base class constructor using base member initialisation
{ \It also calls the parametrized constructor of Base Class
}
double billAmount()
{
total=80*bh+bm+bt;
return total;
}
};
class PreferredProject:public CustomerProject
{
double total;
double bh=h,bm-m,bt=t; \storing the three values whose values were obtained from above get functions.
\these can be accessed easily as the base class is inherited publicly
PreferredProject(bh,bm,bt) : CustomerProject(bh,bm,bt) \passing values to base class constructor using base member initialisation
{ \It also calls the base class parametrized constructor
}
double billAmount()
{
total=0.85*bm+0.90*bt+80*bh;
if(bh>100)
return total;
else
return 0;
}
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.