Write a program in C++ language to realize the entry of student grades, editing of student information, and printing of student information (including grades and numbers)

Design a student class student, which has private member functions: registration number, name, math grades, English grades, computer grades; public member functions: the function sum() to find the total grades of three courses ; find three courses The function average() for class average grade ; the function print() for displaying student data information ; the function get_reg_num() for obtaining student registration number ; the function set_stu_inf() for setting student data information . Prepare the main function and describe an array of student class objects And carry out the input and setting of the student information of the whole class, and then calculate the total score of each student, the average score, the highest score of the total score of the whole class, the total average score of the whole class, and after inputting a registration number, output the relevant information of the student all data information.

code:

#include<iostream>

 

using namespace std;

 

#define num 3 // Number of students in the class

 

class cstudent

 

{

 

private:

 

 int kingdom,math,english,computer;

 

 char name[10];

 

public:

 

 int sum();

 

 void average();

 

 void display();

 

 void set_stu_inf();

 void get_reg_num();

 

};

 

int cstudent::sum()

 

{

 

 return (math+english+computer);

 

}

 

void cstudent::average()

 

{

 

 float ave;

 

 ave=(math+english+computer)/3;

 

 cout<<"注册号为:"<<regnum<<"的学生的平均成绩为:"<<ave<<endl;

 

}

 

void cstudent::display()

 

{

 

 cout<<"注册号:"<<regnum<<endl;

 

 cout<<"姓名:"<<name<<endl;

 

 cout<<"数学:"<<math<<endl<<"外语:"<<english<<endl<<"计算机:"<<computer<<endl;

 

}

void cstudent::get_reg_num()

{

cout<<"请输入学生信息:"<<endl;

 

 cout<<"注册号:";

 

 cin>>regnum;

}

void cstudent::set_stu_inf()

 

{

 

 

 

 cout<<"姓名:";

 

 cin>>name;

 

 cout<<"数学:";

 

 cin>>math;

 

 cout<<"外语:";

 

 cin>>english;

 

 cout<<"计算机:";

 

 cin>>computer;

 

}

 

void main()

 

{

 

 int i;

 

 cstudent stu[num];

 

 for(i=0;i<num;i++)

 

 {

 

  stu[i].set_stu_inf();

 

 }

 

 int max=0,maxj;

 

 for(i=0;i<num;i++)

 

 {

 

  cout<<""<<i+1<<"个学生总成绩"<<stu[i].sum()<<endl;

 

 }

 

 for(i=0;i<num;i++)

 

 {

 

  stu[i].average();

 

 }

 

 for(i=0;i<num;i++)

 

 {

 

  if(stu[i].sum()>max)

 

  {

 

   max=stu[i].sum();

 

   maxj=i;

 

  }

 

 }

 

 cout<<"全班学生总成绩最高的同学的全部数据信息 "<<endl;

 

 stu[maxj].display();

 

}


运行结果:

Guess you like

Origin blog.csdn.net/qq_37904531/article/details/78009675