第三周报告一
来源:互联网 发布:mysql集群端口 编辑:程序博客网 时间:2024/06/11 09:05
#include <iostream>
using namespace std;
class Time
{
public:
void set_time( );
void show_time( );
private:
bool is_time(int, int, int); //is_time函数仅限于类内使用,声明为private型是必要的。
//另外,请欣赏函数名的取法。函数的作用在于判断,返回值为bool型,is_time()看起来就是个一般疑问句,读起来很上口
int hour;
int minute;
int sec;
};
int main( )
{
Time t1;
Time &t2=t1; //t2为引用变量(对象),需要理解其作用
t1.set_time();
t2.show_time();
return 0;
}
void Time::set_time( ) //这段函数给出了“界面友好”型输入的范例
{
char c1,c2;
cout<<"请输入时间(格式hh:mm:ss)";
while(1)
{
cin>>hour>>c1>>minute>>c2>>sec;
if(c1!=':'||c2!=':')
cout<<"格式不正确,请重新输入"<<endl;
else if (!is_time(hour,minute,sec))
cout<<"时间非法,请重新输入"<<endl;
else
break;
}
}
void Time::show_time( )
{
cout<<hour<<":"<<minute<<":"<<sec<<endl;
}
bool Time::is_time(int h,int m, int s)
{
if(h<0 ||h>24 || m<0 ||m>60 || s<0 ||s>60)
return false;
return true;
}
#include <iostream>
using namespace std;
class Time
{
public:
void set_time( );
void show_time( );
private:
bool is_time(int, int, int); //is_time函数仅限于类内使用,声明为private型是必要的。
//另外,请欣赏函数名的取法。函数的作用在于判断,返回值为bool型,is_time()看起来就是个一般疑问句,读起来很上口
int hour;
int minute;
int sec;
};
int main( )
{
Time t1;
Time &t2=t1; //t2为引用变量(对象),需要理解其作用
t1.set_time();
t2.show_time();
return 0;
}
void Time::set_time( ) //这段函数给出了“界面友好”型输入的范例
{
char c1,c2;
cout<<"请输入时间(格式hh:mm:ss)";
while(1)
{
cin>>hour>>c1>>minute>>c2>>sec;
if(c1!=':'||c2!=':')
cout<<"格式不正确,请重新输入"<<endl;
else if (!is_time(hour,minute,sec))
cout<<"时间非法,请重新输入"<<endl;
else
break;
}
}
void Time::show_time( )
{
cout<<hour<<":"<<minute<<":"<<sec<<endl;
}
bool Time::is_time(int h,int m, int s)
{
if(h<0 ||h>24 || m<0 ||m>60 || s<0 ||s>60)
return false;
return true;
}
- 第三周报告一
- 第三周报告三
- 第三周报告
- 第二周报告一
- 十二周报告一
- 十三周报告一
- 十四周报告一
- 十五周报告一
- 周报告
- [CSDN代码夏令营]spark-webserver 第三周报告
- 第18周报告(一):指向字符的指针
- 第四周报告一:计算三角形的周长和面积
- 第十三周报告3
- 17周报告3
- 第十周报告2
- 第十三周报告3
- 第15周报告
- 第十七周报告2
- 佛法中是如何解释宇宙和生命的诞生的?
- 总结
- 文件结构“图”
- asp.net 获得存储过程 返回值,影响行数,输出参数 output 用法
- java点滴
- 第三周报告一
- 设计模式之创建模式Builder
- 周总结3.04----3.11(简单的写了一点)
- C++中将string类型转换为int, float, double类型 主要通过以下几种方式:
- Struts2拦截器介绍及说明
- 如何分析最耗CPU的线程
- 模仿第三周任务,判断三角形
- excell vba
- 期待新的ArcGIS Runtime SDK