C++中继承类的问题

#include"iostream.h"#include"string.h"classclock{private:inthour;intminute;intsecond;... # include "iostream.h"
# include "string.h"

class clock
{
private:
int hour;
int minute;
int second;
public:
clock(int hour = 0,int minute = 0,int second = 0);
int return_hour();
void output();
};

class Newclock:public clock
{
private:
char a[10];
public:
Newclock(int hour = 0,int minute = 0,int second = 0,char a = NULL);
void judge_AM_PM();
void output();
};

clock::clock(int hour, int minute, int second)
{
this -> hour = hour;
this -> minute = minute;
this -> second = second;
}

int clock::return_hour()
{
return hour;
}

void clock::output()
{
cout<<"The time is :"<<endl;
cout<<hour<<":"<<minute<<":"<<second<<endl;
}

Newclock::Newclock(int hour,int minute,int second,char a):clock(hour,minute,second);

void Newclock::judge_AM_PM()
{
if (clock::return_hour > 12)
{
strcpy(a,"AM");
}

else
{
strcpy(a,"PM");
}
}

void Newclock::output()
{
clock::output();
cout<<a<<endl;
}

void main()
{
Newclock time(8,12,13);

time.judge_AM_PM();
time.output();

}

这个程序的功能是:将输入的一个时间(比如:13:12:14)改成(1:12:14 PM),即加上 AM 还是PM,但我运行时,遇到了很多麻烦。怎么改都不行。请高手帮忙改一下。
错误如下:
error C2062: type 'void' unexpected
error C2630: ';' found in what should be a comma-separated list
error C2296: '>' : illegal, left operand has type 'int (__thiscall clock::*)(void)'
error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
type to pointer type requires reinterpret_cast, C-style cast or function-style cast
error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
展开
 我来答
zhuangzizhi
推荐于2016-10-11
知道答主
回答量:32
采纳率:0%
帮助的人:22.1万
展开全部
编译时两个地方有错,功能部分未实现
# include <iostream>
# include <string>

using namespace std;

class clock
{
private:
int hour;
int minute;
int second;
public:
clock(int hour = 0,int minute = 0,int second = 0);
int return_hour();
void output();
};

class Newclock:public clock
{
private:
char a[10];
public:
Newclock(int hour = 0,int minute = 0,int second = 0,char a = NULL);
void judge_AM_PM();
void output();
};

clock::clock(int hour, int minute, int second)
{
this -> hour = hour;
this -> minute = minute;
this -> second = second;
}

int clock::return_hour()
{
return hour;
}

void clock::output()
{
cout<<"The time is :"<<endl;
//
// 实现将输入的一个时间(比如:13:12:14)改成(1:12:14 PM),也就是hour
//如果大于12,就减12
//
if (hour > 12)
hour -= 12;
cout<<hour<<":"<<minute<<":"<<second<<endl;
}

Newclock::Newclock(int hour,int minute,int second,char a):clock(hour,minute,second)
//上面已经声明过了!这里必须定义
{}

void Newclock::judge_AM_PM()
{
if (clock::return_hour() > 12) // 加上函数参数列表,也就是()
{
strcpy(a,"AM");
}

else
{
strcpy(a,"PM");
}
}

void Newclock::output()
{
clock::output();
cout<<a<<endl;
}

void main()
{
Newclock time(16,12,13);

time.judge_AM_PM();
time.output();

}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
晓网科技
2024-10-17 广告
ZigBee 协议属于高级通信协议,是基于上世界的IEEE协会制定的802协议,主要约束了网路的无线协议、通讯协议、安全协议和应用需求等方面的标准,其有效转播速率可以达到300Kbps (千比特率)。 和计算机通信的模式类似,ZigBee的... 点击进入详情页
本回答由晓网科技提供
bdlanyu
2011-02-10 · TA获得超过550个赞
知道小有建树答主
回答量:378
采纳率:0%
帮助的人:519万
展开全部
#include <iostream>
#include "string.h"

using namespace std;
class clock
{
private:
int hour;
int minute;
int second;
public:
clock(int hour = 0,int minute = 0,int second = 0);
int return_hour();
void output();
};

class Newclock:public clock
{
private:
char a[10];
public:
Newclock(int hour = 0,int minute = 0,int second = 0,char a = NULL);
void judge_AM_PM();
void output();
};

clock::clock(int hour, int minute, int second)
{
this -> hour = hour;
this -> minute = minute;
this -> second = second;
}

int clock::return_hour()
{
return hour;
}

void clock::output()
{
cout<<"The time is :"<<endl;
cout<<hour<<":"<<minute<<":"<<second<<endl;
}

Newclock::Newclock(int hour,int minute,int second,char a):clock(hour,minute,second){};//
//必须要有函数体

void Newclock::judge_AM_PM()
{
if (clock::return_hour() > 12)//函数调用要有()
{
strcpy(a,"AM");
}

else
{
strcpy(a,"PM");
}
}

void Newclock::output()
{
clock::output();
cout<<a<<endl;
}

int main()
{
Newclock time(8,12,13);

time.judge_AM_PM();
time.output();

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式