Question

In: Computer Science

Question 5 The following is a description of the Time class and its actual Time.h: (A.)...

Question 5

  1. The following is a description of the Time class and its actual Time.h:

    (A.) Four Member Variables

            (1.) hour      (int)

            (2.) minute    (int)

            (3.) second    (int)

            (4.) count     (static int)

    (B.) Constructors (Each constructor should increment the count static member variable)

            (1.) A Default Constructor that initializes the time to 0:00:00

            (2.) A Single Parameter Constructor that initializes the time to x:00:00 (where x is the parameter value)

            (3.) A Double Parameter Constructor that initializes the time to x:y:00 (where x and y are the 1st and 2nd parameter values respectively)

            (4.) A Triple Parameter Constructor that initializes the time to x:y:z (where x, y, and z are the 1st, 2nd, and 3rd parameter values respectively)

    (C.) Accessor Functions for the 3 non-static member variables

    (D.) Mutator Functions for the 3 non-static member variables

    (E.) A Static Accessor Function for the static member variable

    (F.) An Input Function that uses console input to change the values of the Time instance

    (G.) An Output Function that displays the Time object on the console in the format - hour:minute:second

    /****************** Time.h *********************/

    #ifndef TIME_H

    #define TIME_H

    #include <iostream>
    #include <iomanip>

    class Time {

    public:

        Time();
    Time(int h);
    Time(int h, int m);
    Time(int h, int m, int s);

    //Accessor
    int getHour() const;
    int getMinute() const;
    int getSecond() const;
    static int getCount();

    //Mutator
    void setHour(int h);
    void setMinute(int m);
    void setSecond(int s);

    void input();
    void output() const;

    private:

    int hour, minute, second;
    static int count;

    };

    #endif

    Here is the main.cpp:

    /****************** main.cpp *********************/

    #include <iostream>

    #include <iomanip>

    #include "Time.h"

    int main() {

        Time t1, t2(3), t3(3,5), t4(15, 25, 35), t5(7);

        std::cout << "First time object:\n";

        t1.output();

        t1.input();

        t1.output();

        std::cout << std:: endl;

        std::cout << "Second time object:\n";

        t2.output();

        t2.input();

        t2.output();

        std::cout << std:: endl;

        t3.output();

        t4.output();

        t5.output();

    std::cout << "The total count is " << Time::getCount()

                  << std::endl;

        return 0;

    }

    And a sample run:

    [ctse@venus fa20]$ g++ Time.cpp main.cpp

    [ctse@venus fa20]$ ./a.out

    First time object:

    Time instance = 00:00:00

    Change hour? Y/N

    Y

    Enter hour: 1

    Change minute? Y/N

    N

    Change second? Y/N

    N

    Time instance = 01:00:00

    Second time object:

    Time instance = 03:00:00

    Change hour? Y/N

    N

    Change minute? Y/N

    N

    Change second? Y/N

    N

    Time instance = 03:00:00

    Time instance = 03:05:00

    Time instance = 15:25:35

    Time instance = 07:00:00

    The total count is 5

    [ctse@venus fa20]$

    Provide the Time.cpp (You don’t need to comment).  

Solutions

Expert Solution

//IF YOU ARE SATISFIED WITH THE CODE, KINDLY LEAVE A LIKE, OR ELSE COMMENT TO CLEAR DOUBTS

//AS ASKED ONLY PROVIDED THE TIME.CPP

Time.cpp

#include <iostream>

#include <iomanip>

#include "Time.h"

using namespace std;

int Time::count = 0;

Time::Time(){

    hour = minute = second = 0;

    ++count;

}

Time::Time(int h){

    hour = h;

    minute = second = 0;

    ++count;

}

Time::Time(int h, int m){

    hour = h;

    minute = m;

    second = 0;

    ++count;

}

Time::Time(int h, int m, int s)

{

    hour = h;

    minute = m;

    second = s;

    ++count;

}

int Time::getHour() const{

    return hour;

}

int Time::getMinute() const

{

    return minute;

}

int Time::getSecond() const

{

    return second;

}

void Time::setHour(int h){

    hour = h;

}

void Time::setMinute(int m)

{

    minute = m;

}

void Time::setSecond(int s)

{

    second = s;

}

int Time::getCount(){

    return count;

}

void Time::output() const{

    cout<<"\nTime instance = ";

    cout << setw(2) << setfill('0') << hour << ":";

    cout << setw(2) << setfill('0') << minute << ":";

    cout << setw(2) << setfill('0') << second;

    cout<<endl;

}

void Time::input(){

    char choice;

    int temp;

    cout<<"\nChange hour? (Y/N) :";

    cin>>choice;

    if(choice == 'Y' || choice == 'y'){

        cout<<"Enter hour: ";

        cin>>temp;

        setHour(temp);

    }

    cout << "Change minute? (Y/N) :";

    cin >> choice;

    if (choice == 'Y' || choice == 'y')

    {

        cout << "Enter minute: ";

        cin >> temp;

        setMinute(temp);

    }

    cout << "Change second? (Y/N) :";

    cin >> choice;

    if (choice == 'Y' || choice == 'y')

    {

        cout << "Enter second: ";

        cin >> temp;

        setSecond(temp);

    }

}

CODE OUTPUT:


Related Solutions

Question 5 – Chapter 10 Working With Variances From the following data, determine the total actual...
Question 5 – Chapter 10 Working With Variances From the following data, determine the total actual costs incurred for direct material, direct labor, and variable overhead. Standard Costs Variances Direct material $155,000 Price variance 3,000 U Quantity variance 4,000 F Direct labor 135,000 Rate variance 1,400 U Efficiency variance 1,800 U Variable overhead 79,000 Spending variance 1,000 F Efficiency variance 600 U Actual Costs Direct material Direct labor Variable overhead
I have 5 multiple choice question related to my accounting class. 1. In the "time interest...
I have 5 multiple choice question related to my accounting class. 1. In the "time interest earned" ratio, the numerator should be income before deducting (select the best answer): A. interest Expense B. Income tax expense C. Both A & B D. None of the above 2. A lender accepts real estate with a fair value of $15,000,000 in full settlement of a $20,000,000 loan. the real estate has a carrying value of $19,000,000 on the bond of the borrower....
Description This problem involves forecasting techniques only Instructions Question 1 contains the actual values for 12...
Description This problem involves forecasting techniques only Instructions Question 1 contains the actual values for 12 periods (listed in order, 1-12). In Excel, create forecasts for periods 6-13 using each of the following methods: 5 period simple moving average; 4 period weighted moving average (0.63, 0.26, 0.08, 0.03); exponential smoothing (alpha = 0.23 and the forecast for period 5 = 53); linear regression with the equation based on all 12 periods; and quadratic regression with the equation based on all...
QUESTION 5 Jason Ltd receives a one-time order that is not considered part of its normal...
QUESTION 5 Jason Ltd receives a one-time order that is not considered part of its normal ongoing business. Jason Ltd makes a single product with a unit variable manufacturing cost of $10. This is made up of direct material $4, direct manufacturing labour $2, and variable MOH allocated $4 per unit. Variable marketing cost for the product is $2 per unit. Normal selling price is $25 per unit. Annual capacity is 10,000 units, and actual annual fixed costs total $58,000....
QUESTION 1 Match the specific risk on bonds to its description.       -      ...
QUESTION 1 Match the specific risk on bonds to its description.       -       A.       B.       C.       D.    The chance that the bond's par value will lose purchasing power.       -       A.       B.       C.       D.    The chance that the bond buyer will not receive interest and principal payments when due       -       A.       B.      ...
A UML class diagram has the following description about a member of the class: + getHeaderField(name:String):String...
A UML class diagram has the following description about a member of the class: + getHeaderField(name:String):String Which of the following is a correct declaration of the member in Java? 1 public String getHeaderField(String name) 2 public String getHeaderField; 3 public String getHeaderField(String) 4 public static String getHeaderField( name) ------------------------------------------------------------------------------------------------------------------------------------- Note: all answers are case sensitive. Inside a class, the declaration of a constructor looks like the following: public JButton(String text) 1. From the constructor, you infer that the name of...
Second time posting: Actual question is How would you structure the datasets to analyze this relationship?...
Second time posting: Actual question is How would you structure the datasets to analyze this relationship? For some reason everyone discusses the trade and economic growth as if this is a writing class but Im just trying to figure out how to answer the question about analyzing the relationship with datasets. THANKS Lets say you are interested in how levels of trade for countries influence economic growth. How would you structure the dataset to analyze this relationship
5 Question the most appropriate description to the term. A section of memory is lost after...
5 Question the most appropriate description to the term. A section of memory is lost after a blow to the head 1. Retrograde Amnesia 2. Trace transformation 3. Amnesia 4. Sleeper Effect 5. Karsokoff Syndrome 6. Repression 7. Encoding Failure Dementia and forgetfulness due to malnutrition 1. Retrograde Amnesia 2. Trace transformation 3. Amnesia 4. Sleeper Effect 5. Karsokoff Syndrome 6. Repression 7. Encoding Failure? Plaque build up damages memories 1. Retrograde Amnesia 2. Trace transformation 3. Amnesia 4. Sleeper...
Q1.Consider an inventory system in discrete time with the following description. At the beginning of the...
Q1.Consider an inventory system in discrete time with the following description. At the beginning of the period the inventory decreases by one unit if the inventory level at the beginning is positive other the level remains zero till the end of the period. At the end of the period nth period, the inventory is increased by an amount Vn, where {Vn|n ≥ 1} is i.i.d. with P{V1 = i} = pi , i ≥ 0. Let Xn denote the level...
Q1.Consider an inventory system in discrete time with the following description. At the beginning of the...
Q1.Consider an inventory system in discrete time with the following description. At the beginning of the period the inventory decreases by one unit if the inventory level at the beginning is positive other the level remains zero till the end of the period. At the end of the period nth period, the inventory is increased by an amount Vn, where {Vn|n ≥ 1} is i.i.d. with P{V1 = i} = pi , i ≥ 0. Let Xn denote the level...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT