Seventh week the second item-friend class

Source: Internet
Author: User

/*copyright (c) 2016, College of Computer and Control engineering, Yantai University 02.*all rights reserved.03.* file name: main.cpp04.* Author: Tian Zhiwei 05.* finish Date: May 9, 2016 06.* version Number: v1.007.*08.* problem Description: Friend Time class 09. Input Description: 10.* Output Description: Month Day hour minute seconds */#include <iostream>using namespace Std;class Date;    Advance reference to the Date class declares class Time{public:time (Int,int,int);  void Add_a_second (Date &);  Add 1 seconds, 1 seconds after the next day, to the next month, the next year, void Display (Date &);    Display time, Format: Month/day/year: minutes: seconds Private:int hour;    int minute; int sec;};    Class Date{public:date (Int,int,int); Friend class time;    Time is the friend class of date Private:int month;    int day; int year;};    Time::time (int a,int b,int c) {hour=a;    Minute=b; Sec=c;}    Date::D ate (int x,int y,int z) {month=x;    Day=y; Year=z;}; void Time::add_a_second (DATE&AMP;D1) {sec=sec+1;}        void time::d isplay (DATE&AMP;D1) {if (sec>=60) {minute=sec/60+minute;    sec=sec%60;        } if (minute>=60) {hour=minute/60+hour;    minute=minute%60; } if (hour>=24) {D1.DAY=D1.DAY+HOUR/24;    hour=hour%24;        } if (d1.day>31) {d1.month=d1.day/30+d1.month;    d1.day=d1.day%30;        } if (d1.month>12) {d1.year=d1.month/12+d1.year;    d1.month=d1.month%12; } cout<<d1.month<< "/" <<d1.day<< "/" <<d1.year<< "" <

Program run:


Seventh week the second item-friend class

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.