0 like 0 dislike
1.8k views

The program below can compare time which is generated by class CTime but it seems not working properly. Please help to fix it. Remember that YOU CAN ONLY ADD YOUR CODE INSIDE THE SPECIFIC AREA

#include <iostream>
#include <cstdlib>
using namespace std;
class CTime
{
   private:
      int hour,min;
      double sec;

   public:

//Your code from here

 

//to here
};

int main(void)
{
   CTime t1(4,13,51.3);
   CTime t2(5,44,30.3);
   
   if(t1>t2)
      cout << "t1 is larger than t2" << endl;
   else
      cout << "t2 is larger than t1" << endl;

   if(t1<t2)
      cout << "t1 is smaller than t2" << endl;
   else
      cout << "t2 is smaller than t1" << endl;
   
   system("pause");
   return 0;
}

 

[Exercise] Coding (C) - asked in C++
ID: 24827 - Available when: Unlimited - Due to: Unlimited
| 1.8k views
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help

26 Answers

0 like 0 dislike
Hidden content!
#include <iostream>

#include <cstdlib>

using namespace std;

class CTime

{
* ** ** * * *** ** ****
* ** * * * * * **** ***** ** ** * hour,min;
** * *** ** * * * ** * * ******** * sec;


* ** * * *** ***
* * ** ***** * ** * ** a, int b,double c){
** ** * * ** *** * *** *** * * **** *** * * * ** *
** * * * ** *** **** * * * ** * * *** *
** * * * *** *** * * *** * **** ** * * * * *** ****
* *** * * *
* ** ** ** * * ** **** operator>(CTime& t2){
** ** * ** *** *** * * **** * * *** ******** * s1,s2;
*** * * * *** * * ** **** **** ** ** ** ** * ** ** *** * * ** **** * * * ****** *
** ** * **** * ******* *** * ** **** *** * *** * * ** * ** * *
* ** *** * ** *** * * * * ** * * *** * * * * * *
*** * **** * ** ****** **** *** ** *** * *** * ** ** *** ******** * 1;
** ** *** ** ***** * ***** *
* * ** * * * ***** * * ** * * t2){
* *** *** * * *** ** * **** ** * ** ** * ** * ** ** s1,s2;
* ** ** ***** ** * **** * ** ***** * * **** * * * *** ** * ** *
** ** * * ** * * * * * * * * ** **** * * * ***** * * **** ** * *
*** ****** ** *** **** * ** **** ** * *** ** ****
* *** * * ** * *** ****** ** ** * * ** * * ***** * ** *** ** ** * 1;
* ** * * * ** *** **





};



int main(void)

{
** * * * * * * * ** t1(4,13,51.3);
***** * * *** * t2(5,44,30.3);
* ** *
****** * * ** *
* * *** * ** **** ** * *** *** * ** << "t1 is larger than t2" << endl;
** * ** * * * * * *
** * ** ** * * * *** **** * * ** * * * ** * << "t2 is larger than t1" << endl;


*** ** * ** * * **
* * * * ****** * ** * * * * ** << "t1 is smaller than t2" << endl;
***** * * **
** **** ** * * * * ** << "t2 is smaller than t1" << endl;
**** ** ***
* *** **** * ** ** * ** * * * **
** * * * * ** * 0;

}
answered by (-384 points)
0 like 0 dislike
Hidden content!
#include <iostream>

#include <cstdlib>

using namespace std;

class CTime

{
* ** ** * *** *** * * **
**** ** ** * * * * **** * * * ** **** * hour,min;
* *** * * ****** * * * *** ***** sec;


* ** **** * * * *



//Your code from here
*** * * *** ********** ** ** *** **** * *** chour,int cmin,double csec){
* * ***** ** * * * * ** * * ** * *** ** *
* * *** ***** * *** ** * * ** ****** ** ** * * *
* * ** * ** **** **** * * * **** * ** ** *
* **** * ** **** ****** * **** *** *
* * * * *** ** ***** ** ** * * ** * * * * operator>(const CTime& b)
* * * *** * * *** ** * ** * ** * ** * *
* ***** **** *** * * * * ** * * ** * ** * ** * ** * * * * **** ** ** * * ** return true;
* * ** ** ********** * ***** ***** * * ** **** *** *** ** ****** *** * * * ***** * return false;
** * ***** * * * * * ****** * * * * * ** * * * *** * * ** * *** * **** return true;
* *** * * * ** * *** ** ** * *** * ****** * *** **** ** * * * ** return false;
* ** * ** * ** * * * *** ** * **** * **** *** **** ** *** *** ** * *** * * * * * **** return true;
* **** ** * * *** * * **** *** ***** * *** * * ** *** * ******* *** * * ** return false;
* ** * * ***** *** * ** ****** * *** *
**** * ** * * * * * ** ** ** **** * * * ** operator<(const CTime& b)
* * ** ** ** * * * ** * *** ** ** * *
***** * ** **** ******* * *** * * * * ****** ****** * * ***** * ***** **** return false;
** ** * * ******** ** *** * ** **** * ** ** ** ** ** *** ** ** ** ** * * ** * * return true;
* ********** ** ** *** ** ** * * * * * ** ****** * * ** * ** * * * * * ** * ** return false;
*** * **** * ****** * ***** ** * ** * * * * ** *** * ** * ** ** ** ** ** * * ******** * *** return true;
* ** * * ** *** *** ** * * ** * * ** **** * * * * * * * * * *** * ** * * * * * return false;
* *** * * * **** *** *** *** * *** * ** * ** * * * ** * * ** return true;
***** ** * ** ** * ***** * * *







//to here

};



int main(void)

{
* **** ** ** ***** ** t1(4,13,51.3);
*** * * * ** * t2(5,44,30.3);
* *** * * * *** *
******* * ***** ***** *
** * ** * *** * * ****** * * << "t1 is larger than t2" << endl;
* ** ** * * ** *
* ****** * *** ** ** * ** << "t2 is larger than t1" << endl;


*** ** * ***** * ** *
** * * * * *** *** * * ** ** * * << "t1 is smaller than t2" << endl;
* ** *** * ******* **
**** * * ***** * ** ** ****** * * *** ** << "t2 is smaller than t1" << endl;
* ** ***** *** ** * **
* ** * ** ** ** ** ** * * * *** **
* ** * **** * ** * * * 0;

}
answered by (-412 points)
0 like 0 dislike
Hidden content!
#include ** * ** ** **

#include *** * * * ***

using namespace std;

class CTime

{
* * * ** ** *****
** * *** *** ** * ** ** * * * * ** * hour,min;
* ** * * * **** ** * ** ***** sec;


** ** ****** *** ** * ***



//Your code from here
*** * *********** ** h, int m, double s){
** ** ** ** *** * * **** ****** * = h;
* *** ** ** ** *** * ** ** * **** * = m;
* * ** **** * ****** * *** ** *** = s;
* * * ** ** * * *


* * *** ** ** bool * * * * (const CTime * * const CTime * * * *
** * *** **** ** * ** ** **** ** ** * ** ** * * * + num1.min + * * > * * ** + num2.min + **
* *** ***** * * **


** * * * ** * bool *** * * (const CTime **** const CTime **** *
* *** ** *** * ** * * *** ******* * *** ** ** + num1.min + num1.sec) < *** + num2.min + * **
* * *** *** * * *



//to here

};



int * *

{
** * ** ** ****** ***** ****
* ***** ** ** ** *** * * *


* ** ***** ***** * * *
*** ** ** * * *** ** **** *** * ** ***** ** is larger than * * ** * *** ** endl;
*** * ** ***** * *
* * * * * * ** * ** * **** * * ** * * * * * * * is larger than *** *** * * *** endl;


*** * ** ** ** * *** ** **
* * * *** ** * * * ** * ** ** ** * ** ********* * * * *** is smaller than *** * * * * ** endl;
* ** * * * ** ***
***** * * ***** * ** * ** ** ** ***** *** is smaller than ** * *** endl;


* * * * * ** **** * *** **** * * * **
** * *** *** * ** 0;

}
answered by (5.2k points)
0 like 0 dislike
Hidden content!
#include **** * * *** * *

#include *** * ****** ** *

using namespace std;

class CTime

{
** *** ** * *** * *
**** * ** **** * * *** * ** hour,min;
** **** ** ** * ** **** ***** *** *** ** sec;


* ** ** * **** *** * *
*** * **** *** ****** * ** **** ** *** * * * *** * h,int m,double s){
** * ** * * * ***** * * * *** * **** * ** **** * = h;
* *** * ****** * *** ** ***** * * *** *** = m;
**** * * ** ******** * * ***** * ** **** ** * = s;
* **** ** ** *** ** ** ** **



//Your code from here

bool operator > (const **** b){
* * ** *** *** *** > b.hour)
*** *** * * ****** * ** * ** ** * * * ******** true;
** * * * * *** * * * ** if(hour == b.hour * **** min > b.min)
** ** ** *** * * *** ** * ****** *** * ** **** true;
****** * * **** * * if (hour == b.hour * * * * * min == b.min * * * sec > b.sec)
** ** * * * * ** **** ** * ** ** * * * * * * * * true;
* * * * ** * *** * *
*** * * * ** *** * ** * * * * ***** * false;

}



bool operator < (const * * * b){
* *** ** * *** * * < b.hour)
* * * * **** * ****** * ****** * *** true;
* * * ** ** * * if(hour == b.hour ** ** *** ** min < b.min)
** **** ** ** *** **** * * * ** *** * ** true;
*** * * * * *** if (hour == b.hour * **** * * min == b.min * ** **** sec < b.sec)
*** *** ** * ****** * **** ** ** ** *** * **** true;
** * **** ** * * ** *
* * **** ** ** * **** *** ******** ********* false;

}





//to here

};



int main(void)

{
*** * * * ** ** ** *
* ** * * * * * * *


* ** * * **** *** * ***** *
* *** * * * * * * ********* ** ** * ** ***** * **** is larger than ** ** ** **** endl;
* ** *** *** * **
** *** * * ** ** * ** * * * ** * * * * * *** is larger than ** ** * * *** endl;


* **** ** * ** *
* * *** **** * ** **** * **** * *** ** * ** *** *** * * * *** * is smaller than *** * ******** endl;
**** * * * * * ** * *
* * ** ** *** ** * * ** *** ** **** *** ** ** *** is smaller than *** *** ** * * endl;


* *** * * * * ** *** ***** **
* ****** * ** * * *** 0;

}
answered by (-368 points)
0 like 0 dislike
Hidden content!
#include * * *** **

#include ** *

using namespace std;

class CTime

{
* ****** *** * * *
***** * *** * * * * *** * hour,min;
*** ** * ** ** ** *** * **** * ***** * sec;


* * ** * **
* *** * ** * ** ** *** * *
** * * * *** ** * ** ** ** ** *** * * a,int b,int c);
** * * *** * * ** ***** * ** compare(CTime &d);
** ** ** * * * ***** * * * * * operator >(CTime &d);
**** ****** ** ** * *** * ***** ** * * operator <(CTime &d);

//to here

};
** ** *

{
* *** ** ** * *
** * ***** *** *** *** * *
* * ** * ** * * * **

}
*** **** * a,int b,int c)

{
* ** * * *** * * ** ** * ** *
* *** * *** ***** *** **
***** * ** **** ** *

}

int * * * &d)

{
*** * * *** ** *** ** ** ** ****
* ****** *** ** * * * * ** * **** * ******* * * * *** -1;
** * * * **** ** * **** **
********* *** *** * * * *** *** ** * * *** 1;
*** *** * * * * ** ** ***
* *** ** ** ** * ** ***** * ** ** * * ***** *** -1;
* * *** ** * * * * ** * * **
* ***** * ***** *** **** ****** **** * * 1;
*** * ** ** ***** * * *** ****
** * **** ** ** ** **** * * * * ** ** *** -1;
* *** * ****** ***** * * ** ** *** * ***
* * ** * ** *** * * * **** * ** * * ** ** * 1;
* * *** * ** ** * ** 0;

}

bool ** ** >(CTime &d)

{
* **** * * ** * **** * **** *

}

bool * ** ** <(CTime &d)

{
*** ** *** * * *** ***** * * ** **

}





int main(void)

{
** * * * * * t1(4,13,51.3);
* ******* ** * t2(5,44,30.3);


* * ** ****** * * * ** * * *
* *** *** * * * **** ** *** * * * * ***** "t1 is larger than t2" **** endl;
******** **** ****
*** * **** * ** ** ** * ** ** *** * ** * "t2 is larger than t1" * * ** * * endl;


****** ** * ** * ***
** * **** * *** *** ** ** *** * * * * *** ** "t1 is smaller than t2" *** * endl;
** ** ********* * ** **
** * * *** * * **** **** * * * * * * "t2 is smaller than t1" * * endl;


* ** ** ** ** *** * * **
*** * *** ** 0;

}
answered by (0 points)
0 like 0 dislike
Hidden content!
#include ****** ** ** *

#include * * * * ***

using namespace std;

class CTime

{
* * * * * ** ** **
* * ** * **** * **** ** * *** **** ** *** hour,min;
* * * ** * **** ** * * * sec;


* * ** * ***** **
** * *** *** ** ** * * * ** *
** ** *** *** ***** ** * * * ** ** a,int b,int c);
*** ** * * ** * * * * * * * **** compare(CTime &d);
* ****** *** ** **** * ** ** *** operator >(CTime &d);
** ** * ** * ** ** **** * * operator <(CTime &d);

//to here

};
** ** *

{
* ** ** * * * *** ** ** ******
* * *** **** ** * ** *
** * **** ** * * ****

}
* * ** * * a,int b,int c)

{
*** ** ** * ** ******* * **
*** * * *** ** * *** * *
** ** **** *** ** * **

}

int * ** * * &d)

{
* * ** * ** ** * * * * *** ****
* ** *** * **** * * * ** ** * **** * * * ** -1;
* * * ** ** *** ** *** * ** ** ****
**** * *** ** *** * **** ** * ** ****** * ****** * * 1;
* * ** * * **** ** *
* * **** ** ** * * * ******* * ** **** *** * -1;
* * ***** ** ** ** ** * * * **
* * ** * **** * ** * ** * * * *** ** ** * * * ** 1;
* * *** * * * *** * ** *** ** ***
* * ** ** ** * ** ** ** * *** * * ** **** ** * * -1;
* * *** * * * * * *** *** *
** ** ** ** * *** *** *** * * * ** ** 1;
* ***** * *** * * * * 0;

}

bool *** ** * >(CTime &d)

{
** * *** * * * ***** * ** * * *

}

bool *** ** <(CTime &d)

{
** ** * *** * ** * * ** * *** *

}





int main(void)

{
* * ** * * * **** t1(4,13,51.3);
* * ******* * t2(5,44,30.3);


* * ** * * ** * * * *
* * ********* * * ****** *** * * * ** * * ** "t1 is larger than t2" *** *** ** endl;
* **** **** ****
** ** * * * ** *** ** ** ** * "t2 is larger than t1" *** ** endl;


** * ***** * * ** ***
*** ** ** * * * * **** *** * * * ** ** * * * ** "t1 is smaller than t2" * ** * *** endl;
** * * * ** * ** ***
* ** ***** * *** * *** * * ** ** "t2 is smaller than t1" ** ** ** endl;


*** * ***** * *** ** ** *** *
** * *** * *** 0;

}
answered by (0 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.100.89
©2016-2024

Related questions

0 like 0 dislike
15 answers
[Exercise] Coding (C) - asked Jun 1, 2017 in C++
ID: 24854 - Available when: Unlimited - Due to: Unlimited
| 1.2k views
0 like 0 dislike
18 answers
[Exercise] Coding (C) - asked May 25, 2017 in C++
ID: 24828 - Available when: Unlimited - Due to: Unlimited
| 1.5k views
0 like 0 dislike
17 answers
[Exercise] Coding (C) - asked Jun 1, 2017 in C++
ID: 24855 - Available when: Unlimited - Due to: Unlimited
| 1.2k views
0 like 0 dislike
30 answers
[Exercise] Coding (C) - asked May 18, 2017 in C++
ID: 24769 - Available when: Unlimited - Due to: Unlimited
| 1.8k views
12,783 questions
183,443 answers
172,219 comments
4,824 users