登录 | 首页 -> 华新鲜事 -> 求学狮城 | 切换到:传统版 / sForum | 树形列表
test.h file
<<始页  [1]  末页>> 

test.h file#ifndef TEST_H
#define TEST_H

public class Time {
public:
Time( int = 0, int = 0, int =0);

//set function
void settime(int, int, int);
void sethour(int);
void setmin(int);
void setsec(int);

//get function
int gethour() const;
int getmin() const;
int getsec() const;

void printmili() const;
void printsta() const;

private:
int hour;
int minute;
int second;
};

#endif
[和尚庙的主持 (2-20 16:55, Long long ago)] [ 传统版 | sForum ][登录后回复]1楼

test.cpp file#include "test.h"
#include <iostream.h>

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 <<(hour < 10 ? "0" : "") << hour << ":"
<<(minute < 10 ? "0" : "") << minute << ":"
<<(second < 10 ? "0" : "") <<second;
}

void Time::printsta() const
{
cout << ((hour == 0 || hour== 12) ? 12 : hour % 12)<< ":"
<<(minute <10 ? "0" :"") << minute << ":"
<<(second < 10 ? "0":"") << second
<<(hour < 12 ? "AM" : "PM");
}
[和尚庙的主持 (2-20 16:55, Long long ago)] [ 传统版 | sForum ][登录后回复]2楼

(引用 和尚庙的主持:test.cpp file#include "test.h" #include Time::Time( int hr, int min, int sec) { hour = (hr >= 0 && hr < 24) ? hr : 0; minute =...)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;
//}
[和尚庙的主持 (2-20 16:56, Long long ago)] [ 传统版 | sForum ][登录后回复]3楼

(引用 和尚庙的主持:t.cpp file#include #include "test.h" // void increasement(Time &, const int); main() { Time t; t.sethour(17); t.setmin(34)...)这三个file都在同一个目录下用borland c compiler运行

Error E2040 d:\c\lib\test.h 4: Declaration terminated incorrectly
Error E2090 d:\c\lib\test.cpp 4: Qualifier 'Time' is not a class or namespace name
Error E2040 d:\c\lib\test.cpp 4: Declaration terminated incorrectly


有谁知道该怎么办呢?谢谢.
[和尚庙的主持 (2-20 16:58, Long long ago)] [ 传统版 | sForum ][登录后回复]4楼

(引用 和尚庙的主持:这三个file都在同一个目录下用borland c compiler运行 Error E2040 d:\c\lib\test.h 4: Declaration terminated incorrectly Error E209...)好像C++的class没有modifier吧试着改一下:

in test.h, remove the "public" before "class"


class Time
{
public:
...
...
};
[simon (2-20 21:59, Long long ago)] [ 传统版 | sForum ][登录后回复]5楼

(引用 simon:好像C++的class没有modifier吧试着改一下: in test.h, remove the "public" before "class" class Time { public: ... ... };)没用,同样的问题还会出现[和尚庙的主持 (2-21 0:49, Long long ago)] [ 传统版 | sForum ][登录后回复]6楼

in the test.h file#ifndef TEST_H
#define TEST_H
#endif


the last line cannot be missed.
[注册 (2-22 3:47, Long long ago)] [ 传统版 | sForum ][登录后回复]7楼


<<始页  [1]  末页>> 
登录 | 首页 -> 华新鲜事 -> 求学狮城 | [刷新本页] | 切换到:传统版 / sForum