The 1.time class is saved in "htime.h" and requires:
⑴ data members are included (hour), minutes (minute), seconds (second), and are private members;
⑵ A member function that can provide a value to a data member (the default value is 0 for 0 minutes and 0 seconds);
⑶ can take time, minutes and seconds respectively;
⑷ can output hours, minutes, seconds (separated by ":" ) and display the morning (am) or PM (pm);
The ⑸ has a default constructor (the default value is 0 for 0 minutes and 0 seconds).
Description: Member functions are defined as public members.
2. Write a main () function that tests the time class (stored in exp_104.cpp). Requirements:
⑴ defines the object, object pointer, object reference;
⑵ Set the time with the input value;
⑶ Displays the time with the member function of the output time, minutes and seconds;
The ⑷ uses the time, minute, and second member functions to display the times in the format of " minutes " ;
⑸ calls member functions with references to objects, object pointers, and objects, respectively.
#ifndef time_htime_h#define time_htime_h#include<iostream>using namespace Std;class time{public: Time (int h = 0,int m = 0,int s = 0) { hour = h; minute = m; Second = s; } ~time () {} void set_time (int h,int m,int s) { hour = h; minute = m; Second = s; } int Get_hour () { return hour; } int Get_second () { return second; } int Get_minute () { return minute; } void Ptint () { if (hour <12 && hour > 0) { cout<< "PM"; } else cout<< "AM"; cout<
#include "htime.h" int main () {time T; Time *p; Time &s = T; P = &T; T.set_time (a); cout<< "Hour:" <<s.get_hour () <<endl; cout<< "minute:" <<s.get_minute () <<endl; cout<< "Second:" <<s.get_second () <<endl; P->ptint (); return 0;}
[C + +] object pointer, referenced action