-
Description
用C语言自定义结构体类型time来表示时间,用来存储小时、分钟、秒三个量。编写函数get_time()、put_time()、time_swap()实现对时间的输入、输出和交换功能。请根据“append.c”文件内容定义类型并设计函数,使程序编译正确。用C++语言定义Time类型,并实现函数time_swap(),请根据“append.cc”文件内容定义类型并设计函数,使程序编译正确。 函数的调用格式见“Append Code”。
#include <stdio.h>
#include <stdlib.h>
struct time
{
int shi;
int fen;
int miao;
};
void get_time(struct time *tm)
{
scanf("%d:%d:%d",&((*tm).shi),&((*tm).fen),&((*tm).miao));
}
void put_time(struct time tm)
{
printf("%d:%d:%d\n",tm.shi,tm.fen,tm.miao);
}
void time_swap(struct time *tm,struct time *tn)
{
struct time t;
t=*tm;
*tm=*tn;
*tn=t;
}
int main()
{
struct time tm, tn;
get_time(&tm);
get_time(&tn);
time_swap(&tm, &tn);
put_time(tm);
put_time(tn);
return 0;
}