How to solve this question?

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.

Write:
a.Problem Analysis
b.Algorithm
c.Flowchart
d.Pseudocode
e.Complete C++ program
f.Output
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <cctype>
#include <limits>

int main()
{
	std::cout << "Do you want someone to do all the work for you? ";
	char answer{};
	std::cin >> answer;

	// Ignore to the end of line
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

	if (std::toupper(answer) == 'Y' ) { std::cout << "Post it in the Jobs section.\n"; }

	else { std::cout << "Show what have you coded so far.\n"; }

	std::cout << "Good luck.\n";
}
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int basedColonial, basedSplitEntry, basedSingleStorey,
finishedColo, finishedSplit, finishedSingle,
priceColo, priceSplit, priceSingle;

cout <<"Please enter the base price of Colonial house: ";
cin >>basedColonial;

cout <<"Please enter the finished area in square foot of the Colonial house: ";
cin >>finishedColo;

cout <<"\n \n";

cout <<"Please enter the base price of Split-Entry house: ";
cin >>basedSplitEntry;

cout <<"Please enter the finished area in square foot of the Split Entry House: ";
cin >>finishedSplit;

cout <<"\n \n";

cout <<"Please enther the base price of the Single-Storey House: ";
cin >>basedSingleStorey;

cout <<"Please enter the finished area in square foot of the Single-Storey House: ";
cin >>finishedSingle;

cout <<"\n \n";
cout <<"The price of Colonial House is " <<" RM" <<basedColonial
<<" per " <<finishedColo <<" square foot \n" <<endl;

cout <<"The price of Split-Entry House is " <<" RM" <<basedSplitEntry
<<" per " <<finishedSplit <<" square foot \n" <<endl;

cout <<"The price of Single-Storey House is " <<" RM" <<basedSingleStorey
<<" per " <<finishedSingle <<" square foot \n\n" <<endl;


priceColo = basedColonial / finishedColo;
priceSplit = basedSplitEntry / finishedSplit;
priceSingle = basedSingleStorey / finishedSingle;


if ((priceColo <= priceSplit) && (priceColo <= priceSingle))
cout <<"Colonial house is the cheapest one. \n" <<endl;
else if ((priceSplit <= priceColo) && (priceColo >= priceSingle))
cout <<"Split-Entry house is the cheapest one. \n" <<endl;
else if ((priceSingle <= priceSplit) && (priceSplit >= priceColo))
cout <<"Single-Storey house if the cheapest one. \n" <<endl;




getchar();
getchar();
return EXIT_SUCCESS;
}
How To Write:
a.Problem Analysis
b.Algorithm
c.Flowchart
d.Pseudocode
f.Output
Well a - d should have been done before you even started to write your program. You have a program so now all you need to do is compile and run it to find out the output (f).

For the rest you may want to start something like:
https://codeburst.io/10-steps-to-solving-a-programming-problem-8a32d1e96d74
Do you know anything about classes, or functions yet?

Or is it all just copy/paste everything into main?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <string>
using namespace std;

class House {
private:
    double price;
    double area;
    string name;
public:
    void input(const string &name) {
        this->name = name;
        cout <<"Please enter the base price of " << name << " house: ";
        cin >>price;
        cout <<"Please enter the finished area in square foot of the " << name << " house: ";
        cin >>area;
    }
    double getPricePerUnitArea() {
        return price / area;
    }
};

int main()
{
    House houses[3];
    houses[0].input("Colonial");
    houses[1].input("Split-Entry");
    houses[2].input("Single-Storey");
    return 0;
}
I just know some basics commands only.

#include<iostream>
#include<iomanip>
#include<math.H>

double
int
string

Topic archived. No new replies allowed.