数据结构(c++)课程设计(请各位大哥帮忙)

sjwsly3214 2004-12-21 12:35:12
制定教学计划
(1)根据先修课程拓扑图动态输入课程,包括(类别 课程 編号 课程名称 理论学时 试验学时。)
(2)每学期科目不得超过8个,总学时不得多于420学时,公共课必须在前两年开完
(3)按照上述要求实现教学计划的自动生成
(4)教学计划的结果按学习输出包括课程的各个属性
那位大哥用c++帮我做出来呀
...全文
263 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
sjwsly3214 2004-12-23
  • 打赏
  • 举报
回复
哪位大哥给小弟一个思路好往下编呀 帮帮忙呀

sjwsly3214 2004-12-23
  • 打赏
  • 举报
回复
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
struct COURSES
{
char course[30];
char kechengleixing[10];
float xuefen;
int xueshi;
int jiangshou;
int shiyan;
int shixi;
};
COURSES courses[50];
int term=1;
int indegree[10];
const MAX_VERTEX_NUM=30;
typedef int VertexType;
typedef struct ArcNode{
int adjvex;
struct ArcNode *nextarc;
}ArcNode;
typedef struct VNode{
VertexType data;
ArcNode *firstarc;
}VNode,AdjList[MAX_VERTEX_NUM];
typedef struct{
AdjList vertices;
int vexnum,arcnum;
}ALGraph;
struct Stack{
int *elem;
int top;
int stacksize;
};
const int STACK_INIT_SIZE=100;
const int STACKINCREMENT=10;
const int OVERFLOW=-1;
//初始化栈
void InitStack(Stack &S,int maxsize=STACK_INIT_SIZE)
{
S.elem=new int[STACK_INIT_SIZE];
if(!S.elem)exit(OVERFLOW);
S.top=-1;
S.stacksize=maxsize;
}
//压入栈
int Push(Stack &S,int e)
{
if((term+1)>4&&strcmp(courses[e].kechengleixing,"gonggong")==0){
cout<<"Shu Ru Cuo Wu"<<endl;
return 0;}
S.top++;
S.elem[S.top]=e;
}
//弹出栈
void Pop(Stack &S,int &e)
{
if(S.top==-1)cout<<"ERROR";
e=S.elem[S.top--];
}
//销毁栈
void DestoryStack(Stack &S){delete[]S.elem;}
//清空栈
void ClearStack(Stack &S){S.top=-1;}
//判空
int StackEmpty(Stack S)
{
if(S.top==-1)return 1;
else return 0;
}
void CopyStack(Stack &S1,Stack S2)
{
for(int i=0;i<=S2.top;i++)
S1.elem[i]=S2.elem[i];
S1.top=S2.top;
}
void CreateDG(ALGraph &G)
{
int j=0,v1,v2;
cout<<"Input courses:"<<endl;
cin>>courses[j].course>>courses[j].kechengleixing;
while(strcmp(courses[j].course,"#")!=0){++j;cin>>courses[j].course>>courses[j].kechengleixing;}
G.vexnum=j;
for(int i=0;i<G.vexnum;i++)
G.vertices[i].firstarc=NULL;
for(int k=0;k<G.vexnum;k++)
cout<<k+1<<":"<<courses[k].course<<" "<<courses[k].kechengleixing<<endl;
for(int h=0;h<G.vexnum;h++)
indegree[h]=0;
cout<<"Inpute the order:v1-->v2"<<endl;
cin>>v1>>v2;
while((v1>0)&&(v2>0)){
ArcNode *pi=new ArcNode;
pi->adjvex=v2-1;
pi->nextarc=G.vertices[v1-1].firstarc;
G.vertices[v1-1].firstarc=pi;
G.arcnum++;
indegree[v2-1]++;
cin>>v1>>v2;
}
}
void TopoSet(ALGraph G){
int count=0;
ArcNode *p;
Stack S1,S2;
InitStack(S1);
InitStack(S2);
for(int i=0;i<G.vexnum;i++)
if(indegree[i]==0)Push(S1,i);
cout<<term<<"TERM:"<<endl;
while((!StackEmpty(S1))||(!StackEmpty(S2))){
if((StackEmpty(S1))&&(!StackEmpty(S2))){
CopyStack(S1,S2);
ClearStack(S2);
term++;
cout<<term<<"TERM:"<<endl;
}
int v;
Pop(S1,v);++count;cout<<courses[v].course<<endl;
for(p=G.vertices[v].firstarc;p;p=p->nextarc){
int w;
w=p->adjvex;
--indegree[w];
if(!indegree[w])Push(S2,w);
}//for

}//while
if(count<G.vexnum)cout<<"THE NETWORK HAS A CYCLE"<<endl;
DestoryStack(S1);
DestoryStack(S2);
}
void main(){
ALGraph G;
CreateDG(G);
cout<<"The Tesult of a Toposet Sorting:"<<endl;
TopoSet(G);
}

我在S1中入的是入度为0的顶点证明它可在第一学期完成。在S2中入的是新产生的入度为0的
我用什么算法可以让栈S1中的公共课先输出呢???并且公共课输出后不满8科且总学时不到420时
再输出不是公共课的直到达到8科或是达到420学时为止.请各位大哥帮帮忙
drugon 2004-12-22
  • 打赏
  • 举报
回复
类是一个好方法的。

类中的变量不是也可以保存的吗?
sjwsly3214 2004-12-21
  • 打赏
  • 举报
回复
我用什么方式把个个属性存到一起呀
各位大哥帮忙呀
sjwsly3214 2004-12-21
  • 打赏
  • 举报
回复
不用栈用什么呀

谁帮我改改呀
dongyuanzhang 2004-12-21
  • 打赏
  • 举报
回复
心情能够理解,为什么要用栈呢?
sjwsly3214 2004-12-21
  • 打赏
  • 举报
回复
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
char course[30][30];
int indegree[10];
const MAX_VERTEX_NUM=30;
typedef int VertexType;
typedef struct ArcNode{
int adjvex;
struct ArcNode *nextarc;
}ArcNode;
typedef struct VNode{
VertexType data;
ArcNode *firstarc;
}VNode,AdjList[MAX_VERTEX_NUM];
typedef struct{
AdjList vertices;
int vexnum,arcnum;
}ALGraph;
struct Stack{
int *elem;
int top;
int stacksize;
};
const int STACK_INIT_SIZE=100;
const int STACKINCREMENT=10;
const int OVERFLOW=-1;
//初始化栈
void InitStack(Stack &S,int maxsize=STACK_INIT_SIZE)
{
S.elem=new int[STACK_INIT_SIZE];
if(!S.elem)exit(OVERFLOW);
S.top=-1;
S.stacksize=maxsize;
}
//压入栈
void Push(Stack &S,int e)
{
S.top++;
S.elem[S.top]=e;
}
//弹出栈
void Pop(Stack &S,int &e)
{
if(S.top==-1)cout<<"ERROR";
e=S.elem[S.top--];
}
//销毁栈
void DestoryStack(Stack &S){delete[]S.elem;}
//清空栈
void ClearStack(Stack &S){S.top=-1;}
//判空
int StackEmpty(Stack S)
{
if(S.top==-1)return 1;
else return 0;
}
void CopyStack(Stack &S1,Stack S2)
{
for(int i=0;i<=S2.top;i++)
S1.elem[i]=S2.elem[i];
S1.top=S2.top;
}
void CreateDG(ALGraph &G)
{
int j=0,v1,v2;
cin>>course[j];
while(strcmp(course[j],"#")!=0)cin>>course[++j];
G.vexnum=j;
for(int i=0;i<G.vexnum;i++)
G.vertices[i].firstarc=NULL;
for(int k=0;k<G.vexnum;k++)
cout<<k+1<<":"<<course[k]<<endl;
for(int h=0;h<G.vexnum;h++)
indegree[h]=0;
cout<<"Inpute the order:v1-->v2"<<endl;
cin>>v1>>v2;
while((v1>0)&&(v2>0)){
ArcNode *pi=new ArcNode;
pi->adjvex=v2-1;
pi->nextarc=G.vertices[v1-1].firstarc;
G.vertices[v1-1].firstarc=pi;
G.arcnum++;
indegree[v2-1]++;
cin>>v1>>v2;
}
cout<<indegree[1];
}
void TopoSet(ALGraph G){
int count=0,term=1;
ArcNode *p;
Stack S1,S2;
InitStack(S1);
InitStack(S2);
for(int i=0;i<G.vexnum;i++)
if(indegree[i]==0)Push(S1,i);
cout<<term<<"TERM:"<<endl;
while((!StackEmpty(S1))||(!StackEmpty(S2))){
if((StackEmpty(S1))&&(!StackEmpty(S2))){
CopyStack(S1,S2);
ClearStack(S2);
term++;
cout<<term<<"TERM:"<<endl;
}
int v;
Pop(S1,v);++count;cout<<course[v]<<endl;
for(p=G.vertices[v].firstarc;p;p=p->nextarc){
int w;
w=p->adjvex;
--indegree[w];
if(!indegree[w])Push(S2,w);
}//for

}//while
if(count<G.vexnum)cout<<"THE NETWORK HAS A CYCLE"<<endl;
DestoryStack(S1);
DestoryStack(S2);
}
void main(){
ALGraph G;
CreateDG(G);
cout<<"The Tesult of a Toposet Sorting:"<<endl;
TopoSet(G);
}

这是我的程序。没有那么多功能。如何把每科的属性加上呀 怎么样标记公共课呀
是在栈中加入吗
那位大哥帮我改改
sjwsly3214 2004-12-21
  • 打赏
  • 举报
回复
我想问一下如何才能使公共课在前两年开完
我应用什么方法呀
AIGPTchina 2004-12-21
  • 打赏
  • 举报
回复
多发贴!!
xuzheng318 2004-12-21
  • 打赏
  • 举报
回复
呵呵,没时间,帮楼主顶,楼主你到网上搜索一下!
pacman2000 2004-12-21
  • 打赏
  • 举报
回复
作业题向来不能靠抄别人的啊。
双杯献酒 2004-12-21
  • 打赏
  • 举报
回复
原来学校的课程是这样排出来的。
carambo 2004-12-21
  • 打赏
  • 举报
回复
这个基本上得需要你自己来写,但是不难。只有你自己写了,你才能体会数据结构和算法的精髓!
goodluckyxl 2004-12-21
  • 打赏
  • 举报
回复
THIS TOPIC SHOULD BE DELLED

IT MAKES ME UNCOMFORTALE

yevv 2004-12-21
  • 打赏
  • 举报
回复
晕倒啊

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧