// Classes_Part2.cpp : main project file. /* _____________________________________________________ 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/22/2017 CLR VERSION This version of the Area app shows how to create 3 instances of the Room class so we can find the total area of three rooms. However, each Room 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 Room and make it inline and managed. //Step 2: In this file, add an include "Room.h" directive so we can access it. #include "stdafx.h" #include "Room.h" using namespace System; int main(array ^args) { double number; // To hold input double totalArea; // The total area double getDimension (); // helper method to get user input void NotifyUser (String^); // helper method to display prompts Room^ kitchen = gcnew Room; // To hold kitchen dimensions Room^ bedroom = gcnew Room; // To hold bedroom dimensions Room^ den = gcnew Room; // To hold den dimensions NotifyUser("Welcome to My Room Area Calculator Version 2\n\n"); NotifyUser ("Now let's calculate the area of three rooms....\n\n"); // Get the kitchen dimensions. Console::Write("What is the kitchen's length? "); number = getDimension (); // Get the length kitchen->setLength (number); // Store in kitchen object Console::Write("What is the kitchen's width? "); number = getDimension (); // Get the width kitchen->setWidth (number); // Store in kitchen object // Get the bedroom dimensions. Console::Write("\n\nWhat is the bedroom's length? "); number = getDimension (); // Get the length bedroom->setLength (number); // Store in bedroom object NotifyUser("What is the bedroom's width? "); number = getDimension (); // Get the width bedroom->setWidth (number); // Store in bedroom object // Get the den dimensions. Console::Write("\n\nWhat is the den's length? "); number = getDimension (); // Get the length den->setLength (number); // Store in den object Console::Write("What is the den's width? "); number = getDimension (); // 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. NotifyUser("\n\n\nThe total area of the three rooms is " + totalArea.ToString("n2") + "\n\n"); Console::ReadKey (); return 0; } //---HELPER FUNCTIONS TO GET/DISPLAY USER INPUTS double getDimension () { return Convert::ToDouble(Console::ReadLine ()); } void NotifyUser (String^ msg) { Console::Write (msg); return; }