// Native_Classes_Part2.cpp : Defines the entry point for the console application. /* _____________________________________________________ W O R K I N G W I T H C L A S S E S P A R T 2 Ron Kessler Created 1/20/2017 This version of the rectangle app shows how to create 3 instances of the Rectangle class so we can find the total area of three rooms. However, each Rectangle object we create holds different sets of data. This data is stored with each object in memory. Here we reuse our class to make our coding way easier! We are resuing the same class three times. (Resuablity) It is easier to maintain than a procedural version. (Maintainability) It can be extended (Extensibility) by simply adding another class for and entire house. _____________________________________________________ */ //Step 1: Add a new class to the project called Rectangle and make it inline. //Step 2: In this file, add an include "Rectangle.h" directive so we can access it. //Run with CTL-F5 #include "stdafx.h" #include #include //so we can format our output #include "Rectangle.h" //the class you just made using namespace std; int main () { double number; // To hold input double totalArea; // The total area Rectangle kitchen; // To hold kitchen dimensions Rectangle bedroom; // To hold bedroom dimensions Rectangle den; // To hold den dimensions //---tell cout how to format our doubles with 2 decimal places cout << setprecision (2) << fixed; cout << "Welcome to My Room Area Calculator Version 2" << "\n\n"; cout << "Now let's calculate the area of three rooms....\n\n"; // Get the kitchen dimensions. cout << "What is the kitchen's length? "; cin >> number; // Get the length kitchen.setLength (number); // Store in kitchen object cout << "What is the kitchen's width? " ; cin >> number; // Get the width kitchen.setWidth (number); // Store in kitchen object // Get the bedroom dimensions. cout << "\n\nWhat is the bedroom's length? "; cin >> number; // Get the length bedroom.setLength (number); // Store in bedroom object cout << "What is the bedroom's width? "; cin >> number; // Get the width bedroom.setWidth (number); // Store in bedroom object // Get the den dimensions. cout << "\n\nWhat is the den's length? "; cin >> number; // Get the length den.setLength (number); // Store in den object cout << "What is the den's width? " ; cin >> number; // Get the width den.setWidth (number); // Store in den object // Calculate the total area of the three rooms. totalArea = kitchen.getArea () + bedroom.getArea () + den.getArea (); // Display the total area of the three rooms. cout << "\n\n\nThe total area of the three rooms is " << totalArea << endl; return 0; }