turn this header file from structure to class. Please add comments to show where
ID: 3828928 • Letter: T
Question
turn this header file from structure to class. Please add comments to show where you made the changes #ifndef TIME_H #define TIME_H #include <iostream> struct Time { int hours, minutes, seconds; }; void init(Time &t, int hours, int minutes, int seconds); void normalize(Time &t); Time add(const Time &t1, const Time &t2); Time &addInPlace(Time &t1, const Time &t2); Time subtract(const Time &t1, const Time &t2); Time &subtractInPlace(Time &t1, const Time &t2); bool equals(const Time &t1, const Time &t2); std::ostream &operator <<(std::ostream &os, const Time &t); std::istream &operator >>(std::istream &is, Time &t); #endif
Explanation / Answer
//turn this header file from structure to class.
//here im just giving the code for structure to class transformation..
//and sample function execution.
Time.h //Time header declaration
#ifndef TIME_H
#define TIME_H
class Time //struct to class
{
int hours, minutes, seconds;
public:
Time();
};
void show(); //sample function declaration
void init(Time &t, int hours, int minutes, int seconds);
void normalize(Time &t);
Time add(const Time &t1, const Time &t2);
Time &addInPlace(Time &t1, const Time &t2);
Time subtract(const Time &t1, const Time &t2);
Time &subtractInPlace(Time &t1, const Time &t2);
bool equals(const Time &t1, const Time &t2);
std::ostream &operator <<(std::ostream &os, const Time &t);
std::istream &operator >>(std::istream &is, Time &t);
#endif // TIME_H
Time.cpp
#include "Time.h" //include the header file.
#include <iostream>
using namespace std;
void show() //function defintion
{
std::cout<<"this is my time show"<<endl;;
}
main.cpp
#include "Time.h" //header decalartion
#include <iostream>
using namespace std;
int main()
{
show(); //call the function
cout<<endl;
cout<<"hello im main";
return 1;
}
output:
this is my time show
hello im main
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.