当前位置:编程学习 > C/C++ >>

求C++编程,编写一个学生类

编写一个学生类,包括成绩、学号、性别、姓名、年龄、班级,要求:可以通过输入学号或年龄查询该学生的其他全部信息,可以进行学号、成绩、班级的排序
答案:
程序比较长,分开发给你,按照顺序粘贴到一起就行了
类定义:
#include <iostream>
#include <string>
#include <iomanip>
#define N 100
using namespace std;
int num_of_students=0;

class student
{
private:
string name;
string no;
string 易做图;
int age;
float score;
int squad;
public:
void get_info();
void show_info();
void show_ord_info();
string &get_name() {return name;}
string &get_no() {return no;}
float get_score() {return score;}
int get_squad() {return squad;}
} st[N],t;

void student::get_info()
{
cout<<"姓名:";
cin>>name;
cout<<"性别:";
cin>>易做图;
cout<<"年龄:";
cin>>age;
cout<<"学号:";
cin>>no;
cout<<"班级:";
cin>>squad;
cout<<"成绩:";
cin>>score;
}

void student::show_info()
{
cout<<"---------------"<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"性别:"<<易做图<<endl;
cout<<"年龄:"<<age<<endl;
cout<<"学号:"<<no<<endl;
cout<<"班级:"<<squad<<endl;
cout<<"成绩:"<<score<<endl;
cout<<"---------------"<<endl;
}

void student::show_ord_info()
{
cout<<setw(5)<<no<<'\t'<<name<<'\t'<<易做图<<'\t'<<age<<'\t'<<squad<<'\t'<<score<<endl;
}
程序比较长,分开发给你,按照顺序粘贴到一起就行了类定义:#include <iostream>#include <string>#include <iomanip>#define N 100using namespace std;int num_of_students=0;class student{    private:        string name;        string no;        string 易做图;        int age;        float score;        int squad;    public:        void get_info();        void show_info();        void show_ord_info();        string &get_name()  {return name;}        string &get_no()    {return no;}        float get_score()   {return score;}        int get_squad()     {return squad;}} st[N],t;void student::get_info(){    cout<<"姓名:";    cin>>name;    cout<<"性别:";    cin>>易做图;    cout<<"年龄:";    cin>>age;    cout<<"学号:";    cin>>no;    cout<<"班级:";    cin>>squad;    cout<<"成绩:";    cin>>score;}void student::show_info(){    cout<<"---------------"<<endl;    cout<<"姓名:"<<name<<endl;    cout<<"性别:"<<易做图<<endl;    cout<<"年龄:"<<age<<endl;    cout<<"学号:"<<no<<endl;    cout<<"班级:"<<squad<<endl;    cout<<"成绩:"<<score<<endl;    cout<<"---------------"<<endl;}void student::show_ord_info(){    cout<<setw(5)<<no<<'\t'<<name<<'\t'<<易做图<<'\t'<<age<<'\t'<<squad<<'\t'<<score<<endl;}
#include <iostream>
#include <string>
using namespace std;
class students
{
private:
char name[40];
char 易做图;
int age;
int ID;
int class;
int score;
public:
students ID_search(int ID);
students name_search(char *name);
}

上一个:四个C++的小题目 急急急!!!!!
下一个:C++鍏ラ棬锛岃鐪嬪摢鏈功锛?- 宸茶В鍐?- 鎼滄悳闂棶

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,