KiKi学习了面向对象技术,学会了通过封装属性(变量)和行为(函数)定义类,现在他要设计一个电子日历类TDate。
它有3个私有数据成员:Month,Day,Year和若干个公有成员函数,要求:
(1)带有默认形参值的构造函数,默认值为0, 0, 0;(2)输出日期函数,用“日/月/年”格式输出日期;
(3)设置日期函数,从键盘输入年、月、日。
一行,三个整数,用空格分隔,分别表示年、月、日。
一行,用“日/月/年”格式输出日期。
2019 12 30
30/12/2019
#include <bits/stdc++.h> using namespace std; class TDate { private: int Month, Day, Year; public: TDate(int m, int d, int y) :Month(m), Day(d), Year(y) { } void outDate() { cout << Day << '/' << Month << '/' << Year << endl; } void inDate() { cin >> Year >> Month >> Day; } }; int main() { TDate t(0,0,0); t.inDate(); t.outDate(); return 0; }
while(line = readline()){ var arr =line.split(" ").map(function(item){ return parseInt(item) }); console.log(arr[2]+"/"+arr[1]+"/"+arr[0]); }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int year=sc.nextInt(); int month=sc.nextInt(); int day=sc.nextInt(); TDate td=new TDate(day, month,year); td.print(); } static class TDate { private int Month = 0; private int Day=0; private int Year=0; public TDate(int day, int month, int year) { this.Month = month; this.Day = day; this.Year = year; } public void print() { System.out.println(Day + "/" + Month + "/" + Year); } } }
#include <iostream> using namespace std; class TDate { private: int Month; int Day; int Year; public: TDate(int m = 0, int d = 0, int y = 0); void set_date(void); void print_date(void) const; }; TDate::TDate(int m, int d, int y) { this->Month = m; this->Day = d; this->Year = y; } void TDate::set_date(void) { cin >> this->Year >> this->Month >> this->Day; return; } void TDate::print_date(void) const { cout << this->Day << "/"; cout << this->Month << "/"; cout << this->Year << endl; return; } int main(void) { TDate mytime; mytime.set_date(); mytime.print_date(); return 0; } //C++类的初步构造即可解决;
#include <stdio.h> //此写法仅供娱乐 int main() { int a,b,c; scanf("%d %d %d",&a,&b,&c); printf("%d/%d/%d",c,b,a); return 0; }
#include <stdio.h> //定义结构体 typedef struct TDate { int Month,Day,Year; }Tdate; int main() { Tdate d; scanf("%d %d %d",&d.Year,&d.Month,&d.Day); printf("%d/%d/%d",d.Day,d.Month,d.Year); return 0; }
#include <stdio.h> struct TDate { int Month; int Day; int Year; }s1={0,0,0}; int main() { int a, b, c; scanf("%d %d %d", &s1.Month, &s1.Day, &s1.Year); printf("%d/%d/%d", s1.Year, s1.Day, s1.Month); }
#include<stdlib.h> #include<stdio.h> typedef struct TDate { /* data */ int Mouth; int Day; int Year; }TD; TD* int_TD() { TD *new_TD=(TD*)malloc(sizeof(TD)); if(new_TD==NULL) { return NULL; } new_TD->Mouth=0; new_TD->Day=0; new_TD->Year=0; return new_TD; } void set_TD(TD *TD,int year,int mouth,int day) { TD->Day=day; TD->Mouth=mouth; TD->Year=year; } void printf_TD(TD *TD) { printf("%d/%d/%d",TD->Day,TD->Mouth,TD->Year); } int main(void) { TD *TD=int_TD();; //printf_TD(TD); int day,mouth,year; scanf("%d %d %d",&year,&mouth,&day); set_TD(TD,year,mouth,day); printf_TD(TD); }
#include <iostream> using namespace std; class TDate{ int Month; int Day; int Year; public: TDate(int Month = 0, int Day = 0, int Year = 0){ this->Month = Month; this->Day = Day; this->Year = Year; }; void input() { cout<<Day<<'/'<<Month<<'/'<<Year; } void setDate(int day,int month,int year) { Day = day; Month = month; Year = year; } }; int main() { int y,m,d; cin>>y>>m>>d; TDate A(m,d,y); A.input(); return 0; }