Answer to Question #117921 in C++ for Raghu kiran .R

Question #117921
define a class that has hours and minutes as private data members. define member function to take in the values and display the time and to convert hours minutes to minutes
1
Expert's answer
2020-05-25T18:51:46-0400
#include <iostream>


using namespace std;


class Time {
private:
    int hours;
    int minutes;

public:
    void set_time(int, int);
    void print_time();
    int convert_to_min(int, int);


};

void Time::set_time(int hrs, int mins) {
    hours = hrs;
    minutes = mins;
}


void Time::print_time() {
    cout << hours << ':' << minutes;
}


int Time::convert_to_min(int hrs, int mins) {

    return hrs * 60 + mins;
}

int main() {
    Time time;
    int hrs, mins;
    cout << "Enter the time: ";
    cin >> hrs >> mins;
    time.set_time(hrs, mins);
    cout << "Time is: ";
    time.print_time();
    cout << "\nTime in minutes is: " << time.convert_to_min(hrs, mins);


    return 0;
}


Output:






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS