定义一个学生类,数据成员包含姓名和分数,成员函数自行设计。 5
展开全部
#include<stdio.h>
#include<xstring>
#include <WTypes.h>
class CStudent
{
public:
//构造函数
CStudent();
//重载构造
CStudent(LPSTR szName, byte byAge, int nID);
//析构函数
~CStudent();
protected:
LPSTR m_szName; //学生姓名
byte m_byAge; //学生年龄
int m_nID; //学生学号
//功能函数
public:
//学生信息
void SetStudentInf(LPSTR szName, byte byAge, int nID);
//获取学生信息
void GetStudentInf(LPSTR &szName, byte &byAge, int &nID);
};
/////////////////////////////////////////
//实现类方法
CStudent::CStudent()
{
m_szName = NULL;
m_byAge = 0;
m_nID = 0;
}
CStudent::CStudent(LPSTR szName, byte byAge, int nID)
{
m_szName = szName;
m_byAge = byAge;
m_nID = nID;
}
CStudent::~CStudent(){}
void CStudent::SetStudentInf(LPSTR szName, byte byAge, int nID)
{
m_szName = szName;
m_byAge = byAge;
m_nID = nID;
}
void CStudent::GetStudentInf(LPSTR &szName, byte &byAge, int &nID)
{
szName = m_szName;
byAge = m_byAge;
nID = m_nID;
}
void main()
{
CStudent Student;
Student.SetStudentInf("例子",22,1000);
LPSTR lpName=NULL;
byte byAge=0;
int nID=0;
Student.GetStudentInf(lpName,byAge,nID);
printf("学生姓名:%s,年龄:%d,学号:%d",lpName,byAge,nID);
getchar();
}
#include<xstring>
#include <WTypes.h>
class CStudent
{
public:
//构造函数
CStudent();
//重载构造
CStudent(LPSTR szName, byte byAge, int nID);
//析构函数
~CStudent();
protected:
LPSTR m_szName; //学生姓名
byte m_byAge; //学生年龄
int m_nID; //学生学号
//功能函数
public:
//学生信息
void SetStudentInf(LPSTR szName, byte byAge, int nID);
//获取学生信息
void GetStudentInf(LPSTR &szName, byte &byAge, int &nID);
};
/////////////////////////////////////////
//实现类方法
CStudent::CStudent()
{
m_szName = NULL;
m_byAge = 0;
m_nID = 0;
}
CStudent::CStudent(LPSTR szName, byte byAge, int nID)
{
m_szName = szName;
m_byAge = byAge;
m_nID = nID;
}
CStudent::~CStudent(){}
void CStudent::SetStudentInf(LPSTR szName, byte byAge, int nID)
{
m_szName = szName;
m_byAge = byAge;
m_nID = nID;
}
void CStudent::GetStudentInf(LPSTR &szName, byte &byAge, int &nID)
{
szName = m_szName;
byAge = m_byAge;
nID = m_nID;
}
void main()
{
CStudent Student;
Student.SetStudentInf("例子",22,1000);
LPSTR lpName=NULL;
byte byAge=0;
int nID=0;
Student.GetStudentInf(lpName,byAge,nID);
printf("学生姓名:%s,年龄:%d,学号:%d",lpName,byAge,nID);
getchar();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <cstring> //学生成绩,分数
#include <string>
#include <iostream>
using namespace std;
class STUD
{
public:
STUD()
{
m_strName = "";
m_nMark = 0;
}
void setStud(string strName, int nMark);
void print();
private:
string m_strName;
int m_nMark;
};
void STUD::setStud(std::string strName, int nMark)
{
m_strName = strName;
m_nMark = nMark;
}
void STUD::print()
{
cout << "name: " << m_strName << endl;
cout << "mark: " << m_nMark << endl;
}
void main()
{
string name;
int mark;
STUD stud;
cout << "Name: ";
cin >> name;
cout << "mark: ";
cin >> mark;
stud.setStud(name, mark);
stud.print();
}
#include <string>
#include <iostream>
using namespace std;
class STUD
{
public:
STUD()
{
m_strName = "";
m_nMark = 0;
}
void setStud(string strName, int nMark);
void print();
private:
string m_strName;
int m_nMark;
};
void STUD::setStud(std::string strName, int nMark)
{
m_strName = strName;
m_nMark = nMark;
}
void STUD::print()
{
cout << "name: " << m_strName << endl;
cout << "mark: " << m_nMark << endl;
}
void main()
{
string name;
int mark;
STUD stud;
cout << "Name: ";
cin >> name;
cout << "mark: ";
cin >> mark;
stud.setStud(name, mark);
stud.print();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
class Stu
{
public:
void set()
{cout<<"输入姓名和分数:"<<endl;
string s;
int t;
cin>>s;
cin>>t;
name=s;
score=t;
}
void show()
{cout<<"姓名:"<<name<<“分数:"<<score<<endl;}
private:
string name;
int score;
}
就行了,是个很简单的类
{
public:
void set()
{cout<<"输入姓名和分数:"<<endl;
string s;
int t;
cin>>s;
cin>>t;
name=s;
score=t;
}
void show()
{cout<<"姓名:"<<name<<“分数:"<<score<<endl;}
private:
string name;
int score;
}
就行了,是个很简单的类
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询