《GIS程序设计》实验报告实验一
学 号: 姓 名:
一、实验目的和要求
1.实验目的:
掌握类定义的方法,理解类类型,实例的含义;并且体会面向对象程序设计中数据隐藏的概念。
2.主要内容:
.定义一个时间类Time,它能提供由时分秒组成的时间。能够修改时间和打印出时间。
实验内容
1、(1)实现代码:
#include class Time {public: int h; int m; int s; void inputT(); void changeT(); void output(); }; void Time::inputT() {begin: int a,b,c; cout<<\"input time(H:M:S)\"; cin>>a>>b>>c; if(c>60 || c<0) { cout<<\" Wrong time! please set again !\"< } else { if(b>60 || b<0) { cout<<\"Wrong time! please set again !\"< } else { if(a>24 || a<0) {cout<<\"Wrong time! please set again !\"< } else if(a==24) { if(b!=0 || c!= 0) { cout<<\"Wrong time! please set again !\"< } else { h=a; m=b; s=c; } } else { h=a; m=b; s=c; } } } } void Time::changeT() { char p; cout<<\"do you wanna change time?(Y/N):\"; cin>>p; if(p=='n'||p=='N') { cout<<\"thank you for your using!\"< else { begin1: int a,b,c; cout<<\"input time(H:M:S)\"; cin>>a>>b>>c; if(c>60 || c<0) { cout<<\"Wrong time! please set again!\"< } else { if(b>60 || b<0) { cout<<\"Wrong time! please set again!\"< } else { if(a>24 || a<0) { cout<<\"Wrong time! please set again!\"< } else if(a==24) { if(b!=0 || c!= 0) { cout<<\"Wrong time! please set again!\"< } else { h=a; m=b; s=c; } } else { h=a; m=b; s=c; } } } } } void Time::output() { cout<<\"output time(H:M:S)\"< void main(void) { Time time1; time1.inputT(); time1.output(); time1.changeT(); time1.output(); } (2)结果显示: 因篇幅问题不能全部显示,请点此查看更多更全内容