Created
May 5, 2019 05:06
-
-
Save dibakarsutradhar/7b3e4b510971ff18bd41a1dbf52a2339 to your computer and use it in GitHub Desktop.
Assignment for TCS3024 Introductory Programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dibakar Sutra Dhar | |
// SUKD1802273 | |
/* Victor and Francis are looking to buy a house in a new development. | |
After looking at the several of 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. | |
Problem Analysis | |
Algorithm | |
Flowchart | |
Pseudocode | |
Complete C++ program | |
Output | |
*/ | |
#include <iostream> | |
#include <string> | |
#include <iomanip> | |
using namespace std; | |
// function declaration | |
double leastPrice(double p, double f); | |
int main() | |
{ | |
// variable declaration | |
double colPrice, splitPrice, singlePrice, colFt, splitFt, singleFt; | |
double colTotal, splitTotal, singleTotal; | |
cout << "Enter the base price of Colonial Model: "; | |
cin >> colPrice; | |
cout << "Enter the finished area in square feet of Colonial Model: "; | |
cin >> colFt; | |
// calling leastPrice() function and assigning it to colTotal | |
colTotal = leastPrice(colPrice, colFt); | |
cout << "Enter the base price of Split-Entry Model: "; | |
cin >> splitPrice; | |
cout << "Enter the finished area in square feet of Split-Entry Model: "; | |
cin >> splitFt; | |
// calling leastPrice() function and assigning it to splitTotal | |
splitTotal = leastPrice(splitPrice, splitFt); | |
cout << "Enter the base price of Single-Entry Model: "; | |
cin >> singlePrice; | |
cout << "Enter the finished area in square feet of Single-Entry Model: "; | |
cin >> singleFt; | |
// calling leastPrice() function and assigning it to singleTotal | |
singleTotal = leastPrice(singlePrice, singleFt); | |
// printing model name, base price, square feet and price/square feet | |
cout << fixed << setprecision(2); | |
cout << endl << endl; | |
cout << setw(10) << " Model " << setw(15) << " Base Price " << setw(20) << " Square Feet " << setw(25) << "Price/Square Feet" << endl; | |
cout << setw(10) << "------------" << setw(15) << "--------------" << setw(20) << "---------------" << setw(25) << "-----------------" << endl; | |
cout << setw(10) << "Colonial " << setw(15) << colPrice << setw(20) << colFt << setw(25) << colTotal << endl; | |
cout << setw(10) << "Split-Entry " << setw(15) << splitPrice << setw(20) << splitFt << setw(25) << splitTotal << endl; | |
cout << setw(10) << "Single-Entry" << setw(15) << singlePrice << setw(20) << singleFt << setw(25) << singleTotal << endl; | |
cout << endl << endl; | |
// deteriming the least price model name | |
if(colTotal <= splitTotal && colTotal <= singleTotal) | |
cout << "Model with the Least Price is Colonial"; | |
if(splitTotal <= colTotal && splitTotal <= singleTotal) | |
cout << "Model with the Least Price is Split-Entry"; | |
if(singleTotal <= colTotal && singleTotal <= splitTotal) | |
cout << "Model with the Least Price is Single-Entry"; | |
return 0; | |
} | |
// function for calculating price per square feet | |
double leastPrice(double p, double f) | |
{ | |
double t = p/f; | |
return t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment