Question

In: Computer Science

Please read and understand the following program code. Use it to answer the following 4 questions....

  1. Please read and understand the following program code. Use it to answer the following 4 questions.

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

class timeStamp // uses 24-hour times (0..24)

{

public:

    timeStamp(void);

    timeStamp(int, int, int);

    void setTime(int, int, int);

    timeStamp *addTimes(timeStamp *);

    timeStamp *subTimes(timeStamp *);

    string toString(void);

    int hour;

    int minute;

    int second;

};

int main()

{

    timeStamp noon(12, 0, 0);

    timeStamp *teaTime = new timeStamp(51, 35, 9);

    cout << "noon = " << noon.toString() << endl;

    cout << "teaTime = " << teaTime->toString() << endl;

    cout << "Time sum = "

         << (noon.addTimes(teaTime))->toString() << endl;

    cout << "Another sum = "

        << (teaTime->subTimes(&noon)).toString() << endl;

    return 0;

}

timeStamp::timeStamp(void)

{

    hour = 0;

    minute = 0;

    second = 0;

}

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

{

    hour = h;

    minute = m;

    second = s;

}

void timeStamp::setTime(int h, int m, int s)

{

    hour = s;

    minute = m;

    second = s;

}

timeStamp *timeStamp::addTimes(timeStamp *ts)

{

    int ourTime = (hour * 3600) + (minute * 60) + second;

    int theirTime = (ts->hour * 3600) + (ts->minute * 60) + ts->second;

    int timeSum = (ourTime + theirTime);

    timeStamp *newTime = new timeStamp();

    newTime->hour = timeSum / 3600;

    newTime->minute = (timeSum % 3600) / 60;

    newTime->second = ((timeSum % 3600) % 60);

    return newTime;

}

timeStamp *timeStamp::subTimes(timeStamp *ts)

{

    int ourTime = (hour * 3600) + (minute * 60) + second;

    int theirTime = (ts->hour * 3600) + (ts->minute * 60) + ts->second;

    int timeSum = (ourTime - theirTime);

    timeStamp *newTime = new timeStamp();

    newTime->hour = timeSum / 3600;

    newTime->minute = (timeSum % 3600) / 60;

    newTime->second = ((timeSum % 3600) % 60);

    return newTime;

}

string timeStamp::toString(void)

{

    ostringstream convert;

    convert << "hour = " << hour << ", minute = " << minute

            << ", second = " << second;

    return convert.str();

}

There are two changes needed to this program to make it compile & build correctly. Please be careful and don’t go changing things all over the place.

  1. Please show the exact output from the 1stcout statement in main.

  1. Please show the exact output from the 2ndcout statement in main

  1. Please show the exact output from the 3rdcout statement in main

  1. Please show the exact output from the 4thcout statement in main

Solutions

Expert Solution

Please show the exact output from the 1stcout statement in main

noon = hour = 12, minute = 0, second = 0

Explanation:Since we created the noon object " timeStamp noon(12, 0, 0);" the above output will be printed

Please show the exact output from the 2ndcout statement in main

teaTime = hour = 3, minute = 35, second = 9

Explanation:Since 0..24 is allowed for Hours we divide it by 24

Please show the exact output from the 3rdcout statement in main

Time sum = hour = 15, minute = 35, second = 9

Explanation:We now added noon and teaTime 15 hours(12+3) ,35 minute(0+35), 9 second(0+9)

Please show the exact output from the 4thcout statement in maiN

AAnother sum = hour = 8, minute = 24, second = 51

2.OUTPUT :

3.CODE :

#include <iostream>

#include <string>

#include <sstream>

using namespace std;

class timeStamp // uses 24-hour times (0..24)

{

public:

    timeStamp(void);

    timeStamp(int, int, int);

    void setTime(int, int, int);

    timeStamp *addTimes(timeStamp *);

    timeStamp *subTimes(timeStamp *);

    string toString(void);

    int hour;

    int minute;

    int second;

};

int main()

{

    timeStamp noon(12, 0, 0);

    timeStamp *teaTime = new timeStamp(51, 35, 9);

    cout << "noon = " << noon.toString() << endl;

    cout << "teaTime = " << teaTime->toString() << endl;

    cout << "Time sum = "

         << (noon.addTimes(teaTime))->toString() << endl;

    cout << "Another sum = "

        << (teaTime->subTimes(&noon))->toString() << endl;

    return 0;

}

timeStamp::timeStamp(void)

{

    hour = 0;

    minute = 0;

    second = 0;

}

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

{

    hour = h%24;

    minute = m;

    second = s;

}

void timeStamp::setTime(int h, int m, int s)

{

    hour = h;

    minute = m;

    second = s;

}

timeStamp *timeStamp::addTimes(timeStamp *ts)

{

    int ourTime = (hour * 3600) + (minute * 60) + second;

    int theirTime = (ts->hour * 3600) + (ts->minute * 60) + ts->second;

    int timeSum = (ourTime + theirTime);

    timeStamp *newTime = new timeStamp();

    newTime->hour = (timeSum / 3600)%24;

    newTime->minute = (timeSum % 3600) / 60;

    newTime->second = ((timeSum % 3600) % 60);

    return newTime;

}

timeStamp *timeStamp::subTimes(timeStamp *ts)

{

    int ourTime = (hour * 3600) + (minute * 60) + second;

    int theirTime = (ts->hour * 3600) + (ts->minute * 60) + ts->second;

    int timeSum = (ourTime - theirTime);
        if(timeSum<0)
                timeSum=-(timeSum);

    timeStamp *newTime = new timeStamp();

    newTime->hour = (timeSum / 3600)%24;

    newTime->minute = (timeSum % 3600) / 60;

    newTime->second = ((timeSum % 3600) % 60);

    return newTime;

}

string timeStamp::toString(void)

{

    ostringstream convert;

    convert << "hour = " << hour << ", minute = " << minute

            << ", second = " << second;

    return convert.str();

}


Related Solutions

Please read the scenarios and answer the questions based on the nursing code of ethics. A)....
Please read the scenarios and answer the questions based on the nursing code of ethics. A). You are a home health nurse caring for patient who was discharged home after a fall. The patient sustained a hip fracture and is in significant pain. You review the chart of the nurse who has seen him for the past two weeks, and they have charted the patient has taken prescribed oxycodone several times per day. During ambulation the patient states they need...
Understand the code and explain the code and answer the questions. Type your answers as comments....
Understand the code and explain the code and answer the questions. Type your answers as comments. #include #include using namespace std; // what is Color_Size and why it is at the end? enum Color {        Red, Yellow, Green, Color_Size }; // what is Node *next and why it is there? struct Node {        Color color;        Node *next; }; // explain the code below void addNode(Node* &first, Node* &last, const Color &c) {        if (first == NULL)...
A. Please read the following situation statement and answer the questions that follow: While traveling on...
A. Please read the following situation statement and answer the questions that follow: While traveling on business with a co-worker, you spend quite a few evenings having dinner and cocktails with your co-worker’s extended family that lives in town. After each of these meals your co-worker charges the entire meal to his corporate credit card, which he then submits as a business expense as part of his travel expense report. As these meals were not overly extravagant, the total value...
INSTRUCTIONS Please read the following case study and then answer the three questions at the end....
INSTRUCTIONS Please read the following case study and then answer the three questions at the end. Copy/paste the questions followed by your answers into the Discussion Board. Remember to reply to one other person’s initial post with a minimum of four sentences. Module 4 Chapter 4 Ethics Discussion The discussion board assignment is Case 4 - 34 found at the end of chapter problems in your eTextbook. Your initial post should answer the two questions (a-b) posed at the end...
Please read the following case study and answer the questions to the best of your ability....
Please read the following case study and answer the questions to the best of your ability. Case 14.1: Intake for Hira Hira called into the agency because she is not "feeling right." She sounds somewhat tearful as she describes an inability to sleep and a loss of weight over a 4-week period. She reports that she experienced a miscarriage four weeks ago and is not sure if she is dealing with a postpartum issue or grief over losing the baby....
The following are case questions, please read the facts and answer: Question:(1) is there a contract...
The following are case questions, please read the facts and answer: Question:(1) is there a contract under the CISG? (2) And why?
PLEASE explain why each answer of the following questions is correct, I need to understand it...
PLEASE explain why each answer of the following questions is correct, I need to understand it . 1)Economy is at its long run equilibrium. Assuming all else equal, stock market collapses and consumer sentiment level deteriorates. Which of the following is incorrect? A. In short run, output level decreases and price level decreases. B. In long run, output level is back to its long run output level. C. In short run, short run aggregate supply decrease. D. In long run,...
Please read the following case study and answer the questions posted. Please ensure you are reflective...
Please read the following case study and answer the questions posted. Please ensure you are reflective in your answers: answer thoughtfully and completely as senior nursing students. Maria Perez is a patient arriving from the Emergency Department (ED) with acute heart failure and confusion. Betty, the licensed practical nurse/licensed vocational nurse (LPN/LVN) who receives the call from the ED, recognizes the patient’s name and volunteers to take Maria as a patient. While getting Maria settled, Betty recognizes that this patient...
Please read the case and answer the questions at the end. Please respond to two of...
Please read the case and answer the questions at the end. Please respond to two of your peers. Do you agree or disagree? Collegiate Promotions distributes products that are marketed to students and alumni of major universities. High-selling products include coffee mugs and T-shirts that bear collegiate logos. In order to distribute its products, Collegiate Promotions has adopted an independent sales representative model. The sales representatives work for themselves and are not actual employees of Collegiate. They have independent contractor...
Please answer all the questions. Thank you Use the following data to answer the questions below:...
Please answer all the questions. Thank you Use the following data to answer the questions below: Column 1 Column 2 Column 3 Y in $ C in $ 0 500 500 850 1,000 1,200 1,500 1,550 2,000 1,900 2,500 2,250 3,000 2,600 What is mpc and mps? Compute mpc and mps. Assume investment equals $ 100, government spending equals $ 75, exports equal $ 50 and imports equal $ 35. Compute the aggregate expenditure in column 3. Draw a graph...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT