求c++大神帮忙看下这段代码有哪里错啊?
题目:定义一个表示学生信息的student类,在其中有对象成员:Birthday(Date类的对象),姓名Name、学号StuNo、英语成绩EnglishScore、数学...
题目:定义一个表示学生信息的student类, 在其中有对象成员:Birthday(Date类的对象),姓名Name、学号StuNo、英语成绩EnglishScore、数学成绩MathScore、C++成绩CPPScore、平均成绩AvgScore。
代码:
#include<iostream>
using namespace std;
class Student
{
public:
void show_information();
void get_information();
private:
int Birthday;
char Name[20];
int StuNo;
double EnglishScore;
double MathScore;
double CppScore;
double AvgScore;
};
void Student::get_information()
{
int b,no;
double e,ma,c;
char n[20];
cout<<"请输入学生生日"<<endl;
cin>>b;
cout<<"请输入学生姓名"<<endl;
cin>>n;
cout<<"请输入学生学号"<<endl;
cin>>no;
cout<<"请输入学生英语成绩"<<endl;
cin>>e;
cout<<"请输入学生数学成绩"<<endl;
cin>>ma;
cout<<"请输入学生c++成绩"<<endl;
cin>>c;
a=(e+ma+c)/3;
Birthday=b;
Name=n;
StuNo=no;
EnglishScore=e;
MathScore=ma;
CppScore=c;
AvgScore=a;
}
void Student::show_information()
{
cout<<"学生"<<Name<<"生日是:"<<Birthday<<",学号是"<<StuNo<<",英语成绩
是:"<<EnglishScore<<",数学成绩是:"<<MathScore<<",c++成绩
是:"<<CppScore<<",平均成绩是:"<<AvgScore<<endl;
}
void main()
{
Student Student1;
Student1.get_information();
Student1.show_information(); 展开
代码:
#include<iostream>
using namespace std;
class Student
{
public:
void show_information();
void get_information();
private:
int Birthday;
char Name[20];
int StuNo;
double EnglishScore;
double MathScore;
double CppScore;
double AvgScore;
};
void Student::get_information()
{
int b,no;
double e,ma,c;
char n[20];
cout<<"请输入学生生日"<<endl;
cin>>b;
cout<<"请输入学生姓名"<<endl;
cin>>n;
cout<<"请输入学生学号"<<endl;
cin>>no;
cout<<"请输入学生英语成绩"<<endl;
cin>>e;
cout<<"请输入学生数学成绩"<<endl;
cin>>ma;
cout<<"请输入学生c++成绩"<<endl;
cin>>c;
a=(e+ma+c)/3;
Birthday=b;
Name=n;
StuNo=no;
EnglishScore=e;
MathScore=ma;
CppScore=c;
AvgScore=a;
}
void Student::show_information()
{
cout<<"学生"<<Name<<"生日是:"<<Birthday<<",学号是"<<StuNo<<",英语成绩
是:"<<EnglishScore<<",数学成绩是:"<<MathScore<<",c++成绩
是:"<<CppScore<<",平均成绩是:"<<AvgScore<<endl;
}
void main()
{
Student Student1;
Student1.get_information();
Student1.show_information(); 展开
4个回答
展开全部
你是刚开始学C++的吧,编码风格有些奇怪.C++要分开文件来写,而且C++中有字符串类string等,尽量不要用char name[].我给你改了一下.
Student.h文件
#include <string>
using namespace std;
class Student
{
public:
void show_information();
void get_information();
private:
string m_strName;
int m_iBirthday;
int m_iStudentID;
double m_dEnglishScore;
double m_dMathScore;
double m_dCppScore;
double m_dAvgScore;
};
Student.cpp文件
#include "Student.h"
#include <iostream>
using namespace std;
void Student::get_information()
{
cout<<"请输入学生生日"<<endl;
cin>>m_iBirthday;
cout<<"请输入学生姓名"<<endl;
cin>>m_strName;
cout<<"请输入学生学号"<<endl;
cin>>m_iStudentID;
cout<<"请输入学生英语成绩"<<endl;
cin>>m_dEnglishScore;
cout<<"请输入学生数学成绩"<<endl;
cin>>m_dMathScore;
cout<<"请输入学生c++成绩"<<endl;
cin>>m_dCppScore;
m_dAvgScore = (m_dEnglishScore + m_dMathScore + m_dCppScore)/3;
}
void Student::show_information()
{
cout<<"学生"<<m_strName<<"生日是:"<<m_iBirthday<<",学号是"<<m_iStudentID<<",英语成绩是:"<<m_dEnglishScore<<",数学成绩是:"<<m_dMathScore<<",c++成绩是:"<<m_dCppScore<<",平均成绩是:"<<m_dAvgScore<<endl;
}
main.cpp文件
#include<iostream>
#include "Student.h"
using namespace std;
int main()
{
Student Student1;
Student1.get_information();
Student1.show_information();
return 0;
}
vs2005运行正确,加油吧.
Student.h文件
#include <string>
using namespace std;
class Student
{
public:
void show_information();
void get_information();
private:
string m_strName;
int m_iBirthday;
int m_iStudentID;
double m_dEnglishScore;
double m_dMathScore;
double m_dCppScore;
double m_dAvgScore;
};
Student.cpp文件
#include "Student.h"
#include <iostream>
using namespace std;
void Student::get_information()
{
cout<<"请输入学生生日"<<endl;
cin>>m_iBirthday;
cout<<"请输入学生姓名"<<endl;
cin>>m_strName;
cout<<"请输入学生学号"<<endl;
cin>>m_iStudentID;
cout<<"请输入学生英语成绩"<<endl;
cin>>m_dEnglishScore;
cout<<"请输入学生数学成绩"<<endl;
cin>>m_dMathScore;
cout<<"请输入学生c++成绩"<<endl;
cin>>m_dCppScore;
m_dAvgScore = (m_dEnglishScore + m_dMathScore + m_dCppScore)/3;
}
void Student::show_information()
{
cout<<"学生"<<m_strName<<"生日是:"<<m_iBirthday<<",学号是"<<m_iStudentID<<",英语成绩是:"<<m_dEnglishScore<<",数学成绩是:"<<m_dMathScore<<",c++成绩是:"<<m_dCppScore<<",平均成绩是:"<<m_dAvgScore<<endl;
}
main.cpp文件
#include<iostream>
#include "Student.h"
using namespace std;
int main()
{
Student Student1;
Student1.get_information();
Student1.show_information();
return 0;
}
vs2005运行正确,加油吧.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先问一下,你考全代码没有,因为main函数却结束的“}”,然后能不能把出错信息说明一下,是编译错,还是链接错,还是运行错
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
路过看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询