test.h file
登录 | 论坛导航 -> 华新鲜事 -> 求学狮城 | 本帖共有 7 楼,当前显示第 3 楼 : 从楼主开始阅读 : 本帖树形列表 : 返回上一页
作者:和尚庙的主持 (等级:3 - 略知一二,发帖:672) 发表:2003-02-20 16:56:23  3楼 
test.cpp file#include "test.h" #include Time::Time( int hr, int min, int sec) { hour = (hr >= 0 && hr < 24) ? hr : 0; minute = (min >= 0 && min < 60) ? min : 0; second = (sec >= 0 && sec < 60) ? sec : 0; } void Time::settime(int h, int m, int s) { hour = (h >= 0 && h < 24) ? h : 0; minute = (m >= 0 && m < 60) ? m : 0; second = (s >= 0 && s < 60) ? s : 0; } void Time::sethour(int h) {hour = (h >= 0 && h < 24) ? h : 0;} void Time::setmin(int m) {minute = (m >= 0 && m < 60) ? m : 0;} void Time::setsec(int s) {second = (s >= 0 && s < 60) ? s : 0;} int Time::gethour() const {return hour;} int Time::getmin() const {return minute;} int Time::getsec() const {return second;} void Time::printmili() const { cout (more...)
t.cpp file
#include <iostream.h>
#include "test.h"

// void increasement(Time &, const int);

main()
{
Time t;
t.sethour(17);
t.setmin(34);
t.setsec(25);

cout << "Result of setting all valid values:\n Hour: "
<< t.gethour()
<< " Minute: " << t.getmin()
<< " Second: " << t.getsec() <<"\n\n";

t.sethour(234);
t.setmin(43);
t.setsec(6373);

cout << "Result of attemping to set invalid hour and"
<< " second\n Hour: " << t.gethour()
<< " Minute: " << t.getmin()
<< " Second: " << t.getsec() <<"\n\n";

t.settime(11,58,0);
// increasement(t, 3);
return 0;
}

//void increasement (Time &tt, const int count)
//{
// cout << "Increasementing minute "<< count
// << " times:\nStart time: ";
// tt.printsta();
//
// for (int i = 1; i<= count ; i++)
// {
// tt.setmin((tt.getmin()+1)%60);
// if (tt.getmin()==0)
// tt.sethour((tt.gethour()+1)%24);
// cout << "\nminute +1: ";
// tt.printsta();
// }
// cout <<endl;
//}
Put your OWN COOL signature here!
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法!原文 / 传统版 / WAP版只看此人从这里展开收起列表

本帖共有 7 楼,当前显示第 3 楼,本文还有 N-1 层楼,要不你试试看:点击此处阅读更多 >>



请登录后回复:帐号   密码