『代码』··By/蜜汁炒酸奶

学生类Student之学生信息-C++

先将以前的代码贴完,让电脑腾出点空间 功能:输入及输出学生姓名、年龄、性别

/*
功能:设计学生类Student
日期:2013-10-19
*/
#include <iostream>
#include <string>
using namespace std;

class Student
{
public:
	Student(string aName,string aAge,string aSex);

	~Student();
	string getName()const;
	string getAge()const;
	string getSex()const;
	void setName(string aName);
	void setAge(string aAge);
	void setSex(string aSex);
private:
	string m_aName;
	string m_aAge;
	string m_aSex;
};
Student::Student(string aName=NULL,string aAge=NULL,string aSex=NULL):
m_aName(aName),m_aAge(aAge),m_aSex(aSex){};
Student::~Student(){};
string Student::getName()const
{
	return m_aName;
}
string Student::getAge()const
{
	return m_aAge;
}
string Student::getSex()const
{
	return m_aSex;
}
void Student::setName(string aName)
{
     m_aName = aName;
}
void Student::setAge(string aAge)
{
	m_aAge = aAge;
}
void Student::setSex(string aSex)
{
	m_aSex = aSex;
}
int main(void)
{

   int n=5;
   string name,age,sex;
   Student student;
   cout<<"请输入学生姓名、年龄、性别"<<endl;
   cin>>name>>age>>sex;
   student.setName(name);
   student.setAge(age);
   student.setSex(sex);
   cout<<"学生信息为:"<<endl;
   cout<<student.getName()<<" "<<student.getAge()<<" "<<student.getSex()<<endl;





	system("pause");
	return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

预览
Loading comments...
0 条评论

暂无数据

example
预览