
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<string>
#define LIST_INIT_SIZE 50
#define LISTINCREMENT 10
using namespace std;
class Student
{
public:
void InputStudent();//输入学生信息
void OutputStudent();//输出学生信息
void ChangeStudent();//修改学生信息
void DeleteStudent();//删除学生信息
void SearchStudent();//查找
friend class Class;
private:
string name,sex;
int id,age;
float english_score,math_score,computer_score;
};
void Student::InputStudent()
{
cout<<"请输入你要录入的学生的姓名:";
cin>>name;
cout<<"\n"<<"性别:";
cin>>sex;
cout<<"\n"<<"年龄:";
cin>>age;
cout<<"\n"<<"学号:";
cin>>id;
cout<<"\n"<<"数学成绩:";
cin>>math_score;
cout<<"\n"<<"英语成绩:";
cin>>english_score;
cout<<"\n"<<"计算机成绩:";
cin>>computer_score;
cout<<"\n";
}
void Student::OutputStudent()
{
cout<<"姓名 性别 学号 年龄 数学 英语 计算机"<<endl;
cout<<name<<" "<<sex<<" "<<id<<" "<<age<<" "<<math_score<<" "<<english_score<<" "<<computer_score<<" ";
cout<<"\n";
}
typedef struct {
Student *elem;
int length;
int listsize;
}SqList;
class Class
{
public:
void InputClass();//输入班级信息
void OutputClass();//输出班级信息
void InitClass_Sq(SqList &L);
void FillClass_Sq(SqList &L,int i,Student St);//将学生类插入到班级的线性表中
int GetClassNumber();
SqList GetClass();
private:
SqList Class;
string ClassName;
int ClassNumber;
//要增加学生类的顺序表
};
void Class::InputClass()
{
cout<<"请输入你要创建的班级的名称:";
cin>>ClassName;
cout<<"\n";
cout<<"请输入该班级的人数:";
cin>>ClassNumber;
cout<<"\n";
}
void Class::OutputClass()
{
cout<<"该班级总人数为:"<<ClassNumber<<endl;
cout<<"该班级所有学生姓名为:";
for(int i=1;i<=ClassNumber;i++)
{
cout<<Class.elem[i-1].name<<"\n";
}
cout<<"\n";
}
void Class::InitClass_Sq(SqList &L){
L.elem=(Student *)malloc(LIST_INIT_SIZE*sizeof(Student));
if(!L.elem)exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
}
void Class::FillClass_Sq(SqList &L,int i,Student St){
if(L.length>=L.listsize){
Student *newbase;
newbase=(Student *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(Student));
if(!newbase)exit(OVERFLOW);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
L.elem[i-1]=St;
++L.length;
}
int Class::GetClassNumber()
{
return ClassNumber;
}
SqList Class::GetClass()
{
return Class;
}
int main()
{
Class Classone;
Classone.InputClass();
SqList ClassoneList;
Classone.InitClass_Sq(ClassoneList);
Student stud[Classone.GetClassNumber()];
for(int j=0;j<Classone.GetClassNumber();j++){
stud[j].InputStudent();
Classone.FillClass_Sq(ClassoneList,j+1,stud[j]);
}
Classone.GetClass()=ClassoneList;
Classone.OutputClass();
return 0;
}
#include<stdlib.h>
#include<math.h>
#include<string>
#define LIST_INIT_SIZE 50
#define LISTINCREMENT 10
using namespace std;
class Student
{
public:
void InputStudent();//输入学生信息
void OutputStudent();//输出学生信息
void ChangeStudent();//修改学生信息
void DeleteStudent();//删除学生信息
void SearchStudent();//查找
friend class Class;
private:
string name,sex;
int id,age;
float english_score,math_score,computer_score;
};
void Student::InputStudent()
{
cout<<"请输入你要录入的学生的姓名:";
cin>>name;
cout<<"\n"<<"性别:";
cin>>sex;
cout<<"\n"<<"年龄:";
cin>>age;
cout<<"\n"<<"学号:";
cin>>id;
cout<<"\n"<<"数学成绩:";
cin>>math_score;
cout<<"\n"<<"英语成绩:";
cin>>english_score;
cout<<"\n"<<"计算机成绩:";
cin>>computer_score;
cout<<"\n";
}
void Student::OutputStudent()
{
cout<<"姓名 性别 学号 年龄 数学 英语 计算机"<<endl;
cout<<name<<" "<<sex<<" "<<id<<" "<<age<<" "<<math_score<<" "<<english_score<<" "<<computer_score<<" ";
cout<<"\n";
}
typedef struct {
Student *elem;
int length;
int listsize;
}SqList;
class Class
{
public:
void InputClass();//输入班级信息
void OutputClass();//输出班级信息
void InitClass_Sq(SqList &L);
void FillClass_Sq(SqList &L,int i,Student St);//将学生类插入到班级的线性表中
int GetClassNumber();
SqList GetClass();
private:
SqList Class;
string ClassName;
int ClassNumber;
//要增加学生类的顺序表
};
void Class::InputClass()
{
cout<<"请输入你要创建的班级的名称:";
cin>>ClassName;
cout<<"\n";
cout<<"请输入该班级的人数:";
cin>>ClassNumber;
cout<<"\n";
}
void Class::OutputClass()
{
cout<<"该班级总人数为:"<<ClassNumber<<endl;
cout<<"该班级所有学生姓名为:";
for(int i=1;i<=ClassNumber;i++)
{
cout<<Class.elem[i-1].name<<"\n";
}
cout<<"\n";
}
void Class::InitClass_Sq(SqList &L){
L.elem=(Student *)malloc(LIST_INIT_SIZE*sizeof(Student));
if(!L.elem)exit(OVERFLOW);
L.length=0;
L.listsize=LIST_INIT_SIZE;
}
void Class::FillClass_Sq(SqList &L,int i,Student St){
if(L.length>=L.listsize){
Student *newbase;
newbase=(Student *)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(Student));
if(!newbase)exit(OVERFLOW);
L.elem=newbase;
L.listsize+=LISTINCREMENT;
}
L.elem[i-1]=St;
++L.length;
}
int Class::GetClassNumber()
{
return ClassNumber;
}
SqList Class::GetClass()
{
return Class;
}
int main()
{
Class Classone;
Classone.InputClass();
SqList ClassoneList;
Classone.InitClass_Sq(ClassoneList);
Student stud[Classone.GetClassNumber()];
for(int j=0;j<Classone.GetClassNumber();j++){
stud[j].InputStudent();
Classone.FillClass_Sq(ClassoneList,j+1,stud[j]);
}
Classone.GetClass()=ClassoneList;
Classone.OutputClass();
return 0;
}
感觉是我的向顺序表中一个个传递学生类的函数出了问题,但真的不知道怎么弄