⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 student.h

📁 内有详细说明文件
💻 H
字号:
#include<iostream.h>
#include<string.h>
class student
{
public:
	student(int n,char na[],char s,int a,float sc[]);
	student();
	~student();
	void in();
	void out();
	void set_num(int n);
	void set_name(char na[]);
	void set_sex(char s);
	void set_age(int a);
	void set_score(float sc[]);
	void set(int n,char na[],char s,int a,float sc[]);
	int get_num();
	void get_name(char na[]);
	char get_sex();
	int get_age();
	void get_score(float sc[]);	
private:
	int num;
	char name[9];
	char sex;
	int age;
	float score[6];
};
student::student(int n,char na[],char s,int a,float sc[])
{
	num=n;
	strcpy(name,na);
	sex=s;
	age=a;
	score[4]=0;
	for(int i=0;i<4;i++)
	{
		score[i]=sc[i];
		score[4]+=score[i];
	}
	score[5]=score[4]/4;
	cout<<"学生类的对象 "<<name
		<<" 的构造函数被调用\n";
}
student::student()
{
	num=0;
	strcpy(name,"");
	sex='f';
	age=18;
	for(int i=0;i<6;i++)
		score[i]=0;
	cout<<"学生类的对象 "<<name
		<<" 的构造函数被调用\n";
}
student::~student()
{
	cout<<"学生类的对象 "<<name
		<<" 的析构函数被调用\n";
}
void student::in()
{
	cout<<"请输入该生的信息\n";
	cout<<"学号:";	cin>>num;
	cout<<"姓名:";	cin>>name;
	cout<<"性别:(男m,女f)";	cin>>sex;
	cout<<"年龄:";	cin>>age;
	score[4]=0;
	for(int i=0;i<4;i++)
	{
		cout<<"成绩"<<i+1<<":";	cin>>score[i];
		score[4]+=score[i];
	}
	score[5]=score[4]/4;
}
void student::out()
{
	cout<<"该生的信息如下:\n"
		<<"学号:"<<num
		<<"\t姓名:"<<name
		<<"\n性别:";
	if(sex=='m') cout<<"男";
	else cout<<"女";
	cout<<"年龄"<<age<<endl;
	for(int i=0;i<4;i++)
		cout<<"成绩"<<i+1<<'='<<score[i]<<"\t";
	cout<<"\n总成绩"<<'='<<score[4]
		<<"\t平均成绩"<<'='<<score[5]<<endl;
}
void student::set_num(int n)
{
	num=n;
}
void student::set_name(char na[])
{
	strcpy(name,na);
}
void student::set_sex(char s)
{
	sex=s;
}
void student::set_age(int a)
{
	age=a;
}
void student::set_score(float sc[])
{
	score[4]=0;
	for(int i=0;i<4;i++)
	{
		score[i]=sc[i];
		score[4]+=score[i];
	}
	score[5]=score[4]/4;
}
void student::set(int n,char na[],char s,int a,float sc[])
{
	num=n;
	strcpy(name,na);
	sex=s;
	age=a;
	score[4]=0;
	for(int i=0;i<4;i++)
	{
		score[i]=sc[i];
		score[4]+=score[i];
	}
	score[5]=score[4]/4;
}
int student::get_num()
{
	return num;
}
void student::get_name(char na[])
{
	strcpy(na,name);
}
char student::get_sex()
{
	return sex;
}
int student::get_age()
{
	return age;
}
void student::get_score(float sc[])
{
	for(int i=0;i<6;i++)
		sc[i]=score[i];
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -