Problem set

There are four problems to code

  • Problem 1 - Construct classes according to specification. Practice on creating dynamic objects. Problem is relevant to the final project.
  • Problem 2 - Utilize file streams in C++. Read data from a file and write into another file.
  • Problem 3 - Work on operator overloading. Distinguish member and nonmember implementation operators for a class and use of the friend declaration.

1. Define the class Robot with properties and functions given in the UML diagram below: The robot moves in a xy-plain, its location on the xy-plain is the ordered pair (xLocation, yLocation). The Robot object has a cargo bed that is either full(true) or empty (false). The Robot can carry a single character in its cargo bed.

Figure: see image.

a) Implement all the functions given in the UML diagram. The Robot can only move one unit at a time in either left, right, up or down directions. The moveTo(int x, int y) function checks the current position of the Robot at (xLocation, yLocation) then using loops moves the Robot ( one unit at a time) to the new location given by parameters x and y.

b) Write a main function in which a dynamic array of three Robot objects is created and populated. Move the Robots to different locations and assign different loads to them. Print the Robots.

2. (a) Write a program that reads a text file in which each line in the file consists of a first name, a last name, following by 4 grades (double types) like

Tim Hanes 78.3 98.0 80.5 72.3

The program must read every line of the text file, find the average of the 4 grades then print the names followed by the averages (one name per line) in a second file as well as on the monitor.

b) Create the text file with at least 5 entries with the format given in part (a). Give the absolute path of the file in your computer. Test your program in part 2(a) on this file.

3. In this problem we will be overloading some operators for the Rectangularcube class we defined in Assignment 1. Recall,

Define the class Rectangularcube. A Rectangularcube has three sides length(L), width (W), and Height (h), define the sides as private data fields. Include a no-argument constructor that sets all three sides to 1. The class must also have a constructor with parameters that receive parameters to initialize sides of the Rectangularcube. Include get and set functions for all three data fields. Finally define the functions volume () and surfaceArea () in the class Rectangularcube that use the formulas given below to calculate and return the volume and the surface area of the Rectangularcube.

Figure: see image.

(a) Overload the output operator "<<" as a nonmember function in the Rectangularcube class to print its length, width, height, volume and surface area. Describe the purpose of a friend function, would you make the operator<< function a friend of the class? Explain

(b) Overload the operator "<" for the Rectangularcube class as a nonmember function. The operator should return true if the volume of the first parameter is less than the volume of the second parameter. Describe the purpose of a friend

(c) Overload the operator+ as a member function. Clearly state how you define the sum of two Rectangularcube objects. Implement the operator.

(d) Overload the subscript operator [], such that index 0 accesses length, index 1 accesses width and index 2 accesses the height of the Rectangularcube.

(e) Write a main function to test the overloaded operators.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.