CISS 243 Week 1 Operator Overloading

Assignment 1
Number of Days. Design a class called NumDays. The class’s purpose is to store a value that will convert the number of worked hours to a number of days. For example, 8 hours would be converted to 1 day, 12 hours would be converted to 1.5 days and 18 hours converted to 2.25 days. The class must have a constructor that accepts a number of hours. There must also be member function to set and get the hours and days. The class should have 2 data members, hours and days.
The class will also overload several operators:

  • the addition operator. This operator will add the hours of the two objects and return a new instance of the NumDays with its hour’s data member set to the sum of the other two objects.
  • the subtraction operator will also be overloaded which will subtract the two objects and return a new instance of the NumDays class.
  • the prefix and postfix increment operator. These operators should increment the number of hours stored in the object. It will return an instance of the NumDays object.
  • the prefix and postfix decrement operator. These operators should decrement the number of hours stored in the object. It will return an instance of the NumDays object.

Note that when the number of hours changes, the number of days should always be updated. The user of this class should be able to use the object in a statement like C = A + B; where A, B and C are instances of the NumDays class. Main must show that the class and all the operators work correctly.

Assignment 2
Carpet Calculator. This problem starts with the FeetInches class that is provided in the course Content area on the assignment page for this week. This program will show how classes will interact with each other as data members within another class. Modify the FeetInches class by overloading the following operators which should all return a bool.

  • <=
  • >=
  • !=

Next add a copy constructor to the FeetInches class and a multiply function.

  • The copy constructor should accept a FeetInches object as an argument. It will assign the feet attribute the value in the argument’s feet attribute and do the same for the inches attributes.
  • The multiply function should accept a FeetInches object as an argument. The argument object’s feet and inches attributes will be multiplied by the calling object’s feet and inches attributes. It will return a FeetInches object containing the result of the multiplication.

Next create a class called RoomDimension which will have its class declaration in RoomDimension.h and its implementation in RoomDimension.cpp. This class will have two data members which have a data type of FeetInches, one for the length of the room and another for the width of the room. The multiply function in FeedInches will be used to calculate the area of the room. RoomDimension will have a function that returns the area of the room as a FeetInches object.

Next create a class called RoomCarpet class that has a Room Dimension object as an attribute. This class will have its class declaration in RoomCarpet.h and its implementation in RoomCarpet.cpp. It should also have an attribute for the cost of the carpet per square foot. It will have a member function that returns the total cost of the carpet. For example, a room that is 12 feet long and 10 feet wide has an area of 120 square feet. If the cost per square foot is $8 then the cost to carpet the room will be $960 (120 x 8).

The main for this program will create an instance of RoomCarpet and ask the user for the dimensions of the room and the price per square foot for the carpet. The application should then display the total cost of the carpet. It should allow the user to continue doing more calculations until the user indicates they are done.

Note: The assignments must be completed with all source code files, including .cpp and .h (.h files only needed when working with classes), submitted to the correct dropbox by the end of the week.