Program using C++ Problem: You need to calculate the square footage of homes and
ID: 3827754 • Letter: P
Question
Program using C++
Problem: You need to calculate the square footage of homes and their property taxes. The town has some odd tax rules. 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 of each room. Each run of the program should calculate and display the total square footage as well as the total taxes due. The property taxes are calculated based on the type and size of the room according to the table below.-
Notes:
The tax rates should be constants in your program, not having them will cost points
Functions should be used to reduce code repetition, not having them will cost points. All functions must be commented with pre and post conditions.
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 all values of length and widths). Your output should match if user provides same values. Six different example runs of the program are provided.
Tax Levy Tax Rate per sqft Function $1.49 Kitchen Bathroom $4.50 $0.45 Bedroom $0.35 Living Room $0.55 Dining Room Any other room $1.25 Misc Tax Minimum total tax $1001 Long Wall Tax $3 per foot over 19 feet for each room length/width over 19 feet. Exception being the kitchen Luxury tax on rooms of 200 sqft and $485 added to calculated higher rooms tax per qualifying room Maximum total tax NoneExplanation / Answer
#include <iostream>
using namespace std;
const double KR=1.49;
const double TR=4.50;
const double BR=0.45;
const double LR=0.35;
const double DR=0.55;
const double OR=1.25;
int kc=0,bc=0,tc=0,count=0;
double area,cost=0;
void printoption()
{
char sel[2];
cout << "Select Next Room: ";
cout << "--------------------- ";
cout << "1|K: Kitchen ";
cout << "2|B: Bedroom ";
cout << "3|T: Bathroom ";
cout << "4|L: Living Room ";
cout << "5|D: Dining Room ";
cout << "6|O: Other Room ";
cout << "--------------------- ";
cout << "6|X: Exit ";
}
double calcarea(double len,double width)
{
area=len*width;
return area;
}
double calcextarea(double area)
{
double extarea;
extarea=area-19;
cost=cost+(extarea*3);
return cost;
}
void checksel(char sel[2])
{
double len,width;
switch(sel[0])
{
case 'K':
cout<<"Enter Kitchen Length:";
cin>>len;
cout<<"Enter Kitchen Width:";
cin>>width;
area=calcarea(len,width);
cost=cost+area*KR;
count++;
kc=1;
printoption();
cin>>sel;
checksel(sel);
break;
case 'B':
cout<<"Enter Bedroom Length:";
cin>>len;
cout<<"Enter Bedroom Width:";
cin>>width;
cost=cost+area*KR;
bc=1;
count++;
if(area>19)
{
cost=calcextarea(area);
}
printoption();
cin>>sel;
checksel(sel);
break;
case 'T':
cout<<"Enter Bathroom Length:";
cin>>len;
cout<<"Enter Bathroom Width:";
cin>>width;
cost=cost+area*BR;
tc=1;
count++;
if(area>19)
{
cost=calcextarea(area);
}
if(area>19)
{
cost=calcextarea(area);
}
printoption();
cin>>sel;
checksel(sel);
break;
case 'L':
cout<<"Enter Living Room Length:";
cin>>len;
cout<<"Enter Living Room Width:";
cin>>width;
cost=cost+area*LR;
count++;
if(area>19)
{
cost=calcextarea(area);
}
printoption();
break;
case 'D':
cout<<"Enter Dining Room Length:";
cin>>len;
cout<<"Enter Dining Room Width:";
cin>>width;
count++;
cost=cost+area*DR;
printoption();
if(area>19)
{
cost=calcextarea(area);
}
cin>>sel;
checksel(sel);
break;
case 'O':
cout<<"Enter Other Room Length:";
cin>>len;
cout<<"Enter other Room Width:";
cin>>width;
cost=cost+area*OR;
count++;
printoption();
if(area>19)
{
cost=calcextarea(area);
}
printoption();
cin>>sel;
checksel(sel);
break;
case 'X':
if(kc==0)
{
cout<<"Error: House must have at least 1 Kitchen";
printoption();
}
if(bc==0)
{
cout<<"Error: House must have at least 1 Bedroom";
printoption();
}
if(tc==0)
{
cout<<"Error: House must have at least 1 Bathroom";
printoption();
}
if(kc==1&&bc==1&&tc==1)
{
cout<<"Taxed Rooms:"<<count;
cout<<"Total SQFT:" <<area;
cout<<"Total Tax: "<<cost;
}
break;
}
}
int main()
{
char sel[2];
printoption();
cin>>sel;
checksel(sel);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.