Question

C++ Please! Given this definition of a Time class: class Time { private: int hour, min,...

C++ Please!

Given this definition of a Time class:

class Time {
private:
int hour, min, sec;
public:
Time() { hour = 0; min = 0; sec = 0; }
Time(int h, int m, int s) {
     hour = h; min = m; sec = s;
}
int getHour() const {
    return hour;
}
int getMin() const {
    return minute;
}
int getSec() const {
    return sec;
}
};

Derive a class MilTime from the Time class. The MilTime class should convert time in military format to the standard format used by the Time class.

The MilTime class should have the following member variables:

milHours: Contains the hour in 24-hour format.
milSeconds: Contains the seconds in standard format.

The class should have the following member functions:

Constructor: The constructor should accept arguments for the hour and seconds, in military format. The time should then be converted to standard time and stored in the hours, min, sec variables of the Time class.

setTime: Accepts arguments to be stored in the milHours and milSeconds variables. The time should then be converted to standard time and stored in the hours, min, and sec variables of the Time class.

getHour: Returns the hour in military format.

getStandardHr: Returns the hour in standard format.

Demonstrate the class in a program that askes the user to enter the time in military format. The program should then display the time in both military format and standard format.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

#include <iostream>
#include <string>
#include <cmath>
using namespace std;

class Time {
protected:
int hour, min, sec;
public:
Time() { hour = 0; min = 0; sec = 0; }
Time(int h, int m, int s) {
hour = h; min = m; sec = s;
}
int getHour() const {
return hour;
}
int getMin() const {
return min;
}
int getSec() const {
return sec;
}
};

class MilTime: public Time
{
private :
    int milHours;
   int milSeconds;
public :  
MilTime(int milHours,int milSeconds)
{
   this->milHours=milHours;
   this->milSeconds=milSeconds;
   setTime(milHours,milSeconds);
   }
   void setTime(int milHours,int milSeconds)
   {
       int fhrs,fmins;
       fhrs = milHours / 100;
      
  
if (fhrs > 12 && fhrs < 23)
{
fhrs -= 12;
}

fmins = milHours % 100;
  
       hour=fhrs;
       min=fmins;
       sec=milSeconds;
      
      
   }
   int getHour()
   {
       return milHours;
   }
   int getStandardHr()
   {
       return Time::getHour();
   }
  
  
  
};
   int main()
   {
int milHr,milsecs;

cout<<"Enter time in milatary format :";
cin>>milHr;
cout<<"Enter no of seconds :";
cin>>milsecs;

MilTime m(milHr,milsecs);
cout<<"Time in Military Format :"<<m.getHour()<<":"<<milsecs<<endl;
cout<<"Time in Standard Format :"<<m.getStandardHr()<<":"<<m.getMin()<<":"<<m.getSec()<<endl;

       return 0;      
   }

_______________________

output:

_______________Thank You

Add a comment
Know the answer?
Add Answer to:
C++ Please! Given this definition of a Time class: class Time { private: int hour, min,...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write in C++ please In Chapter 10, the class clockType was designed to implement the time...

    Write in C++ please In Chapter 10, the class clockType was designed to implement the time of day in a program. Certain applications, in addition to hours, minutes, and seconds, might require you to store the time zone. Derive the class extClockType from the class clockTypeby adding a member variable to store the time zone. Add the necessary member functions and constructors to make the class functional. Also, write the definitions of the member functions and the constructors. Finally, write...

  • C++ class Time { public: Time(); Time(int hrs, int min, int sec); private: int hours; int...

    C++ class Time { public: Time(); Time(int hrs, int min, int sec); private: int hours; int minutes; int seconds; }; 1. Write the class definition for ExtendedTime which derives from Time via public inheritance. Add private data member time_zone which is an enum type TimeZone (enum TimeZone { PACIFIC, MOUNTAIN, CENTRAL, EASTERN } ). Add a default and alternate constructors to ExtendedTime to initialize all class (including the base class) data; use the base member initialization list. NOTE: This implies...

  • Cloekt Cloek ( int, int, int) etTire(int, int, intjt void getHour printTime voia int int teqran...

    Cloekt Cloek ( int, int, int) etTire(int, int, intjt void getHour printTime voia int int teqran le (Clock)boolean 46. According to the UML class diagram above, which of the following is a. ClockO _ data member c. min d. Clock b. According to the UML class diagram above, which method is pablic and doesn't return anything? a getCopyO b. setTime(int, int, int) which ofthe following would be a default constructor ior he ein. Click does is te ips bro a....

  • [Java] We have learned the class Clock, which was designed to implement the time of day...

    [Java] We have learned the class Clock, which was designed to implement the time of day in a program. Certain application in addition to hours, minutes, and seconds might require you to store the time zone. Please do the following: Derive the class ExtClock from the class Clock by adding a data member to store the time zone. Add necessary methods and constructors to make the class functional. Also write the definitions of the methods and constructors. Write a test...

  • Please help with Java programming! This code is to implement a Clock class. Use my beginning...

    Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock { // Declare your fields here /** * The constructor builds a Clock object and sets time to 00:00 * and the alarm to 00:00, also. * */ public Clock() { setHr(0); setMin(0); setAlarmHr(0); setAlarmMin(0); } /** * setHr() will validate and set the value of the hr field * for the clock. * *...

  • Need help with this java code supposed to be a military time clock, but I need...

    Need help with this java code supposed to be a military time clock, but I need help creating the driver to test and run the clock. I also need help making the clock dynamic. public class Clock { private int hr; //store hours private int min; //store minutes private int sec; //store seconds public Clock () { setTime (0, 0, 0); } public Clock (int hours, intminutes, int seconds) { setTime (hours, minutes, seconds); } public void setTime (int hours,int...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • In this practical task, you need to implement a class called MyTime, which models a time...

    In this practical task, you need to implement a class called MyTime, which models a time instance. The class must contain three private instance variables: hour, with the domain of values between 0 to 23. minute, with the domain of values between 0 to 59. second, with the domain of values between 0 to 59. For the three variables you are required to perform input validation. The class must provide the following public methods to a user: MyTime() Constructor. Initializes...

  • D Question 6 4 pts Figure 1: clock Type |-hr: int -min: int -sec; int setTime...

    D Question 6 4 pts Figure 1: clock Type |-hr: int -min: int -sec; int setTime (int, int, int): void get Time (inte, int&, int&) const: void printTime() const: void increment seconds(): int +incrementMinutes(): int +increment Hours(): int -equalTime (const clockType.) const: bool Consider the UML class diagram shown in the accompanying figure. According to the UML class diagram, how many private members are in the class? none zero two three D Question 4 4 pts Consider the following class...

  • My if/else statement wont run the program that I am calling. The menu prints but once...

    My if/else statement wont run the program that I am calling. The menu prints but once I select a number the menu just reprints, the function called wont run. What can I do to fix this probelm? #include <iostream> #include "miltime.h" #include "time.h" #include "productionworker.h" #include "employee.h" #include "numdays.h" #include "circle.h" using namespace std; int main() { int select=1;     while (select>0) { cout << "Option 1:Circle Class\n"<< endl; cout << "Option 2:NumDay Class\n" << endl; cout <<"Option 3:Employee and Production...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT