建立名为CStudent的类,该类有成员变量:姓名、学号、数学、语文、英语三门课成绩
还包括两个成员函数:用于初始化学生姓名、学号、性别和三门课成绩的构造函数;用于输出学生信息的函数。编写主函数,并声明一个CStudent对象,然后调用成员函数在屏幕输出对...
还包括两个成员函数:用于初始化学生姓名、学号、性别和三门课成绩的构造函数;用于输出学生信息的函数。编写主函数,并声明一个CStudent对象,然后调用成员函数在屏幕输出对象信息。
展开
1个回答
展开全部
#include <iostream>
#include <string>
#include <memory.h>
using std::string;
using std::cout;
using std::endl;
class CStudent
{
public:
CStudent(){}
CStudent(string name, unsigned int id, bool Isman, float score[3]);
~CStudent(){}
void PrintInfo(); // 输出学生信息.
protected:
private:
string m_name;
unsigned int m_id;
bool m_Isman;
float m_score[3];
};
CStudent::CStudent(string name, unsigned int id, bool Isman, float score[3])
{
m_name = name;
m_id = id;
m_Isman = Isman;
memcpy(m_score, score, 3 * sizeof(float));
}
void CStudent::PrintInfo()
{
cout<<"姓名:"<<m_name
<<", 学号:"<<m_id;
m_Isman ? (cout<<", 男性") : (cout<<", 女性");
cout<<", 成绩:"<<m_score[0]<<" "<<m_score[1]<<" "<<m_score[2]<<endl;
}
int main(void)
{
string name("张三");
unsigned int id(210);
bool man = true; // 是爷们
float score[3] = {80, 90, 99};
CStudent student(name, id, man, score);
student.PrintInfo();
return 0;
}
#include <string>
#include <memory.h>
using std::string;
using std::cout;
using std::endl;
class CStudent
{
public:
CStudent(){}
CStudent(string name, unsigned int id, bool Isman, float score[3]);
~CStudent(){}
void PrintInfo(); // 输出学生信息.
protected:
private:
string m_name;
unsigned int m_id;
bool m_Isman;
float m_score[3];
};
CStudent::CStudent(string name, unsigned int id, bool Isman, float score[3])
{
m_name = name;
m_id = id;
m_Isman = Isman;
memcpy(m_score, score, 3 * sizeof(float));
}
void CStudent::PrintInfo()
{
cout<<"姓名:"<<m_name
<<", 学号:"<<m_id;
m_Isman ? (cout<<", 男性") : (cout<<", 女性");
cout<<", 成绩:"<<m_score[0]<<" "<<m_score[1]<<" "<<m_score[2]<<endl;
}
int main(void)
{
string name("张三");
unsigned int id(210);
bool man = true; // 是爷们
float score[3] = {80, 90, 99};
CStudent student(name, id, man, score);
student.PrintInfo();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询