In: Computer Science
TEXT ONLY PLEASE (PLEASE NO PDF OR WRITING)
C++ CODE
Summary
Samantha and Vikas are looking to buy a house in a new development. After looking at various models, the three models they like are colonial, split-entry, and single-story.
The builder gave them the base price and the finished area in square feet of the three models. They want to know the model(s) with the least price per square foot.
Instructions
Write a program that accepts as input the base price and the finished area in square feet of the three models.
The program outputs the model(s) with the least price per square foot in the following format:
If the colonial model is the least price, output:
If the split-entry model is the least price, output:
If the single-story model is the least price, output:
If the colonial and split-entry models tie for the least price, output:
If the colonial and single-story models tie for the least price, output:
If the single-story and split-entry models tie for the least price, output:
Finally, if all three tie for the least price, output:
Thanks for the question.
Here is the completed code for this problem. Comments are
included so that you understand whats going on. Let me know if you
have any doubts or if you need anything to change.
Thank You !!
========================================================================================
#include<iostream>
#include<string>
using namespace std;
void printLeastPrice(double,double,double);
void printLeastPrice(double col,double split,double
single){
if(col<split && col<single){
cout<<"The price per square
foot of the colonial model is the least.\n";
}else if(split<col &&
split<single){
cout<<"The price per square
foot of the split-entry model is the least.\n";
}else if(single<col &&
single<split){
cout<<"The price per square
foot of the single-story model is the least.\n";
}else if(col==split && col<single){
cout<<"The price per square
foot of the colonial and split-entry models tie for the
least.\n";
}else if(col==single && col<split){
cout<<"The price per square
foot of the colonial and single-story models tie for the
least.\n";
}else if(single==split &&
single<col){
cout<<"The price per square
foot of the single-story and split-entry models tie for the
least.\n";
}else if(col==split && split==single){
cout<<"The price per square
foot all three models are the same.\n";
}
cout<<endl;
}
int main(){
double colonialBasePrice, splitBasePrice,
singleBasePrice;
double colonialArea, splitArea, singleArea;
double colonialPriceSqFt, splitPriceSqFt,
singlePriceSqFt;
// get user input for all the 3 models
cout<<"Colonial Model:"<<endl;
cout<<"Enter Base Price: ";
cin>>colonialBasePrice;
cout<<"Enter finished area: ";
cin>>colonialArea;
colonialPriceSqFt =
colonialBasePrice/colonialArea;
cout<<"Split-Entry Model:"<<endl;
cout<<"Enter Base Price: ";
cin>>splitBasePrice;
cout<<"Enter finished area: ";
cin>>splitArea;
splitPriceSqFt = splitBasePrice/splitArea;
cout<<"Single-story Model:"<<endl;
cout<<"Enter Base Price: ";
cin>>singleBasePrice;
cout<<"Enter finished area: ";
cin>>singleArea;
singlePriceSqFt = singleBasePrice/singleArea;
// uncomment to print the prices per sq ft for all the
3 models.
//cout<<"Colonial Price/Sqft:
"<<colonialPriceSqFt<<endl;
//cout<<"Split-Entry Price/Sqft:
"<<splitPriceSqFt<<endl;
//cout<<"Single=story Price/Sqft:
"<<singlePriceSqFt<<endl;
printLeastPrice(colonialPriceSqFt,splitPriceSqFt,singlePriceSqFt);
}
=====================================================================================
thanks a lot !!