1. Engineering
  2. Computer Science
  3. c...

Question: c...

Question details

C++CS 116 Programming Assignment 1: Define a time class named HoursMinutes that will encapsulate time calculations. Store the time in a single private data member named totalMinutes. The class should provide the following methods: 1. a Constructor that takes two integer parameters named h and m that represent the desired hours and minutes. The minutes parameter does not need to be restricted to< 60. A time of two hours can be constructed as HoursMinutes (2, θ) or HoursMinutes (0, 120). Keep this in mind when writing the add method 2. a getHours method returning an integer that is the whole number of hours. 3. a getMinutes method returning an integer that is the number of minutes remaining after the who le number of hourS Example: if time t is constructed as HoursMinutes (1, 20) then the totalMinutes data member would store 80, t.getHours() would return 1 and t.getMinutes) would return 20 4. a printHoursMinutes method that prints the time. For the time t described above, it would print 1 h 2θ m 5. an addHoursMinutes method that takes an HoursMinutes object as a parameter and adds it to the calling object time, returning a new HoursMinutes object that is the sum of the two times. 6. a scaleHoursMinutes method that takes an integer as a parameter and multiplies the calling object time by the integer, returning a new HoursMinutes object that is the scaled time. Write a main function that creates two time objects, prints them then adds the two times and prints the result. Also, use the scaling method to double the first time and triple the second time and print the results. For this assignment you do not need to separate the class definition and implementation into separate parts of the program or separate files. For now, we can restrict things to positive times only. I have provided two sample classes for feet and inches objects. The 2nd program uses some advanced features we will learn later, but if you have some programming experience, you can try adding them to your code.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution