求大神帮小弟我看看哈,代码编译时vs没有显示异常,但是运行结果却达不到预定的效果
求大神帮我看看哈,代码编译时vs没有显示错误,但是运行结果却达不到预定的效果
#include<string>
#include<iostream>
using namespace std;
class Student
{
public:
Student(int num,string name,string sex,float score1,float score2)
{
}
float Average()
{
float a;
a=(score1+score2)/2;
return a;
}
void display()
{
cout<<"学号: "<<num<<endl;
cout<<"姓名: "<<name<<endl;
cout<<"性别: "<<sex<<endl;
cout<<"课程1: "<<score1<<endl;
cout<<"课程2: "<<score2<<endl;
cout<<"平均分: "<<Average()<<endl;
}
private:
int num;
string name;
string sex;
float score1;
float score2;
};
void main()
{
Student stu1(1,"jack","man",89,78);
stu1.display();
Student stu2(2,"john","man",87,89);
stu2.display();
Student stu3(3,"mary","woman",78,87);
stu3.display();
Student stu4(4,"asdf","woman",67,87);
stu4.display();
Student stu5(5,"afc","man",78,98);
stu5.display();
getchar();
}

编译结果根本没有显示姓名和性别,而且课程分数和平均分也没有按我想要的显示,到底是哪里出了问题啊,真心求大神们帮帮忙[
------解决思路----------------------
你student的构造函数自己定义了,但是却并未实现内容。在函数里面对私有成员挨个赋值即可。
------解决思路----------------------
Student(int num,string name,string sex,float score1,float score2)
{
}
这个函数,你以为参数的名字和成员变量的名字一样就可以了吗?什么也不做就想赋值?太幼稚了
#include<string>
#include<iostream>
using namespace std;
class Student
{
public:
Student(int num,string name,string sex,float score1,float score2)
{
}
float Average()
{
float a;
a=(score1+score2)/2;
return a;
}
void display()
{
cout<<"学号: "<<num<<endl;
cout<<"姓名: "<<name<<endl;
cout<<"性别: "<<sex<<endl;
cout<<"课程1: "<<score1<<endl;
cout<<"课程2: "<<score2<<endl;
cout<<"平均分: "<<Average()<<endl;
}
private:
int num;
string name;
string sex;
float score1;
float score2;
};
void main()
{
Student stu1(1,"jack","man",89,78);
stu1.display();
Student stu2(2,"john","man",87,89);
stu2.display();
Student stu3(3,"mary","woman",78,87);
stu3.display();
Student stu4(4,"asdf","woman",67,87);
stu4.display();
Student stu5(5,"afc","man",78,98);
stu5.display();
getchar();
}
编译结果根本没有显示姓名和性别,而且课程分数和平均分也没有按我想要的显示,到底是哪里出了问题啊,真心求大神们帮帮忙[
------解决思路----------------------
你student的构造函数自己定义了,但是却并未实现内容。在函数里面对私有成员挨个赋值即可。
------解决思路----------------------
Student(int num,string name,string sex,float score1,float score2)
{
}
这个函数,你以为参数的名字和成员变量的名字一样就可以了吗?什么也不做就想赋值?太幼稚了