Question

we defined, implemented, and tested a class Time. In this lab, we will continue working with...

we defined, implemented, and tested a class Time. In this lab, we will continue working with the Time class. A. Separate the class definition and class implementation from the client program. Move the class definition into a header file named Time.h and move the class implementation into a cpp file named Time.cpp. Use preprocessor directive to include header files as needed. B. Modify the Time class as follows: 1. Replace the default constructor and overloaded constructor with a constructor with default parameters to initialize year, month, and day. The default value for the hour, minute, and second is 0. (See Classes and Objects slides page 30 for constructor with default parameters.) 2. Add a copy constructor to initialize year, month, and day using a Time object. 3. Add an equals function to compare two Time objects’ values. Return true if they are the same, otherwise, return false. The equals function has a formal parameter which is a Time object. C. In the main function, write statements to test constructors and equals function. D. Add a new text file named lab6data to your project. Copy and paste the following data (representing the hour, minute, and second) into the text file and save the file: 10 20 30 22 33 44 1 2 3 24 30 99 15 56 12 E. In the main function, create an array clocks that can hold 10 Time objects. Read data from the data file and store them into the clocks array. F. In the client program, write a printArray function to print out the contents of an array of Time objects. The function has the following function prototype: void printArray(Time array[], int arraySize); G. In the main function, call the printArray function to output the contents of the clocks array. Answer in c++

#include <iostream>
using namespace std;
class Time {
private:
   int hour;
   int minute;
   int second;
public:
   Time() {
       hour = 0;
       minute = 0;
       second = 0;
   }
   Time(int h, int m, int s) {
       hour = h;
       minute = m;
       second = s;
   }
   void setTime(int h, int m, int s) {
       if (h >=0 && h>23) {
           hour = 0;
       }
       else {
           hour = h;
       }
       if (m >=0 && m>59) {
           minute = 0;
       }
       else {
           minute = m;
       }
       if (s >=0 && s < 59) {
           second = 0;
       }
       else {
           second = s;
       }
   }
   void print() {
       cout << hour << "-" << minute << "-" << second << endl;
   }
  
   int getHour() {
       return hour;
   }
   int getMinute() {
       return minute;
   }
   int getSecond() {
       return second;
   }

};
int main()
{
  
   Time getUpTime;
   getUpTime.setTime(6, 30, 0);
   getUpTime.print();
   cout << getUpTime.getMinute() << endl;
  
   cout << endl << endl;
   Time alarms[5];
   alarms[0].setTime(9, 25, 00);
   alarms[1].setTime(10, 50, 00);
   alarms[2].setTime(12, 15, 00);
   alarms[3].setTime(01, 40, 00);
   alarms[4].setTime(02, 55, 00);
   for (int i = 0; i < 5; i++) {
       alarms[i].print();
   }
   return 0;
}

Homework Answers

Answer #1

output of above program all conditions and all operations to added

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the...
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the values for hours, minutes and seconds are a legal military time (i.e. 00 00 00 to 23 59 59) the program should display the formatted results (i.e. 12 34 56 should be displayed as 12:34:56). If there's an error for any of the entered values, an exception should be thrown and an error message should be displayed. Note, there are three exception conditions, one...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private data member for the triplet is a generic array with three elements. The triplet ADT has the following functions:  default constructor  explicit constructor: initialize the data member using parameters  three accessors (three get functions) which will return the value of each individual element of the array data member  one mutator (set function) which will assign values to the data member...
Utilize the code from last week Add a default, full, and copy constructor. Also add a...
Utilize the code from last week Add a default, full, and copy constructor. Also add a constructor that allows you to specify only the name of the video game with no high score or times played specified. Adjust your code to demonstrate use of all 4 constructors and output of the resulting objects. #include <iostream> #include <string> #include <iomanip> using namespace std; class VideoGame { private:     string name;     int highScore;     int numOfPlays; public:     VideoGame() {        ...
do (iii) and (iv) (i) This is a simple Point class interface file whose objects represent...
do (iii) and (iv) (i) This is a simple Point class interface file whose objects represent points in the cartesian plane #include <iostream> using namespace std; class Point { public:     Point()      // default constructor         Point(double x, double y); // another constructor         double x() const; // get function, return _x         double y() const; // get function, return _y private:         double _x, _y; }; (ii) Here is a test driver file for the Point class...
Complete the missing code for the constructors as indicated in the comments in all three header...
Complete the missing code for the constructors as indicated in the comments in all three header files. C++ mainDriver.cpp #include <string> #include "Address.h" #include "Date.h" #include "Person.h" using namespace std; int main() {    Person p1;    Person p2("Smith", "Bobby", "[email protected]", 111, "Main St", "Clemson",            "SC", 29630, 1, 31, 1998);    cout << endl << endl;    p1.printInfo();    p2.printInfo();    return 0; } Person.h #ifndef PERSON_H #define PERSON_H #include <iostream> #include <string> using namespace std; class...
1. Complete a class Clock that represents time on a 24-hour clock, such as 00:00, 15:30,...
1. Complete a class Clock that represents time on a 24-hour clock, such as 00:00, 15:30, or 23:59 ○ Time is measured in hours (00 – 23) and minutes (00 – 59) ○ Times are ordered from 00:00 (earliest) to 23:59 (latest) Complete the first constructor of the class Clock ● It takes two arguments: h and m and creates a new clock object whose initial time is h hours and m minutes ● Test cases: Clock clock1 = new...
Hello, in my programming class we have to create a function that will receive a time...
Hello, in my programming class we have to create a function that will receive a time in units of seconds and must return the equivalent time in units of hours-minutes-seconds. The function must also be called from main. I have attached what I have so far if someone could help me finish it that would be great.   int convert(void); int main() {    int time;    time = convert();    printf("Hour:Minute:Seconds is %d\n", time);       return 0; } int...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...