Project 3-youyuan class

Source: Internet
Author: User

[Cpp]
/*
* Copyright (c) 2013, computer College, Yantai University
* All rights reserved.
* File name: test. cpp
* Author: Fan Lulu
* Completion date: January 1, April 15, 2013
* Version: v1.0
*
* Input Description: None
* Problem description:
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# Include <iostream>
Using namespace std;
Class Date; // advance reference Declaration for the Date class
Class Time
{
Public:
Time (int, int, int); // defines the constructor
Void add_a_second (Date &); // increase by 1 second. After 1 second, it may arrive at the next day, which is until the next month, January, and next year.
Void display (Date &); // display time. Format: Month/day/year hour: minute: Second
Private:
Int hour;
Int minute;
Int sec;
};
 
Class Date
{
Public:
Date (int, int, int );
Friend class Time; // Time is defined as a friend class of Date.
Private:
Int month;
Int day;
Int year;
};
 
Int main ()
{
Time t1 (23, 59, 32 );
Date d1 (2012 );
For (int I = 0; I <= 80; I ++)
{
T1.add _ a_second (d1 );
T1.display (d1 );
}
Return 0;
}
// The member functions in the two classes are defined below, and the member functions must not be added.
// Note that you can call the private data member of the Date class in the Time member function.
Time: Time (int h, int m, int s)
{
Hour = h;
Minute = m;
Sec = s;
}
Date: Date (int m, int d, int y)
{
Month = m;
Day = d;
Year = y;
}
// Defines the time class member function, where Date is a friend class, you can directly call the private member in Date
Void Time: add_a_second (Date & d)
{
If (++ sec> = 60) ++ minute, sec-= 60;
If (minute> = 60) ++ hour, minute-= 60;
If (hour> = 24) ++ d. day, hour-= 24;
If (d. day> 30) + + d. month, d. day-= 30; // Q.
If (d. month> 12) + + d. year, d. month-= 12; // Q.
}
Void Time: display (Date & d)
{
Cout <d. month <"/" <d. day <"/" <d. year <"";
Cout }

/*
* Copyright (c) 2013, computer College, Yantai University
* All rights reserved.
* File name: test. cpp
* Author: Fan Lulu
* Completion date: January 1, April 15, 2013
* Version: v1.0
*
* Input Description: None
* Problem description:
* Program output:
* Problem analysis:
* Algorithm Design: omitted
*/
# Include <iostream>
Using namespace std;
Class Date; // advance reference Declaration for the Date class
Class Time
{
Public:
Time (int, int, int); // defines the constructor
Void add_a_second (Date &); // increase by 1 second. After 1 second, it may arrive at the next day, which is until the next month, January, and next year.
Void display (Date &); // display time. Format: Month/day/year hour: minute: Second
Private:
Int hour;
Int minute;
Int sec;
};

Class Date
{
Public:
Date (int, int, int );
Friend class Time; // Time is defined as a friend class of Date.
Private:
Int month;
Int day;
Int year;
};

Int main ()
{
Time t1 (23, 59, 32 );
Date d1 (2012 );
For (int I = 0; I <= 80; I ++)
{
T1.add _ a_second (d1 );
T1.display (d1 );
}
Return 0;
}
// The member functions in the two classes are defined below, and the member functions must not be added.
// Note that you can call the private data member of the Date class in the Time member function.
Time: Time (int h, int m, int s)
{
Hour = h;
Minute = m;
Sec = s;
}
Date: Date (int m, int d, int y)
{
Month = m;
Day = d;
Year = y;
}
// Defines the time class member function, where Date is a friend class, you can directly call the private member in Date
Void Time: add_a_second (Date & d)
{
If (++ sec> = 60) ++ minute, sec-= 60;
If (minute> = 60) ++ hour, minute-= 60;
If (hour> = 24) ++ d. day, hour-= 24;
If (d. day> 30) + + d. month, d. day-= 30; // Q.
If (d. month> 12) + + d. year, d. month-= 12; // Q.
}
Void Time: display (Date & d)
{
Cout <d. month <"/" <d. day <"/" <d. year <"";
Cout }
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.