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 *' 展开
# 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 *' 展开
展开全部
编译时两个地方有错,功能部分未实现
# 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();
}
# 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 广告
2024-10-17 广告
ZigBee 协议属于高级通信协议,是基于上世界的IEEE协会制定的802协议,主要约束了网路的无线协议、通讯协议、安全协议和应用需求等方面的标准,其有效转播速率可以达到300Kbps (千比特率)。 和计算机通信的模式类似,ZigBee的...
点击进入详情页
本回答由晓网科技提供
展开全部
#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();
}
#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();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询