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

📄 student.cpp

📁 增加学生信息、删除学生信息、修改学生信息 查询时可实现按姓名查询、按学号查询; 能对用户指定的任意课程名
💻 CPP
字号:
#include "student.h"
#include <iostream>

using namespace std;
//default constructor
Student::Student()
{
	name = new char[3];
	strcpy(name,"no");
	snumber = new char[3];
	strcpy(snumber,"no");

	age = 0;
	sex = 'n';
	chinese = 0;
	math = 0;
	english = 0;
	set_tot();
	set_ava();
}

Student::Student(char *n,char *sn, int a, char s,int y,int m ,int e )
{
	name = new char[strlen(n) + 1];
	strcpy(name , n);

	snumber = new char[strlen(sn) +1];
	strcpy(snumber , sn);
	age = a;
	sex = s;
	chinese = y;
	math = m;
	english = e;
	set_tot();
	set_ava();

}

Student::Student(const Student & st)
{
	name = new char[strlen(st.name) + 1];
	strcpy(name, st.name);

	snumber = new char[strlen(st.snumber) +1];
	strcpy(snumber, st.snumber);
	age = st.age;
	sex = st.sex;
	chinese = st.chinese;
	math = st.math;
	english = st.english;
	set_tot();
	set_ava();

}

Student::~Student()
{
	delete [] name;
	delete [] snumber;
}

//set the value of members of the class

void Student::set_name(const char *n)
{
	delete [] name;
	name = new char[strlen(n) + 1];
	strcpy(name , n);
}
void Student::set_sn(char *sn)
{
	delete [] snumber;
	snumber = new char[strlen(sn) +1];
	strcpy(snumber , sn);
}

void Student::set_age(int a)
{
	age = a;
}

void Student::set_sex(char s)
{
	sex = s;
}

void Student::set_chinese(int yw)
{
	chinese = yw;
	set_tot();
	set_ava();
}

void Student::set_math(int m)
{
	math = m;
	set_tot();
	set_ava();
}

void Student::set_english(int e)
{
	english = e;
	set_tot();
	set_ava();
}
void Student::set_pfm(int y, int m, int e)
{
	chinese = y;
	math = m;
	english = e;
	set_tot();
	set_ava();
}
//get the vaule of the members of the class

char * Student::get_n()const
{
	return name;
}

char * Student::get_sn()const
{
	return snumber;
}

int Student::get_age()const
{
	return age;
}

char Student::get_sex()const
{
	return sex;
}

int Student::get_chinese()const
{
	return chinese;
}

int Student::get_math()const
{
	return math;
}

int Student::get_english()const
{
	return english;
}

int Student::get_tot()const
{
	return total;
}

double Student::get_ava()const
{
	return avag;
}
//show methods

void Student::showall()const
{
	cout<<snumber<<"\t"<<name<<" \t"
		<<age<<" \t "<< sex <<"\t" << chinese
		 << "\t" << math << "\t" << english
		 << "\t" << total << "\t" << avag <<endl;

}

void Student::showpfm()const
{
	cout << "\t" << chinese
		 << "\t" << math << "\t" << english
		 << "\t" << total << "\t" << avag <<endl;
}

/*istream & operator >>(istream & is, Student & stu)
{
	char n[40];
	char sn[15];
	cout << "请输入学号:";
    cin.getline(sn,15);
	cout << "请输入姓名:";
	cin.getline(n,40);
	cout << "请输入年龄:";
	cin >> stu.age;


}*/


Student & Student::operator =(const Student & stu)
{
	if(this == &stu)
		return *this;

	delete [] name;
	delete [] snumber;
	name = new char[strlen(stu.name) + 1];
	strcpy(name , stu.name);

	snumber = new char[strlen(stu.snumber) + 1];
	strcpy(snumber,stu.snumber);
	age = stu.age;
	sex = stu.sex;
	chinese = stu.chinese;
	math = stu.math;
	english = stu.english;
	set_tot();
	set_ava();
	return *this;
}

int Student::get_key(int choice)
{	
	if(choice==1)
		return get_chinese();
	else if(choice==2)
		return get_math();
	else if(choice==3)
		return get_english();
	else
		return get_tot();
}

void Student::outfilestream(ofstream &ofs)
{
	ofs<<age<<"\t"<<avag<<"\t"<<chinese<<"\t"<<english<<"\t"<<math<<"\t"<<name<<"\t"<<sex<<"\t"<<snumber<<"\t"<<total<<endl;

}

void Student::infilestream(ifstream &ifs)
{
	ifs>>age>>avag>>chinese>>english>>math>>name>>sex>>snumber>>total;
}

⌨️ 快捷键说明

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