Question: Using your source code from Update #3 of the Real Estate Commissions program, do the following: 1. Create a file in Notepad that contains your

Using your source code from Update #3 of the Real Estate Commissions program, do the following: 1. Create a file in Notepad that contains your test data excluding the bad data. (Note: We are assuming the file has been checked for errors and that the remaining data is good dataso basically the data from Update # 2 Be sure to press the Enter key after the last record is typed into Notepad. Save the file with a .txt or .dat file extension. 2. Read the test data from the file created in Step 2. 3. Instead of, or in addition to writing the output to the screen, send the output to a file. Test your program using your input file.

#include

#include

#include

using namespace std;

#define BasicRate .10

#define StandardRate .15

#define LuxuryRate .20

#define NAME "Suzi's"

#define SIZE 10

//function prototypes

void PrintLargestSmallestAverage(double largest, double smallest, double average);

int GetAgentID(); //function 1

char GetHouseType(); //funciton 2

double GetSellingPrice(); //function 3

string GetCommissionChoice(); //function 4

double CalculateCommission(double sellingprice, char housetype);

int main()

{

int

// Variable to determine if they have a commission to be computed

num_basic = 0, // Number of basic commissions computed

num_standard = 0, // Number of standard commissions computed

num_luxury = 0, // Number of luxury commissions computed

agent_id[SIZE], // Agent ID

j = 0, //counter

howmany = 0; // Keeps track of the number of commissions

char house_Type[SIZE]; // Category of property sold

double

selling_price[SIZE], // Selling price of the property

commission_calculated[SIZE], // Computed commission

totamount_basic = 0.0, // Total amount of basic commissions computed

totamount_standard = 0.0, // Total amount of standard commissions computed

totamount_luxury = 0.0, // Total amount of luxury commissions computed

smallest, // Smallest commission that was calculated

largest, // Largest commission that was calculated

average_comm, // Average of all commissions calculated

totamount_allcomm = 0.00; // Grand total of all commissions computed

string answer;

cout << fixed << setprecision(2);

cout << " ********************* " << NAME << " Commission Computer **************************** ";

cout << " ";

cout << " Do you have a commission to compute? (yes/no): ";

answer = GetCommissionChoice();

//if first answer is no, then exit the program

if (answer == "no")

{

//system ("pause");

return 0;

}

while (answer == "yes")

{

//call function to get agent id

agent_id[howmany] = GetAgentID();

//call function to get type of property sold

house_Type[howmany] = GetHouseType();

//call funciton to get selling price

selling_price[howmany] = GetSellingPrice();

//call function to calculate commission

commission_calculated[howmany] = CalculateCommission(selling_price[howmany], house_Type[howmany]);

switch (house_Type[howmany])

{

case 'b':

case 'B':

num_basic += 1;

totamount_basic += commission_calculated[howmany];

break;

case 's':

case 'S':

num_standard += 1;

totamount_standard += commission_calculated[howmany];

break;

case 'l':

case 'L':

num_luxury += 1;

totamount_luxury += commission_calculated[howmany];

break;

}

howmany++;

if (howmany >= SIZE)

answer = "0";

else

{

cout << " ";

cout << " Do you have another commission to compute? : ";

answer = GetCommissionChoice();

}

}

//calculate total commission amount

totamount_allcomm = totamount_basic + totamount_standard + totamount_luxury;

if (howmany > 0)

{

smallest = commission_calculated[0];

largest = commission_calculated[0];

for (j = 0; j < howmany; j++)

{

if (commission_calculated[j] < smallest)

smallest = commission_calculated[j];

if (commission_calculated[j] > largest)

largest = commission_calculated[j];

}

average_comm = totamount_allcomm / howmany;

}

else

{

smallest = 0;

largest = 0;

average_comm = 0;

}

cout << " **************************End of Run Report**********************************";

cout << " ";

cout << " Total number of Basic houses commissions computed = " << setw(15) << num_basic;

cout << " Total number of Standard houses commissions computed = " << setw(15) << num_standard;

cout << " Total number of Luxury houses commissions computed = " << setw(15) << num_luxury;

cout << " Total number of all commissions computed = " << setw(15) << howmany;

cout << " ";

cout << " Total amount of Residential commissions computed = " << fixed << setw(10) << setprecision(2) << totamount_basic;

cout << " Total amount of Commerical commissions computed = " << setw(10) << totamount_standard;

cout << " Total amount of Multi/Dwell commissions computed = " << setw(10) << totamount_luxury;

cout << " Total amount of all commissions computed = $" << setw(10) << totamount_allcomm;

cout << " ";

//call function to print largest, smallest and average commissions

PrintLargestSmallestAverage(largest, smallest, average_comm);

//display unsorted output

cout << setw(18) << "Agent ID" << setw(18) << "House Type" << setw(18) << "Selling Price" << setw(18) << "Commission" << endl;

for (int i = 0; i

{

cout << setw(18) << agent_id[i] << setw(18) << house_Type[i] << setw(18) << selling_price[i] << setw(18) << commission_calculated[i] << endl;

}

cout << endl;

/*sort data*/

for (int i = 0; i

{

for (int j = i + 1; j

{

if (commission_calculated[i] > commission_calculated[j])

{

double temp = commission_calculated[i];

commission_calculated[i] = commission_calculated[j];

commission_calculated[j] = temp;

temp = selling_price[i];

selling_price[i] = selling_price[j];

selling_price[j] = temp;

char ctemp = house_Type[i];

house_Type[i] = house_Type[j];

house_Type[j] = ctemp;

int itemp = agent_id[i];

agent_id[i] = agent_id[j];

agent_id[j] = temp;

}

}

}

//display sorted output

cout << setw(18) << "Agent ID" << setw(18) << "House Type" << setw(18) << "Selling Price" << setw(18) << "Commission" << endl;

for (int i = 0; i

{

cout << setw(18) << agent_id[i] << setw(18) << house_Type[i] << setw(18) << selling_price[i] << setw(18) << commission_calculated[i] << endl;

}

cout << endl;

cout << " **************************End of Run Report**********************************" << endl << endl;

system("pause");

return 0;

}

/*Utilize a function to print the largest commission, smallest commission and average commission*/

/****

Purpose: Function will print largest commission, smallest commission and average commission

Input Parameter: largest commission, smallest commission and average commission

Return Parameter: None

*****/

void PrintLargestSmallestAverage(double largest, double smallest, double average)

{

cout << " The smallest commission computed = $" << setw(10) << smallest;

cout << " The largest commission computed = $" << setw(10) << largest;

cout << " The average of the commissions computed = $" << setw(10) << average;

cout << " ";

}

/****

Purpose: Function to get user choice to compute a commission and validate value for yes or no

Input Parameter: None

Return Parameter: choice

*****/

string GetCommissionChoice()

{

string choice;

cin >> choice;

while (!(choice == "yes" || choice == "no"))

{

cout << " Error encountered.";

cout << " Please be sure you enter either a 'yes' or 'no'.";

cout << " ";

cout << " Do you have a commission to compute?(yes/no): ";

cin >> choice;

}

return choice;

}

/****

Purpose: Function to get valid agent id from user

Input Parameter: None

Return Parameter: agent_id

*****/

int GetAgentID()

{

int agent_id;

cout << fixed << " Please enter the Agent ID: ";

cin >> agent_id;

while (!(agent_id >= 10000 && agent_id <= 99999))

{

cout << " Invalid Agent ID has been entered.";

cout << " Please be sure the Id entered has only 5 numerical digits.";

cout << " ";

cout << " Re-enter your ID: ";

cin >> agent_id;

}

return agent_id;

}

/****

Purpose: Function to get valid house type from user

Input Parameter: None

Return Parameter: house type

*****/

char GetHouseType()

{

char house_Type;

cout << " Please enter the category of property sold";

cout << " (B=Basic, S=Standard, L=Luxury): ";

cin >> house_Type;

while (house_Type != 'b'&& house_Type != 'B'&& house_Type != 'S'&& house_Type != 's'&& house_Type != 'l'&& house_Type != 'L')

{

cout << " ERROR.";

cout << " Invalid letter has been entered.";

cout << " Please be sure to enter either a 'B','S' or 'L'.";

cout << " ";

cout << " Please enter the category of property sold";

cout << " (B=Basic, S=Standard, L=Luxury): ";

cin >> house_Type;

}

return house_Type;

}

/****

Purpose: Function to get valid selling price from user

Input Parameter: None

Return Parameter: selling price

*****/

double GetSellingPrice()

{

double selling_price;

cout << " Please enter the selling price: ";

cin >> selling_price;

while (selling_price <= 0)

{

cout << " Invalid Price has been entered.";

cout << " Selling Price must be greater than $0.00";

cout << " ";

cout << " Re-enter the selling price: ";

cin >> selling_price;

}

return selling_price;

}

double CalculateCommission(double sellingprice, char housetype)

{

switch (housetype)

{

case 'b':

case 'B':

return sellingprice * BasicRate;

break;

case 's':

case 'S':

return sellingprice * StandardRate;

break;

case 'l':

case 'L':

return sellingprice * LuxuryRate;

break;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!