Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using your source code from Update #3 of the Real Estate Commissions program, do

ID: 3858969 • Letter: U

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 test data excluding the bad data. (Note: We are assuming the file has been checked for errors and that the remaining data is good data…so 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 <iostream>

#include <iomanip>

#include <string>

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<howmany; 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<howmany; i++)

{

for (int j = i + 1; j<howmany; 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<howmany; 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;

}

}

Explanation / Answer

Given below is the code for taking input from file and producing output in a file. Please store all input data in a file and use that filename . Sample input data is given below. You can use same format and put your test data in the file. Please rate the answer if it helped. Thank you.

#include <iostream>

#include <fstream>

#include <iomanip>

#include <string>

#include <cstdlib>

using namespace std;

#define BasicRate .10

#define StandardRate .15

#define LuxuryRate .20

#define NAME "Suzi's"

#define SIZE 10

//function prototypes

void PrintLargestSmallestAverage(ostream &outfile, double largest, double smallest, double average); //pass file by refrence

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 << " ********************* " << NAME << " Commission Computer **************************** ";

cout << " ";

  

ifstream infile;

ofstream outfile;

string infilename, outfilename;

  

cout << " Enter input filename: ";

cin >> infilename;

  

cout << " Enter output filename: ";

cin >> outfilename;

  

infile.open(infilename.c_str());

if(!infile.is_open())

{

cout << "Could not open input file " << infilename << endl;

exit(1);

}

  

outfile.open(outfilename.c_str());

if(!outfile.is_open())

{

cout << "Could not open output file " << outfilename << endl;

exit(1);

}

outfile << fixed << setprecision(2);

  

while (infile>> agent_id[howmany]) //as long as there is another agent_id in files

{

  

//get type of property sold from file

infile>>house_Type[howmany];

  

// get selling price from file

infile>> selling_price[howmany] ;

  

//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)

break;

}

  

infile.close();

//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;

}

  

  

  

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

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

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

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

  

outfile << " ";

  

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

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

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

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

  

outfile << " ";

  

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

PrintLargestSmallestAverage(outfile, largest, smallest, average_comm);

  

outfile << "Unsorted -" << endl << endl;

//display unsorted output

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

for (int i = 0; i<howmany; i++)

{

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

}

outfile << endl;

  

  

/*sort data*/

for (int i = 0; i<howmany; i++)

{

for (int j = i + 1; j<howmany; 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] = itemp;

}

}

}

  

   outfile << "Sorted -" << endl << endl;

//display sorted output

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

for (int i = 0; i<howmany; i++)

{

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

}

outfile << endl;

  

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

outfile.close();

cout << "Check output file " << outfilename << " for output." << endl;

system("pause");

return 0;

  

}

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

/****

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(ostream &outfile, double largest, double smallest, double average)

{

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

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

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

  

outfile << " ";

}

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;

}

return 0;

}

input file: sale.txt

11111 S 50000.00
22222 B 45000.00
33333 L 75000.00
44444 S 30000.00
55555 B 28000.00
66666 L 90000.00

output:


********************* Suzi's Commission Computer ****************************

Enter input filename: sale.txt

Enter output filename: report.txt
Check output file report.txt for output.

output file: report.txt


Total number of Basic houses commissions computed = 2
Total number of Standard houses commissions computed = 2
Total number of Luxury houses commissions computed = 2
Total number of all commissions computed = 6

Total amount of Residential commissions computed = 7300.00
Total amount of Commerical commissions computed = 12000.00
Total amount of Multi/Dwell commissions computed = 33000.00
Total amount of all commissions computed = $ 52300.00

The smallest commission computed = $ 2800.00
The largest commission computed = $ 18000.00
The average of the commissions computed = $ 8716.67


Unsorted -

Agent ID House Type Selling Price Commission
11111 S 50000.00 7500.00
22222 B 45000.00 4500.00
33333 L 75000.00 15000.00
44444 S 30000.00 4500.00
55555 B 28000.00 2800.00
66666 L 90000.00 18000.00

Sorted -

Agent ID House Type Selling Price Commission
55555 B 28000.00 2800.00
44444 S 30000.00 4500.00
22222 B 45000.00 4500.00
11111 S 50000.00 7500.00
33333 L 75000.00 15000.00
66666 L 90000.00 18000.00


**************************End of Run Report**********************************