Problem: You need to calculate the square footage of homes and their property ta
ID: 3827331 • Letter: P
Question
Problem: You need to calculate the square footage of homes and their property taxes. The town has some odd taxrules. All of the homes have at least one kitchen, bathroom, and a bedroom. However, they can also have additional bedrooms, bathrooms, living rooms, and/or a dining room.The user will be able to tell you which rooms they have and the length and width ofeach room. Each nun ofthe program should calculate and displaythe total square footage as well as the total taxes due.The property taxes calculated based on the type and size of the room accor ding to the following table. Function Tax Rate per sqft Kitchen $149 Bathroom Bedroom 5045 Living Room $0.35 Dining Room Any other room 25 Minimum total tax $1001 Long Wall Tax S3 per foot over 19 feet for each room lengthwidth over 19 feet. Exception being the Luxury tax on rooms of 200 sq and sa85 added to rooms tax per quality ng Maximum tota tax None Notes: The tax rates should be constants in your program, not having them wilcostpoints should be used to reduce code repetition, not having them will cost points. Al functions must be commented with pre and post conditions. e At least one function should contain and utilize a pass by reference parameter Example output: Do not hard code these values, your program should work for allvalues ofiength and dths) See provided text file for example output, your output should match if user provides same values.Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
//constant tax rates
const float KITCHEN = 1.49;
const float BATHROOM = 4.50;
const float BEDROOM = .45;
const float LIVINGROOM = .35;
const float DININGROOM = .55;
const float OTHER = 1.25;
void getinput(string s,float &l, float &b) //function to get user input and uses references
{
cout << "enter " << s << " Length:";
cin >>l;
cout << "enter " << s << " Width:";
cin >> b;
}
//calculates area
float calculate_area(float a, float b)
{
return (a*b);
}
//calculate extra tax for length and breadth >19
float calculate_length_width_extra(float a, float b)
{
float temp = 0;
if (a > 19)
{
temp = temp +(a - 19) * 3;
}
if (b > 19)
{
temp = temp + (b - 19) * 3;
}
return temp;
}
int main()
{
const float min_total_tax = 1001;
const float long_wall = 3;
//{0 = kitchen.....5 = other room}
float house_tax[6]; //variable to keep track of total house tax
int total_rooms = 0;
float total_area = 0;
for (int i = 0; i < 6; i++) // initialize the tax to zero
house_tax[i] = 0;
while (1)
{
float length = 0;
float width = 0;
char choice;
cout << "Select Next Room:" << endl;
cout << "------------------" << endl;
cout << "1|K: Kitchen" << endl;
cout << "2|B: Bedroom" << endl;
cout << "3|T: Bathroom" << endl;
cout << "4|L: Living Room" << endl;
cout << "5|D: Dining Room" << endl;
cout << "6|O: Other Room" << endl;
cout << "------------------" << endl;
cout << "7|X: EXit" << endl;
cin >> choice;
switch (choice)
{
case 'K':
{
getinput("Kitchen", length, width); // get the length and breadth
float area = calculate_area(length, width); //calculate area
house_tax[0] = house_tax[0] + (area*KITCHEN); //calulate tax for that room using area and constant tax
if (area >= 200) //if area is greater then 200 add an extra tax
{
house_tax[0] = house_tax[0] + 485;
}
total_rooms = total_rooms++; //increase the room count
total_area = total_area + area; //increase the total area
}
break;
case 'B':
{
getinput("Bedroom", length, width);
float area = calculate_area(length, width);
float extra_tax = calculate_length_width_extra(length, width); //calculate extra tax based on length and width feet
house_tax[1] = house_tax[1] + (area*KITCHEN) + extra_tax;
if (area >= 200)
{
house_tax[1] = house_tax[1] + 485;
}
total_rooms = total_rooms++;
total_area = total_area + area;
}
break;
case 'T':
{
getinput("Bathroom", length, width);
float area = calculate_area(length, width);
float extra_tax = calculate_length_width_extra(length, width);
house_tax[0] = house_tax[0] + (area*KITCHEN)+extra_tax;
if (area >= 200)
{
house_tax[2] = house_tax[2] + 485;
}
total_rooms = total_rooms++;
total_area = total_area + area;
}
break;
case 'L':
{
getinput("Living Room", length, width);
float area = calculate_area(length, width);
float extra_tax = calculate_length_width_extra(length, width);
house_tax[3] = house_tax[3] + (area*KITCHEN)+extra_tax;
if (area >= 200)
{
house_tax[3] = house_tax[3] + 485;
}
total_rooms = total_rooms++;
total_area = total_area + area;
}
break;
case 'D':
{
getinput("Dining Room", length, width);
float area = calculate_area(length, width);
float extra_tax = calculate_length_width_extra(length, width);
house_tax[4] = house_tax[4] + (area*KITCHEN)+extra_tax;
if (area >= 200)
{
house_tax[4] = house_tax[4] + 485;
}
total_rooms = total_rooms++;
total_area = total_area + area;
}
break;
case 'O':
{
getinput("Other", length, width);
float area = calculate_area(length, width);
float extra_tax = calculate_length_width_extra(length, width);
house_tax[5] = house_tax[5] + (area*KITCHEN) + extra_tax;
if (area >= 200)
{
house_tax[5] = house_tax[5] + 485;
}
total_rooms = total_rooms++;
total_area = total_area + area;
}
break;
case 'X':
{
if (house_tax[0] == 0 || house_tax[1] == 0 || house_tax[2] == 0) // check we have atleast 1 kitchen,1bedroom and 1 bathroom
{
if (house_tax[0] == 0)
{
cout << "Error: House must have atleast 1 kitchen"<<endl;
}
if (house_tax[1] == 0)
cout << "Error: House must have atleast 1 Bedroom" << endl;
if (house_tax[2] == 0)
cout << "Error: House must have atleast 1 Bathroom" << endl;
}
else // calculate the total taxs and exit
{
cout << "Total Rooms:" << total_rooms << endl;
cout << "Totat SQFT:" << total_area << endl;
float total_tax = 0;
for (int i = 0; i < 6; i++)
total_tax = total_tax + house_tax[i];
if (total_tax < min_total_tax)
total_tax = min_total_tax;
cout << "Total Tax:" << total_tax << endl;
exit(0);
}
}
break;
default:
cout << "Wrong choice!!!" << endl;;
break;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.