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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <iostream> //
#include <iomanip>
#include <string>
#include <cstring>
#include "rect.h"
using namespace std; // <--- Best not to use.
double Rectangle::yardsAvail = 400;
int main()
{
Rectangle r1(20, 20, "Kitchen");
Rectangle r2(20, 20, "Bathroom");
Rectangle r3(20, 20, "Office");
TestRect tr;
cout <<
std::boolalpha << // <--- Only needs done once.
"Test on r1: " << tr.tester(r1) << "\n"
"Test on r2: " << tr.tester(r2) << "\n"
"Test on r3: " << tr.tester(r3) << "\n"; // <--- Added.
Rectangle house[]
{
Rectangle(0, 0, "Dummy"), // <--- Quick and dirty fix. The if statements need changed. Not adding this line.
Rectangle(10, 12, "Kitchen"),
Rectangle(20, 20, "Bedroom"),
Rectangle(8, 12, "Offce")
};
std::cout << '\n';
constexpr size_t ARR_SIZE{ sizeof(house) / sizeof(house[0]) };
for (int i = 1; i < ARR_SIZE; i++)
{
if (strcmp(house[i].printName(), "Offce") == 0)
{
// cout << "oui\n";
house[i].setName("Office");
};
cout << " Area for " << house[i].printName() << " is : " << house[i].getArea() << '\n';
}
// <--- These sub-scripts need changed.
if (house[1].getArea() > house[2].getArea() && house[1].getArea() > house[3].getArea())
{
cout << "\n " << house[1].printName() << " has the biggest area.\n";
}
else if (house[2].getArea() > house[1].getArea() && house[2].getArea() > house[3].getArea())
{
cout << "\n " << house[2].printName() << " has the biggest area at " << house[2].getArea() << " square feet.\n";
}
else
{
cout << "\n " << house[3].printName() << " has the biggest area\n";
}
// <--- Keeps console window open when running in debug mode on Visual Studio. Or a good way to pause the program.
// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
//std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue: ";
std::cin.get();
return 0; // <--- Not required, but makes a good break point.
}
|