C++ project completion needed (2 additional files of the room class test code and renovation class test code but the website would not let me upload)

7 November 2021 Project #4 COSC 05 1 Fall 2021 Page 1 of 10 Multiple Habitat Property Material Orders Learning Goals • Create, compile, and run a C++ program • Use basic data types to store program data • Use conditional execution • Receive input from the user ( cin ) • Perform basic input validation • Perform basic calculations with user data • Provide formatted output ( cout ) • Use an ifstream object to open and read a text file • Use repeated execution to read multiple lines of a file • Keep running totals of several data values • Format tabulated data output to the terminal • Parallel vectors • Menu driven programs • Object -Oriented Design/Programming • Function Overloading • Operator Overloading Overview For this project, we are going to use object -oriented programming and classes. Specifically, we will modify the Habitat for Humanity problem that we solved in Project 3 . As before, the modified program will also compute building materials over multiple sites . In Project 3 we faced a number of different tasks: • Load a number of files that each contained a number of rooms • Check the rooms for errors while asking the user about over -rideable errors • Compute the materials needed • Show the materials needed • Not allow the user to take inappropriate actions, like computing when there are no rooms or when the errors have not been checked In designing classes , we need to consider how to t ake these factors into account. It is clear that we need to have the concept of a room, since that is the unit we are working in - rooms that need renovation. It is also clear we need the concept of a collection of rooms, which we can refer to as a renova tion. Therefore, we will have two classes: a Room class, and a Renovation class which holds a number of rooms. Project Specification Room Class The Room class will hold all measurement and data information about a room. Given that this is where that data are stored, it also makes sense to have the error checking done here. A Room object can examine its data to determine if there are errors , store the results of error checking, and ensure that error checking was done before anything else is done. Since t he measurements are here, it also makes sense to do the material calculations here. We will therefore use the class de claration below for these functions: 7 November 2021 Project #4 COSC 05 1 Fall 2021 Page 2 of 10 Most of the private data members should be familiar. The items with a prefix of material_ are the things that are calculated based on the measurements. The error data member indicates if there is an error in the room measurements that has not been over -ridden. The error_checked data member indicates that the room has been checked for errors . If there has not been a check for errors then computing materials should be prohibited until that has happened. Member and non -member functions for the Room class are described in more detail below. friend istream& operator>>(istream &in, Room &r); Th e overloaded stream extraction operator is a friend function allow s reading directly from a file into a Room class object. Notice that for this project the file format is slightly different to make things a bit less complicated. class Room { friend istream& operator>>(istream &in, Room &r); friend ostream& operator<<(ostream &out, Room r); public: Room(); Room(string, string, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int); bool ha ve_error(); bool check_error(); bool compute_materials(double &, double &, unsigned int &, unsigned int &); void print_material_header(); void print_materials(); void print(); private: string property; string room; unsigned int wall1_ft; unsigned int wall1_in; unsigned int wall2_ft; unsigned int wall2_in; unsigned int ceiling_ft; unsigned int ceiling_in; unsigned int door_count; unsigned int window_count; unsigned int window_height; unsigned int window_width; bool error; bool error_checked; double material_cost; double material_weight; unsigned int material_sheets; unsigned int material_boxes; }; // END declaration for class Room 7 November 2021 Project #4 COSC 05 1 Fall 2021 Page 3 of 10 Instead of the property name appearing only once at the top of the file, it is now the first item on each line of the file. Like the room name, the property name is guaranteed to not ha ve spaces. The new file format is shown below. friend ostrea m& operator<<(ostream &out, Room r); Th e overloaded stream insertion operator is a friend function used to output information about a room that has been loaded. The output format is the same as format of the show_properties and the show_errors functions from Project 3 . Room(); This is the default constructor. Data members will have random or unknown values unless they are initialized . The default constructor shall provide all data members with an initial value that we specify. Room(string, string, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int); This is a constructor with parameters that we shall use to instantiate a Room object with known values. Please note that it also needs to initialize data memb ers that are not set via a parameter. This constructor could also be use d to load a f ile before the friend functions have been implemented. However, you use the overloaded stream extraction operator to load file data as soon as that friend function is wo rking. bool have_error(); This just lets us know if there are errors in the room. bool check_error(); This performs the check for errors and asks the user if they want to override a recoverable error. It also sets the error and error_checked data members. bool compute_materials(double&, double&, unsigned int&, unsigned int&); This method performs the calculations for materials and updates the material_ data members with the result of those calculation s. If errors have not been checked it stops without making any calculations and return s fal se. If the room has errors that have not been over -ridded, then the function s tops without making any calculations and returns false. This method does not output anything, it just performs the calculations . Notice that the four reference parameters correspond to the four material_ data members. These parameters are NOT passing the da ta members. Like all class methods, the compute_materials function already has access to the class' data members. The purpose of these reference parameters is to pass variables from outside of the class to compute the total over all rooms. 7 November 2021 Project #4 COSC 05 1 Fall 2021 Page 4 of 10 void print_ma terial_header(); This prints a neat header for output that shows the columns appropriately formatted. It does not output the results, just the header. My header looks like this: void print_materials(); This prints out the contents of the materials formatted like the headers above. An example would be: void print(); This method does not get used anywhere in the main program, b ut it is useful for testing and debugging . It will print out a label for and the contents of each private data member so you can see their current values . It can be used to make sure the overloaded stream extraction operator and the constructors are work ing as expected . Renovation Class This class will handle everything that needs to happen over a large group of Rooms. It will load them from files, store them, cause them all to check for errors, show which have errors, and do th e calculation of the total costs. Property Room Drywall Flooring Total Total Name Name Sheets Boxes Cost Weight ------------------------------------------------------------------------ ---------- 104 -Cleo -Drive Bedroom1 18 7 621.88 1005.86 class Renovation { public: Renovation(); unsigned int load_rooms(string); bool is_loaded(); bool is_checked(); void show_rooms(); void check_rooms_for_errors(); void show_rooms_with_errors(); void compute_totals(); void print_totals(); void clear(); private: vector rooms; double total_cost; double total_weight; unsigned int total_sheets; unsigned int total_boxes; bool loaded; bool checked; bool errors; }; // END declaration for class Renovation 7 November 2021 Project #4 COSC 05 1 Fall 2021 Page 5 of 10 The data members for the Renovation class are: vector rooms; This is a vector that holds all the rooms that have been read from the input file. double total_cost; double total_weight; unsigned int total_sheets; unsigned int total_boxes; The data members above hold the results of the computation of the overall costs of materials. bool loaded; This bool indicates if any files have been loaded into the vector yet. bool checked; This bool indicates if t he data has been checked for errors bool errors; This bool indicates if there are known errors in the data. The methods for the Renovation class are: Renovation(); This is the default constructor that initializes the class' data members. unsigned int load_rooms(string); This method loads rooms from a file using the overloaded stream extraction operator (operator >> ). It returns the number of lines loaded. This method should set the loaded data member appropriately. bool is_loaded(); Returns the value of the loaded data member. bool is_checked(); Returns the value of the checked data member. void show_rooms(); Outputs all rooms using the overloaded stream insertion operator ( operator << ). The format is th e same as the forma t of the show_properties function from Project 3 . 7 November 2021 Project #4 COSC 05 1 Fall 2021 Page 6 of 10 void check_rooms_for_errors(); This function c alls the check_erro r method of each Room object in the rooms vector. It also s ets the errors data member depending up on the results. void show_rooms_with_errors(); Prints out rooms that have errors using the overloaded stream insertion operator ( operator << ). The format is the same as the format of the show_errors function from Project 3 . void compute_totals(); This function c omputes the totals by iterating over the rooms vector and calling the compute_materials method of each Room object. void print_totals(); This method calls the compute _totals method to make sure they are calculated, then pri nts out the room header, the materials for each room, and then the totals. This method should also print out the warning if there is an error. This output is the same contents and the sa me format as th e compute_materials function from Proj ect 3. void clear(); Clears the vector and resets the appropriate data members. Function Main In the main function , you only need to create on e data object - a instance of the Renovation class. You can then use it to implement the menu. The main function no longer need s to track if the files have been loaded or if errors have been checked since that now happens in the Renovation class . Data Validation No changes from Project 3. Program Menu No changes from Project 3. 7 November 2021 Project #4 COSC 05 1 Fall 2021 Page 7 of 10 Project Deliverables What to Submit Submit to Canvas a .zip file containing your source code and the given Makefile . Locate the assignment Project 4 on Canvas and attach/upload your file. Do not post your executable file. You should ensure that your source code file compiles on the class server and that the executable file runs and produces the correct output. Use submit.zip as the name of the file you submit . The value for this project is 100 points. Use exactly the following file names ( with spelling and capitalization exactly as shown ): Makefile main.cpp Due Date and Time 17 November 20 21, no later than end -of-day (11:59pm). Late su bmissions will be penalized 2.5 points for each 15 minutes late . If you are over 10 hours late you may turn in the project to receive feedback but the grade will be zero. In general requests for extensions will not be consid ered . Creating submit.zip : Please , PLEASE, PLEASE use the provided Makefile and create your submit.zip file on the class server. If you create the compressed file on your laptop it is highly likely something will go wrong even though it looks fine. It is easy to compress links to files, instead of actual files. It is easy to have the folder containing the project files included in the compressed file. If this, or any other problems happen; your program will not compile, automated grading programs will fail, and you will get a zero . Assuming all of your files are in the same folder on the server, the process to create the submit .zip file is shown below. [waw23@cs -class -1 P4]$ make clean rm -f *.o core a.out [waw23@cs -class -1 P4]$ make submit rm -f submit.zip zip submit.zip main.cpp Makefile adding: main.cpp (deflated 85%) adding: Makefile (deflated 44%) [waw23@cs -class -1 P4]$ unzip -l submit.zip Archive: submit.zip Length Date Time Name --------- ---------- ----- ---- 50678 11 -08 -2021 03:49 main.cpp 329 11 -08 -2021 03:49 Makefile --------- ------- 51007 2 files [waw23@cs -class -1 P4]$ Remove files from last compile Create the zip file to submit Verify the zip file contents 7 November 2021 Project #4 COSC 05 1 Fall 2021 Page 8 of 10 Academic Integrity Your code is an individual project and all work must be your own. Refer to the guidelines specified in the Academic Honesty section of the course syllabus or contact an instructor if you have any questions. Include the following comments at the start of your source code file: These comments must appear exactly as shown above. The only difference will be values that you replace where there are "place holders" within angle brackets such as which should be replaced by your own netID . For example, I would replace on the "Author:" line with waw23 . /* * main.cpp * * COSC 051 Fall 202 1 * Project # 4 * * Due o n: 17 November 202 1 * Author: * * * In accordance with the class policies and Georgetown's * Honor Code, I certify that, with the exception of the * class resources and those items noted below, I have neither * given nor received any assistance on this project. * * References not otherwise commented within the program source code. * Note that you should not mention any help from the TAs, the professor, * or any code taken from the class textbooks. */ 7 November 2021 Project #4 COSC 05 1 Fall 2021 Page 9 of 10 Some Advice You probably can not build the whole project at once. As projects get larger you need to develop the code piece by piece and ensure that earlier pieces works before you move on to later pieces that dep end on earlier ones. If you write both at once, it can be hard to tell where the error is. To help you with this, two main functions are provided: • room_main • reno_main These can be used t o test code as it is written. The way you can use t his code is to first use room _main . Write methods one at a time then use room_main to test them. You will need to write code for the Room class in this order: Default constructor print Constructor with parameters check_error compute_materials print_material_header print_materials There are additional cases after that to test all the error conditions. Similarly, there is a reno_main that steps through checking the renovation class; again, go through it step by step. 7 November 2021 Project #4 COSC 05 1 Fall 2021 Page 10 of 10 Course Materials Notice The materials used in Georgetown University courses ("Course Materials") generally represent the intellectual property of course instructors which may not be disseminated or reproduced in any form for public distribution (e.g., sale, exchange, etc.) without the written permission of the course instructor. Course Materials include all written or electronic documents and materials, including syllabi, current and past examination questions/answers, and presenta tions such as lectures, videos, PowerPoints, etc., provided by a course instructor. Course Materials may only be used by students enrolled in the course for academic (course -related) purposes. Published course readings (book chapters, articles, reports, etc.) available in Canvas are copyrighted material. These works are made available to students through licensed databases or fair use. They are protected by copyright law, and may not be further disseminated or reproduced in any form for distrib ution (e.g., uploading to websites, sale, exchange, etc.) without permission of the copyright owner. More information about intellectual property and copyright can be found here: https://www.library.georgetown.edu/copyright . More information about computer acceptable use policy and intellectual property can be found here: https://security.georgetown.edu/it -policies -procedures/computer -systems -aup Copyright © 202 1 W. Woods. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed