第十七周实验报告三(指针访问字符数组)
2012-02-23 22:30
429 查看
实验目的:揭开关于你生世的秘密
实验内容:简单的处理日期
* 程序头部注释开始 * 程序的版权和版本声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名称: * 作 者: 冯珍珍 * 完成日期: 2011 年 12 月 18 日 * 版本号: V1.2 * 对任务及求解方法的描述部分 * 输入描述:用动态链表处理日期问题 * 问题描述及输出:下面的程序可以在一个 main 函数中完成,也可以用函数求解,main 函数调用即可。 *定义一个表示时间(包括年、月、日、时、分、秒)的结构体,然后完成下面的功能: *(1)输入一个时间(注意各部分数据的取值范围)将输入的时间保存在一个结构体变量中; *(2)输出该日在本年中是第几天(注意闰年问题); *(3)输出这是这一天中的第几秒; *(4)输出这是这一年中的第几秒;(不要认为这个数荒唐,在计算中中需要取随机数时需要 *一个不会重复的“种子数”,这个秒数是常用的。) *(5)求你输入的时间d 天后是哪年哪月哪日,将结果保存在一个结构体变量中输出;(你的 *万天日期靠这个功能了) *(6)求你输入的时间s 秒后是何日何时,将结果保存在一个结构体变量中输出; * 程序头部的注释结束(此处也删除了斜杠) #include <iostream> using namespace std; struct time { int year; int month; int day; int hour; int minite; int second; }; struct tim { int year; int month; int day; }; struct ti { int day; int hour; }; time stu; tim stu1; ti stu2; void this_year_day (time stu); void this_day_second(time stu); void this_year_second(time stu); void this_year_minite(tim stu1,int u); void this_year_minitee(ti stu2,int p); int sum; int main() { int a,b,c,d,e,f,u,p; cout<<"请输入一个时间(包括年,月,日,时,分,秒):"<<endl; cin>>a>>b>>c>>d>>e>>f; stu.year=a; stu.month=b; stu.day=c; stu.hour=d; stu.minite=e; stu.second=f; this_year_day(stu); this_day_second(stu); this_year_second(stu); cout<<"请输入一个时间"<<endl; cin>>u; this_year_minite(stu1,u); cout<<"请输入一个时间"<<endl; cin>>p; this_year_minitee(stu2,p); return 0; } void this_year_day (time stu) { int i,j,m,k,h; h=stu.year@0; i=stu.year%4,j=stu.year0; if (i==0 && j!=0 || h==0) { cout<<stu.year<<"是闰年"<<endl; for (m=1;m<=stu.month;m++) { if(stu.month==2) { sum=sum+28; continue; } k=m%2; if (k!=0 && stu.month<=7) //stu[1].month!=8 && stu[1].month!=10 && stu[1].month!=12 { sum=sum+31; continue; } if(stu.month!=8 && stu.month!=10 && stu.month!=12) { sum=sum+31; continue; } sum=sum+30; } sum=sum+stu.day; cout<<stu.day<<"在"<<stu.year<<"中是第"<<sum<<"天"<<endl; } else { cout<<stu.year<<"是平年"<<endl; for (m=1;m<=stu.month;m++) { if(stu.month==2) { sum=sum+29; continue; } k=m%2; if (k!=0 && stu.month<=7) //stu[1].month!=8 && stu[1].month!=10 && stu[1].month!=12 { sum=sum+31; continue; } if(stu.month!=8 && stu.month!=10 && stu.month!=12) { sum=sum+31; continue; } sum=sum+30; } sum=sum+stu.day; cout<<stu.day<<"在"<<stu.year<<"中是第"<<sum<<"天"<<endl; } return; } void this_day_second(time stu) { int i; i=stu.hour*60*60+stu.minite+stu.second; cout<<"这是这一年中的第"<<i<<"秒."<<endl; return; } void this_year_second(time stu) { int i; i=sum*24*60*60+stu.hour*60*60+stu.minite*60+stu.second; cout<<"这是这一年中的第"<<i<<"秒."<<endl; return; } void this_year_minite(tim stu1,int u) { int m,t,h,n; if(stu.month==1 || stu.month==3 || stu.month==5 || stu.month==7 || stu.month==8 || stu.month==10 || stu.month==12) { m=stu.day+u; if(m>30) { n=m/30; t=n+stu.month; if(t>=12) { h=t/12; stu1.year=stu.year+h; stu1.month=t-12*h; stu1.day=m-n*30; } else { stu1.year=stu.year; stu1.month=t; stu1.day=m-n*30; } } else { stu1.year=stu.year; stu1.month=stu.month; stu1.day=stu.day+u; } } else { m=stu.day+u; if(m>31) { n=m/30; t=n+stu.month; if(t>=12) { h=t/12; stu1.year=stu.year+h; stu1.month=t-12*h; stu1.day=m-n*30; } else { stu1.year=stu.year; stu1.month=t; stu1.day=m-n*30; } } else { stu1.year=stu.year; stu1.month=stu.month; stu1.day=stu.day+u; } } cout<<u<<"天后是"<<stu1.year<<"年"<<stu1.month<<"月"<<stu1.day<<"日"<<endl; return; } void this_year_minitee(ti stu2,int p) { int m,t,n; m=p/60; m=m+stu.minite; if(m>60) { n=m/60; n=n+stu.hour; if(n>24) { t=n/24; stu2.day=stu.day+t; stu2.hour=n-t*24; } else { stu2.day=stu.day; stu2.hour=stu.hour+n; } } else { stu2.day=stu.day; stu2.hour=stu.hour; } cout<<p<<"秒后是"<<stu2.day<<"日"<<stu2.hour<<"时"<<endl; return; }
相关文章推荐
- 第十八周实验报告一(指针访问字符数组)
- C++ 第十八周报告1--《指针访问字符数组》
- 实验目的:学会指针访问字符数组
- 第十七周实验报告
- 第十七周实验报告(三)
- 多域间的访问-实验报告
- 第十七周实验报告1
- 5月8日实验报告(一)理解基类成员的访问限定符和派生类的继承方式
- 16周实验报告3:用指针完成14周任务2
- 第十七周实验报告
- 第十七周实验报告--学生成绩处理
- 第十七周实验报告2
- 第十七周实验报告1
- 第十七周实验报告3 不完整版
- 第六周实验报告(任务一)【this指针】
- 第十七周实验报告(任务一)
- 第十七周实验报告1
- 《C++第十七周实验报告1-1》---学生成绩处理:保存为二进制文件
- 第十六周实验报告(四)---指针做 十四周任务2
- 第十七周实验报告(任务二)