先将以前的代码贴完,让电脑腾出点空间
功能:输入及输出学生姓名、年龄、性别
/*
功能:设计学生类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;
}