C++编程:写一个表示时间的结构体,有年月日时秒的成员,可以使用short类型 (在主程序输入输出)
题目解析:首先电脑提示输入年,然后我们用键盘输入年,依次到秒.最后将我们键盘输入的年月...显示出来就行拉```本人是个菜鸟,希望帮忙下```谢谢各位高手拉!!(不明白的...
题目解析:首先电脑提示输入年,然后我们用键盘输入年,依次到秒.最后将我们键盘输入的年月...显示出来就行拉```本人是个菜鸟,希望帮忙下```谢谢各位高手拉!!(不明白的话我可以再补充)急~~~~
展开
展开全部
#include<iostream>
using namespace std ;
typedef struct
{
int year ;
int month ;
int day;
int hour ;
int minute ;
int second ;
} Time ;
int main()
{
Time *time = new Time() ;
cout << "请输入年:" ;
cin >> time->year ;
cout << "请输入月:";
cin >> time->month ;
cout << "请输入日:";
cin >> time->day ;
cout << "请输入时:";
cin >> time->hour ;
cout << "请输入分钟:" ;
cin >> time->minute ;
cout << "请输入秒:" ;
cin >> time->second ;
//Display
cout << time->year << " 年 " << time->month << " 月 " << time->day << " 日 "
<< time->hour << " 时 " << time->minute << " 分 " << time->second << " 秒" << endl ;
return 0 ;
}
using namespace std ;
typedef struct
{
int year ;
int month ;
int day;
int hour ;
int minute ;
int second ;
} Time ;
int main()
{
Time *time = new Time() ;
cout << "请输入年:" ;
cin >> time->year ;
cout << "请输入月:";
cin >> time->month ;
cout << "请输入日:";
cin >> time->day ;
cout << "请输入时:";
cin >> time->hour ;
cout << "请输入分钟:" ;
cin >> time->minute ;
cout << "请输入秒:" ;
cin >> time->second ;
//Display
cout << time->year << " 年 " << time->month << " 月 " << time->day << " 日 "
<< time->hour << " 时 " << time->minute << " 分 " << time->second << " 秒" << endl ;
return 0 ;
}
展开全部
#include <stdio.h>
void main()
{
int year,month,day,hour,sec,miu;
printf("输入年:");scanf("%d",&year);
printf("输入月:");scanf("%d",&month);
printf("输入日:");scanf("%d",&day);
printf("输入时:");scanf("%d",&hour);
printf("输入分:");scanf("%d",&sec);
printf("输入秒:");scanf("%d",&miu);
printf("输入的日期为:%d年%d月%d日 %d:%d:%d",year,month,day,hour,sec,miu);
}
void main()
{
int year,month,day,hour,sec,miu;
printf("输入年:");scanf("%d",&year);
printf("输入月:");scanf("%d",&month);
printf("输入日:");scanf("%d",&day);
printf("输入时:");scanf("%d",&hour);
printf("输入分:");scanf("%d",&sec);
printf("输入秒:");scanf("%d",&miu);
printf("输入的日期为:%d年%d月%d日 %d:%d:%d",year,month,day,hour,sec,miu);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream.h>
typedef struct time
{
int year,month,day,hour,sec,miu;
}time;
void main()
{
time test;
cout<<"输入年:"<<endl;
cin>>test.year;
cout<<"输入月:"<<endl;
cin>>test.month;
cout<<"输入日:"<<endl;
cin>>test.day;
cout<<"输入时:"<<endl;
cin>>test.hour;
cout<<"输入分钟:"<<endl;
cin>>test.miu;
cout<<"输入秒:"<<endl;
cin>>test.sec;
cout<<"您输入的日期为:"<<test.year <<"年"<<test.month<<"月" <<test.day<<"日"<<test.hour <<"时"<<test.miu<<"分" <<test.sec <<"秒"<<endl;
}
typedef struct time
{
int year,month,day,hour,sec,miu;
}time;
void main()
{
time test;
cout<<"输入年:"<<endl;
cin>>test.year;
cout<<"输入月:"<<endl;
cin>>test.month;
cout<<"输入日:"<<endl;
cin>>test.day;
cout<<"输入时:"<<endl;
cin>>test.hour;
cout<<"输入分钟:"<<endl;
cin>>test.miu;
cout<<"输入秒:"<<endl;
cin>>test.sec;
cout<<"您输入的日期为:"<<test.year <<"年"<<test.month<<"月" <<test.day<<"日"<<test.hour <<"时"<<test.miu<<"分" <<test.sec <<"秒"<<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
using namespace std;
struct time{
int y;
int m;
int d;
int h;
int mi;
int sec;};
int input();
int main()
{
time newtime;
cout<<"输入年:\n";
newtime.y=input();
cout<<"输入月:\n";
newtime.m=input();
cout<<"输入日:\n";
newtime.d=input();
cout<<"输入时:\n";
newtime.h=input();
cout<<"输入分:\n";
newtime.mi=input();
cout<<"输入秒:\n";
newtime.sec=input();
cout<<"你输入的是:"<<newtime.y<<"年"
<<newtime.m<<"月"<<newtime.d<<"日"
<<newtime.h<<"时"<<newtime.mi<<"分"
<<newtime.sec<<"秒";
return 0;
}
int input()
{
int temp;
while(!(cin>>temp))
{
cin.clear();
while(cin.get()!='\n')
continue;
cout<<"请输入数字!\n";
}
return temp;
}
当输入非数值时会报警。
using namespace std;
struct time{
int y;
int m;
int d;
int h;
int mi;
int sec;};
int input();
int main()
{
time newtime;
cout<<"输入年:\n";
newtime.y=input();
cout<<"输入月:\n";
newtime.m=input();
cout<<"输入日:\n";
newtime.d=input();
cout<<"输入时:\n";
newtime.h=input();
cout<<"输入分:\n";
newtime.mi=input();
cout<<"输入秒:\n";
newtime.sec=input();
cout<<"你输入的是:"<<newtime.y<<"年"
<<newtime.m<<"月"<<newtime.d<<"日"
<<newtime.h<<"时"<<newtime.mi<<"分"
<<newtime.sec<<"秒";
return 0;
}
int input()
{
int temp;
while(!(cin>>temp))
{
cin.clear();
while(cin.get()!='\n')
continue;
cout<<"请输入数字!\n";
}
return temp;
}
当输入非数值时会报警。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
using namespace std;
struct Time{
short year,month,day,hour,minute,second;
void SetTime();
void Print();
};
void Time::SetTime()
{
cout<<"set year:"; cin>>year;
cout<<"set month:"; cin>>month;
cout<<"set day:"; cin>>day;
cout<<"set hour:"; cin>>hour;
cout<<"set minute:"; cin>>minute;
cout<<"set second:"; cin>>second;
}
void Time::Print()
{
cout<<"The time is:";
cout<<year<<"年"<<month<<"月"<<day<<"日 "<<hour<<"时"
<<minute<<"分"<<second<<"秒"<<endl;
}
int main()
{
Time TIME;
cout<<"Set Time\n";
TIME.SetTime();
TIME.Print();
return 0;
}
using namespace std;
struct Time{
short year,month,day,hour,minute,second;
void SetTime();
void Print();
};
void Time::SetTime()
{
cout<<"set year:"; cin>>year;
cout<<"set month:"; cin>>month;
cout<<"set day:"; cin>>day;
cout<<"set hour:"; cin>>hour;
cout<<"set minute:"; cin>>minute;
cout<<"set second:"; cin>>second;
}
void Time::Print()
{
cout<<"The time is:";
cout<<year<<"年"<<month<<"月"<<day<<"日 "<<hour<<"时"
<<minute<<"分"<<second<<"秒"<<endl;
}
int main()
{
Time TIME;
cout<<"Set Time\n";
TIME.SetTime();
TIME.Print();
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询