首页 新闻 搜索 专区 学院

如何用C++中的链表和类模板实现学生选课管理小型系统?

0
[已解决问题] 解决于 2012-06-11 18:33

主模块包括学生模块和管理模块,学生模块包括学生选课,学生情况,选课情况,退选系统,

管理模块包括增加学生,学生情况,删除学生,查看课程,删除课程,增加教师,查看教师,

foxing的主页 foxing | 初学一级 | 园豆:5
提问于:2012-06-01 20:57
< >
分享
最佳答案
0

题目描述的不是很清楚呀?我猜测着写的。

我只写了学生模块,希望能帮到你

类模版也没用,没看出来哪里需要用类模版。莫非是为了以后的扩展,增加了校长类什么的?^_^

// student.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;


//假设一个学生最多选10门课程
//假设一位教师最多能教3门课程
#define MAXOFSTCOURSE 10
#define MAXOFTCOURSE 3

//课程节点
typedef struct Course
{
char *course;
struct Course* next;
}Course,*pNodeOfCourse;

//学生节点
typedef struct Student
{
char *name;
int number;
pNodeOfCourse pArry;

}Student,*pNodeOfStudent;

//教师节点
typedef struct Teacher
{
char *name;
char number;
pNodeOfCourse pArry;
}Teacher,*pNodeofTeacher;

//学生管理节点
typedef struct MANAGEST
{
pNodeOfStudent pStudent;
struct MANAGEST*next;
}MANAGEST;

//教师管理节点
typedef struct MANAGET
{
pNodeOfStudent pStudent;
struct MANAGET*next;
}MANAGET;

//管理类
class classOfManage
{
public:
classOfManage();
~classOfManage();
//查看学生
//查看课程
//删除学生
//删除课程
//查看教师
//增加教师
private:
MANAGET *pManageT;
MANAGEST *pManageST;
};

//学生类
class classOfStudent
{
public:
classOfStudent(char *name,int num);
~classOfStudent();
//选课
pNodeOfStudent chooseCourse(char *course);

//选课情况
void showCourse();

//学生情况
void showStudent();

//退选
pNodeOfStudent deleteCourse(char *coure);
private:
pNodeOfStudent student;
};

classOfStudent::classOfStudent(char*name,int num)
{
student = new Student;
int len = strlen(name) + 1;
if(len == 1)
{
student->name = NULL;
}
else
{
student->name = new char[len];
strcpy(student->name,name);
}
student->number = num;
Course *pHead = new Course;
pHead->next = NULL;
student->pArry = pHead;
}

classOfStudent::~classOfStudent()
{
delete student;
student = NULL;
}

pNodeOfStudent classOfStudent::chooseCourse(char *course)
{
pNodeOfCourse p = new Course;
int len = strlen(course) +1;
if(len == 1)
{
return student;
}
course = strlwr(course);
pNodeOfCourse q = student->pArry->next;
//加一个判断,保证不是重复选课
if(q == NULL)
{
p->course = new char[len];
strcpy(p->course,course);
p->next = student->pArry->next;
student->pArry->next = p;

}
else
{
while(NULL != q)
{
if((strcmp(q->course,course)==0)
&&(strlen(q->course)==strlen(course)))
{
return student;
}
q = q->next;
}
p->course = new char[len];
strcpy(p->course,course);
p->next = student->pArry->next;
student->pArry->next = p;
}
return student;


}

//
pNodeOfStudent classOfStudent::deleteCourse(char *course)
{
if(course == NULL || strlen(course)== 0)
{
return student;
}
course = strlwr(course);
int len = strlen(course);
if(len == 0)
{
return student;
}
pNodeOfCourse p = student->pArry->next;
pNodeOfCourse q = student->pArry;
while (NULL != p)
{
int ret = strcmp(p->course,course);
if(0 == ret && len == strlen(course))
{
q->next = p->next;
delete p ;
p = NULL;
}
else
{
p = p->next;
q= q->next;
}
}

}


//
void classOfStudent::showStudent()
{
cout<<student->name<<endl;
cout<<student->number<<endl;
}

//
void classOfStudent::showCourse()
{
pNodeOfCourse p = student->pArry->next;
while(p != NULL)
{
cout<<p->course<<endl;
p = p->next;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
classOfStudent *p = new classOfStudent("wangshijian",10);
p->chooseCourse("wuli");
p->chooseCourse("huaxue");
p->chooseCourse("gaoshu");
p->chooseCourse("wuli");
p->showStudent();
p->showCourse();


p->deleteCourse("haha");
p->showCourse();

p->deleteCourse("wuli");
p->showCourse();
return 0;
}

奖励园豆:5
kunkka_ | 菜鸟二级 |园豆:273 | 2012-06-03 17:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册