Question #50398

Create a class named RealtorCommission. Fields include the sale price of a house, the
sales commission rate, and the commission. Create two constructors. Each constructor
requires the sales price (expressed as a double) and the commission rate. One construc-
tor requires the commission rate to be a double, such as .06. The other requires the sale
price and the commission rate expressed as a whole number, such as 6. Each constructor
calculates the commission value based on the price of the house multiplied by the com-
mission rate. The difference is that the constructor that accepts the whole number must
convert it to a percentage by dividing by 100. Also include a display function for the fields
contained in the RealtorCommission class. Write a main()function that instantiates at
least two RealtorCommission objects—one that uses a decimal and one that uses a
whole number as the commission rate. Display the RealtorCommission object values.
Save the file as RealtorCommission.cpp.
1

Expert's answer

2015-01-13T11:19:01-0500

Answer on Question# 50398- <programming> - <c++>

Program

RealtorCommission.cpp


#include <iostream>
#include <conio.h>
using namespace std;
class RealtorCommission
{
double salePrice;//sale price of a house
double commissionRate;//the sales commission rate
double commission;// the commission
public:
RealtorCommission (double price, double rate);
RealtorCommission (double price, int rate);
void print() {
cout<<"Price is: $"<<salePrice<<endl<<"Commission rate is: "<<commissionRate<<endl<<"Commission is: $"<<commission<<endl;
}
};
RealtorCommission::RealtorCommission (double price, double rate)
{
salePrice=price;
commissionRate=rate;
commission=salePrice*commissionRate;
}
RealtorCommission::RealtorCommission (double price, int rate)
{
salePrice=price;
commissionRate=rate/100.;
commission=salePrice*commissionRate;
}
int main()
{
RealtorCommission a(10000,0.06);
RealtorCommission b(10000,5);
cout<<"First object (10000,0.06): "<<endl;
a.print();
cout<<"Second object (10000,5): "<<endl;
b.print();
getch();
return 0;
}

Example of execute program:

First object (10000,0.06):
Price is: $10000
Commission rate is: 0.06
Commission is: $600
Second object (10000,5):
Price is: $10000
Commission rate is: 0.05
Commission is: $500


http://www.AssignmentExpert.com/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS