这是一个学生管理系统的程序,要实现求三科成绩的平均分,还要实现对每个学生信息的增删改查,请教一下要怎么实现?
#include<iostream>using namespace std;
#define NULL 0
class Student
{
public:
Student(int n,int a,float m,float t,float k):num(n),age(a),score1(m),score2(t),score3(k){}
void output(int n,int a,float m,float t,float k);
void average(int n,int a,float m,float t,float k);
void add(int n,int a,float m,float t,float k);
void del(int n,int a,float m,float t,float k);
void change(int n,int a,float m,float t,float k);
void find(int n,int a,float m,float t,float k);
void display_1();
void display_2();
private:
int num;
int age;
float score1;
float score2;
float score3;
int next;
};
void Student::output()
{ Student stud;
Student*p=stud;
int i;
for(i=0;i<=5;p=p+1,i=i+1)
p->display_1();
}
void Student::average()
{
int av;
av=(score1+score2+score3)/3;
Student*q=av;
int i;
for(i=0;i<=5;q=q+1,i=i+1)
q->display_2();
}
void Student::add()
{
Student stud;
Student*p0,*p1,*p2;
Student head;
Student *next;
p0=stud;
p1=head;
Student*temp;
p2 = NULL;
while((p1 != NULL)&&(p0->num>p1->num))
{
p2=p1;
p1=p1->next;
}
if(p2 == NULL)
{
stud->next = head;
head = stud;
}
else
{
temp = p2->next;
p2->next = stud[];
stud->next = temp;
}
return(head);
}
void Student::del()
{
Student*p1,*p2;
Student head;
Student*next;
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)
{
Student*temp = head;
}
else
{
Student*temp = p2->next;
p2->next=p1->next;
}
cout<<"delete:"<<num<<endl;
}
else
cout<<"It doesn't exist!"<<endl;
return(head);
}
void Student::change()
{
Student stud(102,20,94,82.5,78);
stud.display_1();
stud.change(102,20,94,82.5,90);
stud.display_1();
}
void Student::find()
{ Student stud;
cout<<"所要查学生的学号"<<num<<endl;
Student*r=stud;
int i;
for(i=0;i<=5;r=r+1,i=i+1)
{
if(num==stud[i])
stud.display_1();
}
}
void Student::display_1()
{
cout<<num<<" "<<age<<" "<<score1<<' '<<score2<<' '<<score3<<endl;
}
void Student::display_2()
{
cout<<"平均分"<<' '<<endl;
}
int main()
{
Student stud[5]={Student(101,19,80.5,90,75),Student(102,20,94,82.5,78),Student(103,19,76,87,92.5),
Student(104,20,79.5,78,90.5),Student(105,19,84.5,76,90)};
void ave(Student[5]);
ave(stud);
void add(Student[5]);
add(stud);
void del(Student[5]);
del(stud);
void change(Student[5]);
change(stud);
void find(Student[5]);
find(stud);
return 0;
}
这是一个学生管理系统的程序,要实现求三科成绩的平均分,还要实现对每个学生信息的增删改查,请教一下要怎么实现?