错的稀里糊涂东倒西歪
#include <iostream.h>#include <string.h>
class student_info
{
protected:
char *no; //学号
char *name; //姓名
public:
student_info(char *no1,char *name1); //构造函数
~student_info(); //虚构函数
void setinfo(char *no1,char *name1); //设置函数
virtual void printf() //输出函数
{
cout<<"\n学号:"<<no<<"\n姓名:"<<name<<endl;
}
virtual void input()
{
cout<<"请输入学号:"<<endl;
cin>>no;
cout<<"请输入名字:"<<endl;
cin>>name;
}
};
void student_info::setinfo(char *no1,char *name1)
{
no=new char[strlen(no1)+1];
strcpy(no,no1);
name=new char[strlen(name1)+1];
strcpy(name,name1);
}
student_info::student_info(char *no1,char *name1)
{
no=new char[strlen(no1)+1];
strcpy(no,no1);
name=new char[strlen(name1)+1];
strcpy(name,name1);
}
student_info::~student_info()
{
delete []no;
delete []name;
}
class student_grade:public student_info
{
protected:
float gokugo;
float eigo;
float suugaku;
float konpyu_ta_;
static float sum;
static int count;
float ave;
public:
student_grade()[]
student_grade(char *no1,char *name1,float gokugo1,float eigo1,float suugaku1,float konpyu_ta_1):student_info(char *no1,char *name1)
{
gokugo=gokugo1;
eigo=eigo1;
suugaku=suugaku1;
konpyu_ta_=konpyu_ta_1;
count++;
}
void setgrade(float gokugo1,float eigo1,float suugaku1,float konpyu_ta_1);
void input();
void printf();
};
void setgrade(float gokugo1,float eigo1,float suugaku1,float konpyu_ta_1)
{
gokugo=gokugo1;
eigo=eigo1;
suugaku=suugaku1;
konpyu_ta_=konpyu_ta_1;
}
void student_grade::input()
{
cout<<"输入国语成绩:"<<endl;
cin>>gokugo;
cout<<"输入英语成绩:"<<endl;
cin>>eigo;
cout<<"输入数学成绩:"<<endl;
cin>>suugaku;
cout<<"输入计算机成绩:"<<endl;
cin>>konpyu_ta_;
}
float student_grade::sum=0;
int student_grade::count=0;
void main()
{
student_info p1("001","maiiho);
p1.printf();
}
错误信息
--------------------Configuration: asd - Win32 Debug--------------------
Compiling...
asd.cpp
G:\Users\Maiiho\Desktop\asd.cpp(54) : error C2059: syntax error : ')'
G:\Users\Maiiho\Desktop\asd.cpp(54) : error C2334: unexpected token(s) preceding ':'; skipping apparent function body
G:\Users\Maiiho\Desktop\asd.cpp(69) : error C2065: 'gokugo' : undeclared identifier
G:\Users\Maiiho\Desktop\asd.cpp(69) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
G:\Users\Maiiho\Desktop\asd.cpp(70) : error C2065: 'eigo' : undeclared identifier
G:\Users\Maiiho\Desktop\asd.cpp(70) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
G:\Users\Maiiho\Desktop\asd.cpp(71) : error C2065: 'suugaku' : undeclared identifier
G:\Users\Maiiho\Desktop\asd.cpp(71) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
G:\Users\Maiiho\Desktop\asd.cpp(72) : error C2065: 'konpyu_ta_' : undeclared identifier
G:\Users\Maiiho\Desktop\asd.cpp(72) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
G:\Users\Maiiho\Desktop\asd.cpp(89) : error C2001: newline in constant
G:\Users\Maiiho\Desktop\asd.cpp(90) : error C2146: syntax error : missing ')' before identifier 'p1'
执行 cl.exe 时出错.
asd.exe - 1 error(s), 0 warning(s)