where引导状语从句:c语言编写学生选课系统

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/03 09:29:20
c语言编写学生选课系统

小型模拟选课系统,
要求:
 用户可以用管理员和学生两种帐号登录
 以管理员帐号登录时,可以进行以下操作:添加课程(包括课程名称、学分、选课人数上限);删除课程;添加合法的学生帐号(包括学生的学号和密码)供学生选课时使用
 以学生帐号登录时,可以进行以下操作:修改自己的密码;选课;查看所有可选择的课程;查看自己已选的课程;查看某一课程的已选学生名单(考虑读写权限)
 要求系统能够自动判断某一门课程的选择人数不能超过选课人数上限;单个学生所选的学分不能超过28个学分

其它要求可以自己增加

求助高手帮忙~~~!!~~~~

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
//#include<iostream.h>
void clrscr(void)
{
system("cls");
}
char *getpass(char s[])
{
char *pass,ch;
int i;
pass=new char[100];
i=0;
pass[0]='\0';
printf("%s",s);
while(1)
{
ch=getch();
if(ch!=13)
{
printf("*");
pass[i]=ch;
i++;
pass[i]='\0';
}
else break;
}
//scanf("%s",pass);
return pass;
}
struct course
{
char name[20];
int score;
int students_limited;
course *pNext;
};

struct user
{
char name[20];
char password[17];
char coursename[20];
user *pNext;
};

int Login()
{
char key;

ST1:
clrscr();
printf("\n\n\n\n\n\n\n\t\t\tWelcome to Course System!");
printf("\n\n");
printf("\n\t\t\t1. Login with Administrator");
printf("\n\t\t\t2. Login with Users");
printf("\n\t\t\t0. Exit");
key=getch();

switch(key)
{
case '1' : return 1;
case '2' : return 2;
case '0' : return 0;
default : printf("\n\n\t\t\tInput wrong!\n\t\t\t\tPress any key to continue...");
getch();
goto ST1;
}
}

course *readcourse()
{
FILE *fp;
book *pHead,*pTemp,*pLast;

fp=fopen("coursemsg.dat","r");
if(fp==NULL)
{
printf("\n\n\t\t\tOpen course message file failed!");
return NULL;
}
pHead=NULL;
while(!feof(fp))
{
pTemp=new course;
if(fread(pTemp,sizeof(course),1,fp)!=1)
{
delete pTemp;
break;
}
if(pHead==NULL)
{
pHead=pTemp;
pLast=pTemp;
}
pLast->pNext=pTemp;
pTemp->pNext=NULL;
pLast=pTemp;
}//while
fclose(fp);
return pHead;
}

void writecoursetofile(course *pHead)
{
FILE *fp;
course *pTemp,*pNext;

fp=fopen("coursemsg.dat","w");
for(pTemp=pHead;pTemp;pTemp=pTemp->pNext)
fwrite(pTemp,sizeof(course),1,fp);
fclose(fp);
}

void Add_course()
{
course one,*p;
int i,j;
FILE *fp;

p=&one;
while(1)
{
clrscr();
printf("\n\n\n\n\n\n\n\n\t\tPlease input the name of course(-1 to end):");
//cin>>p->name;
scanf("%s",p->name);
if(!strcmp(p->name,"-1"))break;
i=0;
while(1)
{
if(p->name[i]=='\0')break;
else i++;
}
for(j=i;j<20;j++)p->name[j]='\0';
printf("\n\t\tInput it's scores:");
//cin>>p->score;
scanf("%d",&p->score);
fp=fopen("coursemsg.dat","a+");
fwrite(p,sizeof(course),1,fp);
fclose(fp);
printf("\n\n\t\tAdd course message OK!");
printf("\n\t\t\tPress any key to countinue...");
getch();
}
}

void Del_course()
{
course *pHead,*pNewHead,*pTemp,*pLast;
char name[20];

pHead=readcourse();
printf("\n\t\tPlease input the name of course to be delete:");
gets(name);

while(strcmp(pHead->name,name)==0)
{
pNewHead=pHead->pNext;
printf("\n\n\t\t--%s had been deleted" ,name);
delete pHead;
pHead=pNewHead;
}
for(pTemp=pHead,pLast=pHead;pTemp!=NULL;pLast=pTemp,pTemp=pTemp->pNext)
{
if(strcmp(pTemp->name,name)==0)
{
pLast->pNext=pTemp->pNext;
printf("\n\n\t\t--%s had been deleted" ,name);
delete pTemp;
pTemp=pLast;
}
}//for
writecoursetofile(pHead);
getch();
}

void course_Op()
{
char key;

ST3:
clrscr();
printf("\n\n\n\n\n\n\n\n\t\t\t\t1. Add Course");
printf("\n\t\t\t\t2. Delete Course");
printf("\n\t\t\t\t0. EXIT");
key=getch();
switch(key)
{
case '1' : Add_course();break;
case '2' : Del_course();break;
case '0' : goto _End;
default : printf("\n\tInput wrong!\n\tPress any key to continue...");
getch();
}
goto ST3;

_End:
;
}

void Add_user()
{
FILE *fp;
char name[20],*na,password[6],*pa;
int i,j;
user one,*p;

p=&one;
pa=password;
na=name;

while(1)
{
clrscr();
printf("\n\n\n\n\n\n\n\t\tPlease input user's name(-1 to end):");
gets(name);
if(!strcmp(name,"-1"))break;
pa=getpass("\n\t\tPlease input new password:");
strcpy(p->name,na);
strcpy(p->password,pa);
fp=fopen("usermsg.dat","ab+");
fwrite(p,sizeof(user),1,fp);
fclose(fp);
printf("\n\t\tuser's message has been saved!");
printf("\n\t\tPress any key to countinue...");
getch();
}
}
user *readcusmsg()
{
FILE *fp;
user *pHead,*pTemp,*pLast;

fp=fopen("usermsg.dat","rb");
if(fp==NULL)
{
printf("\n\nOpen user's message file failed");
return NULL;
}
pHead=NULL;

while(!feof(fp))
{
pTemp=new user;
if(fread(pTemp,sizeof(user),1,fp)!=1)
{
delete pTemp;
break;
}
if(pHead==NULL)
{
pHead=pTemp;
pLast=pTemp;
}
pLast->pNext=pTemp;
pTemp->pNext=NULL;
pLast=pTemp;
}//while
fclose(fp);
return pHead;
}

void writecusmsgtofile(user *pHead)
{
FILE *fp;
user *pTemp,*pNext;

fp=fopen("usermsg.dat","wb");
for(pTemp=pHead;pTemp;pTemp=pTemp->pNext)
fwrite(pTemp,sizeof(user),1,fp);
fclose(fp);
}

void user_Op()
{
char key;

ST4:
clrscr();
printf("\n\n\n\n\n\n\n\n\t\t\t\t1. Add Users");
printf("\n\t\t\t\t0. EXIT");
key=getch();

switch(key)
{
case '1' : Add_user();break;
case '0' : goto _End;
default : printf("\n\tInput wrong!\n\tPress any key to continue...");
getch();
}
goto ST4;

_End:;
}

void List_all_course()
{
course *pHead,*pTemp;
int Count=0,tense;

pHead=readcourse();
if(!pHead)
{
printf("\n\t(No data)");
exit(0);
}
printf("\n%30s%8s%10s","course name","Score","Tense");

for(pTemp=pHead;pTemp!=NULL;pTemp=pTemp->pNext)
{
if(pTemp->n>0)tense=1;
else tense=0;
printf("\n%30s%8d%10d",pTemp->name,pTemp->score,tense);
Count++;
if(Count%20==0){printf("Press any key to countinue...");getch();}
}
getch();
}

void Search_course_name()
{
char name[20];
int tense,k=1;
book *pHead,*pTemp,*pNext;

printf("\n\tPlease input the name of the course you want to search:");
gets(name);
pHead=readcourse();
for(pTemp=pHead;pTemp!=NULL;pTemp=pTemp->pNext)
if(!strcmp(pTemp->name,name))
{
if(pTemp->n>0)tense=1;
else tense=0;
k=0;
printf("\n%30s%8d%10d",pTemp->name,pTemp->score,tense);
}
if(k)
{
printf("\n\n\t\tThere's no course named %s",name);
printf("\n\t\t\tPress any key to countinue...");
}
getch();
}

void course_Search()
{
char key;

ST5:
clrscr();
printf("\n\n\n\n\n\n\t\t\t\t1. List all course");
printf("\n\t\t\t\t2. Search by the name of course");
printf("\n\t\t\t\t0. EXIT");
key=getch();

switch(key)
{
case '1' : List_all_course();break;
case '2' : Search_course_name();break;
case '0' : goto _End;
default : printf("\n\t\t\tInput wrong!\n\t\t\tPress any key to continue...");
getch();
}
goto ST5;

_End:;
}

void Pass(int Res)
{
FILE *fp;
char psw[17],*p,pass_in[17],user_name[20];
user *pHead,*pTemp;
int i,k=0;

clrscr();
p=pass;

if(Res==1)
{
if(!(fp=fopen("adm.psw","rb")))
{
printf("\n\n\n\n\n\n\n\t\tWelcome!\n\t******Login Administrator******");
p=getpass("\n\tPlease input your new password:");
fp=fopen("adm.psw","wb");
fprintf(fp,"%s",p);
fclose(fp);
}
else
{
fscanf(fp,"%s",pass_in);
fclose(fp);
printf("\n\n\n\n\n\n\t******Login by Administrator******");
p=getpass("\n\n\t\t\tPlease input your password:");
if(strcmp(p,pass_in))
{
printf("\n\t\tYour Password is wrong!");
printf("\n\t\tPress any key to EXIT...");
getch();
exit(0);
}//if_else
}
Adm_List();
}//if
else
{
printf("\n\n\n\n\n\n\n\n\t\t\t\tWelcome!");
printf("\n\t\t\t******Login by User******");
printf("\n\t\t\tPlease input your name:");
scanf("%s",user_name);
p=getpass("\n\t\t\tPlease input your password:");
pHead=readuser();
for(pTemp=pHead;pTemp!=NULL;pTemp=pTemp->pNext)
if(!strcmp(pTemp->name,user_name))
if(strcmp(pTemp->password,p))
{
k=1;
printf("\n\t\t\tYour password is wrong!");
printf("\n\t\t\t\tPress any key to EXIT...");
getch();
exit(0);
}//if_else
}//psw

int main()
{
int Res;

clrscr();
printf("\n\n\n\n\n\n\n\n");
printf("\n\t*****************************************************************");
printf("\n\t* courses System *");
printf("\n\t* *");
printf("\n\t* QiuYong No.20052419 *");
printf("\n\t* *");
printf("\n\t* 2006-7-20 *");
printf("\n\t*****************************************************************");
printf("\n\t\t\t\t\t\tPress any key to countinue...");
getch();

START:
Res=login();
if(Res==0)goto End;
else if(Res==3)Help();
else Psw(Res);
goto START;

End:
clrscr();
printf("\n\n\n\n\n\n\t\t\tGoodBye ^_^");
return 0;
}

我先试编一个,稍后联系!比较难!