• 大小: 24.66 KB
    文件类型: .rar
    金币: 2
    下载: 0 次
    发布日期: 2024-08-21
  • 语言: 其他
  • 标签: c++  

资源简介

完成选课基本功能(指针与链表),希望对初学者有所帮助

资源截图

代码片段和文件信息

#include “选课.h“
bool course::ifcanselect=true;
studentname* course::getstu(char *stnum)
{
studentname *ro;
ro=getroot();
if(ro)
ro=ro->next;
while(ro)
{
if(!strcmp(ro->numstnum))
break;
ro=ro->next;
}
return ro;
}
coursename* student::getcou(char *co)
{
coursename *c;
c=getroot();
if(c)
c=c->next;
while(c)
{
if(!strcmp(c->numberco))
break;
c=c->next;
}
return c;
}
void course::addstudent(char *snamechar *snumchar *smark)
{
if(root==NULL)
{
studentname *p=new studentname;
p->next=NULL;
root=p;
}
studentname *newstu=new studentname*r=root;
newstu->next=r->next;
r->next=newstu;
strcpy(newstu->stunamesname);
strcpy(newstu->numsnum);
strcpy(newstu->marksmark);
stunum++;
}
void course::delstudent(char *snum)
{
studentname *p1*p2;
p1=getroot();
p2=p1->next;
while(p2)
{
if(!strcmp(p2->numsnum))
break;
p1=p2;
p2=p2->next;
}
if(p2)
{
p1->next=p2->next;
stunum--;
delete p2;
}
else
return;
}
void student::selcourse(char *conamechar *cnumberchar *cclassnumchar *caddresschar *ctimechar *scfloat ccredit)
{
if(root==NULL)
{
coursename *p=new coursename;
        p->next=NULL;
root=p;
}
coursename *newcourse*r=root;
newcourse=new coursename;
newcourse->next=r->next;
r->next=newcourse;
strcpy(newcourse->cournameconame);
    strcpy(newcourse->numbercnumber);
strcpy(newcourse->classnumcclassnum);
strcpy(newcourse->addresscaddress);
strcpy(newcourse->timectime);
strcpy(newcourse->scoresc);
newcourse->credit=ccredit;
snum++;
totalcredit+=ccredit;
}
void student::delcourse(char *cnumber)
{
coursename *p1*p2;
p1=getroot();
p2=p1->next;
while(p2)
{
if(!strcmp(p2->numbercnumber))
break;
p1=p2;
p2=p2->next;
}
if(p2)
{
p1->next=p2->next;
snum--;
totalcredit-=p2->credit;
delete p2;
}
else
return;
}

void createstudentchain(studentchain *&sheadstudentchain *&srear)//////////////初始化产生学生链表
{
int i=0j;
char studentnumber;
char txtctxt;
    char name[20]code[10]classno[8]num[10]score[5];
char cname[20]time[20]address[15]classnum[8]number[10];
    int na=0co=0cl=0no=0;
int cna=0ti=0ad=0clnum=0nu=0sc=0;
    float credit;
    

ifstream inch1inch2inch3;
inch1.open(“student.dat“ios::in);
while(inch1.get(studentnumber))
{
if(studentnumber==‘;‘)
i++;
}
inch1.close(); ///////////////////////////////得到已有的学生数量
inch2.open(“student.dat“ios::in); 
    inch3.open(“coursename.dat“ios::in);

if(!inch3){cout<<“error“;return;}
for(j=0;j {
        studentchain *p=new studentchain;
inch2.get(txt);
while(txt!=‘‘)
{
    name[na]=txt;
    na++;
    inch2.get(txt); 
}
inch2.get(txt);
name[na]=‘\0‘;
while(txt!=‘‘)
{
num[no]=txt;
no++;
            inch2.get(txt);
}
num[no

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件         41  2009-03-27 16:58  选课\studentname.dat

     文件          1  2009-03-27 16:56  选课\whether.dat

     文件        300  2009-03-27 16:58  选课\course.dat

     文件         76  2009-03-27 16:58  选课\coursename.dat

     文件          8  2008-05-05 13:59  选课\managercode.dat

     文件        139  2009-03-27 16:58  选课\student.dat

     文件       1466  2009-03-27 16:55  选课\选课.plg

     文件        533  2009-03-26 23:12  选课\选课.dsw

     文件      82944  2009-03-27 17:01  选课\选课.ncb

     文件       1814  2009-03-27 16:10  选课\选课.cpp

     文件      11532  2009-03-27 00:04  选课\common.cpp

     文件      15428  2009-03-27 16:24  选课\Manager.cpp

     文件       5259  2009-03-27 16:55  选课\选课.h

     文件       2352  2009-03-27 16:15  选课\选课.dsp

     文件       8265  2009-03-27 16:24  选课\StudentOperation.cpp

     文件      49664  2009-03-27 17:01  选课\选课.opt

     文件       1837  2009-03-27 16:24  选课\Mainframe.cpp

     目录          0  2009-03-31 15:53  选课

----------- ---------  ---------- -----  ----

               181659                    18


评论

共有 条评论