成绩系统(C++版)

到百度贴吧首页
新闻   网页   贴吧   知道   MP3   图片   视频   百科
    吧内搜索 | 帮助

成绩系统(C++版)

1楼

#include <iostream.h>
#include <string.h>
#include <fstream.h>

struct student
{
char num[10];
char name[20];
int  age;
int  score;
struct student *next;
};
class grade
{
private :
struct student * head,* last;
public :
void init();
void insert();
int delete();
int select();
int modify();
int display();
int total();
void savefile();
void quit();
};
 
void grade::init()
{
printf("************************************主菜单************************************\n");
printf("\t1输入学生资料\t\t\t\t\t2删除学生资料\n");
printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n");
printf("\t5显示学生资料\t\t\t\t\t6统计学生成绩\n");
printf("\t7保存学生资料\t\t\t\t\t0退出系统\n");
printf("******************************************************************************\n");
head=last=NULL;
}

void grade::insert()
{
struct student * p;
p=(struct student *)malloc(sizeof(struct student));
cout<<"please insert num,name,age,score"<<endl;
cin>>p->num>>p->name>>p->age>>p->score;
if (head==NULL) {head=p;last=p;last->next=NULL;}
else
{
last->next=p;
last=p;
last->next=NULL;
}
}

int grade::delete()
{
char dnum;/* 要删除的学号*/
struct student * p,p1;
cout<<"请你输入要删除的学号:"<<endl;
cin>>dnum;
if (head==NULL) {cout<<"no student can be found"<<endl;return 0;}
if (head->next=NULL && strcpy(head->num,dnum)==0)/* 只有一个记录且是要删除的数据*/
{head=NULL;last=NULL;return 0;}
p=head;
while(p->next!=NULL)
{
p1=p->next;
if (strcpy(p->num,dnum)==0 && p1->next==NULL )/* 数据在到数第二的位置*/
{p->next=last;cout<<"one student has been deleted"<<endl;return 0;}
else if (p1==NULL && strcpy(p1->num,dnum)==0)/* 数据在到数第一的位置*/
  {p->next=NULL;last=p;cout<<"one student has been deleted"<<endl;return 0;}
else if (strcpy(p->num,dnum)==0 && p1->next!=NULL ) 
{p->next=p1->next;p=p1;/*p=p1;等一下次执行p=p->next;实际p已经指到p1->next了*/
cout<<"one student has been deleted"<<endl;return 0;}
p=p->next;
}
cout<<"no student can be found"<<endl;return 0;
}

int grade::select()
{
char snum;/* 要查询的学号*/
struct student * p;
cout<<"请你输入要查询的学号:"<<endl;
cin>>snum;
p=head;
while(p!=NULL)
{
if (strcpy(p->num,snum)==0)
{
cout<<"num:"<<p->num<<"\nname"<<p->name<<"\nage"<<p->age<<"\nscore"<<p->score<<endl;
return 0;
}
p=p->next;
}
cout<<"no student can be found"<<endl;return 0;
}


int grade::modify()
{
char mnum;/* 要修改的学号*/
struct student *p;
cout<<"请你输入要修改的学号:"<<endl;
cin>>mnum;
p=head;
while(p!=NULL)
{
if (strcpy(p->num,mnum)==0)
{
cout<<"please insert the new name,age,score"<<endl;
cin>>p->name>>p->age>>p->score;
cout<<"one student has been modify"<<endl;
return 0;
}
p=p->next;
}
cout<<"no student can be found"<<endl;return 0;
}

int grade::display()
{
struct student *p;
p=head;
if (head==NULL) {cout<<"no student can be found"<<endl;return 0;}
while(p!=NULL)
{
cout<<"num:"<<p->num<<"\nname"<<p->name<<"\nage"<<p->age<<"\nscore"<<p->score<<endl;
p=p->next;
}
return 0;
}


int grade::total()
{
int max,jg_num=0;
struct student *p;
p=head;
if (head==NULL) {cout<<"no student can be found"<<endl;return 0;}
max=p->score;
while(p!=NULL)
{
if (p->score>max) max=p->score;
if (p->score<60) jg++;
p=p->next;
}
cout<<"the high score:"<<max<<endl;
cout<<"不及格学生人数:"<<jg<<endl;
return 0;
}

void savefile()
{
struct student * p;
ifstream input;
input.open("student");
p=head;
while(p!=head)
{
input>>p->num>>p->name>>p->age>>p->score;
p=p->next;
}
cout<<"the file save over"<<endl;
}

int main()
{
int choice;
grade Grage;
Grade.init();
while(1)
{
cin>>choice;
switch(choice)
{
case 1:void Grade.insert(); break;
case 2:int  Grade.delete(); break;
case 3:int  Grade.select(); break;
case 4:int  Grade.modify(); break;
case 5:int  Grade.display();break;
case 6:int  Grade.total();  break;
case 7:int Grade.savefile();break;
case 0:     return 0;       
}
}
return 0;
}





2楼

被它排的好乱啊。

3楼

把空格换成&nbsp;
\t换成4个&nbsp;

4楼

哎~~~~~~~~~~~~~~

5楼

我们吧除了水帖,终于有1000了,呵呵。
220.169.49.*

6楼

有 好多错误啊!!!!!!!

7楼

我还没有运行了,所以不知道。望指出。

8楼

elva 你也有权delete水帖

10楼

有vc99在, c语言那敢有水帖啊。不需要我delete了。

11楼

haha,你还真可爱!

12楼

说真的了。

13楼

谢谢elva6041,不过好象程序有点问题啊,改了半天也没改出来,不晓得 怎么改啊??

14楼

责成elva负责到底,呵呵,

15楼

等礼拜天吧~!

16楼

#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;

struct student
{
char num[10];
char name[20];
int age;
int score;
struct student *next;
};
class grade
{
private :
struct student * head;
 
public :
void menu();
void init();
void insert();
int delete_f();
int select();
int modify();
int display();
int total();
void savefile();
void quit();
};

 
void grade::init()
{
cout<<"************************************主菜单************************************\n";
cout<<"\t1输入学生资料\t\t\t\t\t2删除学生资料\n";
cout<<"\t3查询学生资料\t\t\t\t\t4修改学生资料\n";
cout<<"\t5显示学生资料\t\t\t\t\t6统计学生成绩\n";
cout<<"\t7保存学生资料\t\t\t\t\t0退出系统\n";
cout<<"******************************************************************************\n";
head=NULL;
}

void grade::menu()
{
cout<<"************************************主菜单************************************\n";
cout<<"\t1输入学生资料\t\t\t\t\t2删除学生资料\n";
cout<<"\t3查询学生资料\t\t\t\t\t4修改学生资料\n";
cout<<"\t5显示学生资料\t\t\t\t\t6统计学生成绩\n";
cout<<"\t7保存学生资料\t\t\t\t\t0退出系统\n";
cout<<"******************************************************************************\n";
}

void grade::insert()
{
struct student * p,*p1;
p=(struct student *)malloc(sizeof(struct student));
cout<<"please insert num,name,age,score"<<endl;
cin>>p->num>>p->name>>p->age>>p->score;
if (head==NULL) {head=p;head->next=NULL;}
else
{
p1=head;
while(p1->next!=NULL)
p1=p1->next;
p1->next=p;
p->next=NULL;
}
}

int grade::delete_f()
{
char dnum[10];/* 要删除的学号*/
struct student *p,*p1;
cout<<"请你输入要删除的学号:"<<endl;
cin>>dnum;
if (head==NULL) {cout<<"no student can be found"<<endl;return 0;}
if (head->next==NULL && strcmp(dnum,head->num)==0)
 {head=NULL;cout<<"one student has been deleted"<<endl;return 0;}
 /* 只有一个记录且是要删除的数据*/
p=head;
while (p->next!=NULL)
{
p1=p->next;
if (strcmp(dnum,head->num)==0) 
{head=head->next;cout<<"one student has been deleted"<<endl;return 0;}
/* 要删除的数据在文件头*/
if (strcmp(dnum,p1->num)==0) 
{p->next=p1->next;cout<<"one student has been deleted"<<endl;return 0;}
p=p->next;
}
cout<<"no student can be found"<<endl;return 0;
}

int grade::select()
{
char snum[10];/* 要查询的学号*/
struct student * p;
cout<<"请你输入要查询的学号:"<<endl;
cin>>snum;
p=head;
while(p!=NULL)
{
if (strcmp(p->num,snum)==0)
{
cout<<"num: "<<p->num<<"\nname: "<<p->name<<"\nage: "<<p->age<<"\nscore: "<<p->score<<endl;
return 0;
}
p=p->next;
}
cout<<"no student can be found"<<endl;return 0;
}

int grade::modify()
{
char mnum[10];/* 要修改的学号*/
struct student *p;
cout<<"请你输入要修改的学号:"<<endl;
cin>>mnum;
p=head;
while(p!=NULL)
{
if (strcmp(p->num,mnum)==0)
{
cout<<"please insert the new name,age,score"<<endl;
cin>>p->name>>p->age>>p->score;
cout<<"one student has been modified"<<endl;
return 0;
}
p=p->next;
}
cout<<"no student can be found"<<endl;return 0;
}

int grade::display()
{
struct student *p;
p=head;
if (head==NULL) {cout<<"no student can be displayed"<<endl;return 0;}
while(p!=NULL)
{
cout<<"num: "<<p->num<<"\nname: "<<p->name<<"\nage: "<<p->age<<"\nscore: "<<p->score<<endl;
p=p->next;
cout<<endl;
}
return 0;
}

int grade::total()
{
int max,jg=0;
struct student *p;
p=head;
if (head==NULL) {cout<<"no student can be found"<<endl;return 0;}
max=p->score;
while(p!=NULL)
{
if (p->score>max) max=p->score;
if (p->score<60) jg++;
p=p->next;
}
cout<<"the high score:"<<max<<endl;
cout<<"不及格学生人数:"<<jg<<endl;
return 0;
}

void grade::savefile()
{
struct student * p;
ifstream input;
input.open("student");
p=head;
while(p!=head)
{
input>>p->num>>p->name>>p->age>>p->score;
p=p->next;
}
cout<<"the file save over"<<endl;
}

int main()
{
int choice;
grade Grade;
Grade.init();
while(1)
{
cin>>choice;
switch(choice)
{
case 1: Grade.insert(); break;
case 2: Grade.delete_f(); break;
case 3: Grade.select(); break;
case 4: Grade.modify(); break;
case 5: Grade.display();break;
case 6: Grade.total(); break;
case 7: Grade.savefile();break;
case 0: return 0; 
}
Grade.menu(); 
}
return 0;
}

17楼

我在dev-cpp中运行了,没有发现错误。
哪个C++中文件操作我不会,assiss能不能讲一下。

18楼

我也改了一下,不过还有一点点小错误(执行完一个操作后不能继续运行)
#include <iostream.h>
#include <string.h>
#include <fstream.h>

struct student
{
char num[10];
char name[20];
int age;
int score;
struct student *next;
};
class grade
{
private :
struct student * head,* last; 
public :
void init();
void insert();
int delet();
int select();
int modify();
int display();
int total();
void savefile();
void quit();
};
 
void grade::init()
{
cout<<"************************************主菜单************************************\n"<<endl;
cout<<"\t1输入学生资料\t\t\t\t\t2删除学生资料\n"<<endl;
cout<<"\t3查询学生资料\t\t\t\t\t4修改学生资料\n"<<endl;
cout<<"\t5显示学生资料\t\t\t\t\t6统计学生成绩\n"<<endl;
cout<<"\t7保存学生资料\t\t\t\t\t0退出系统\n"<<endl;
cout<<"******************************************************************************\n"<<endl;
head=last=NULL;
}

void grade::insert()
{
struct student * p;
//p=(struct student *)malloc(sizeof(struct student));
p = new student;
cout<<"please insert num,name,age,score"<<endl;
cin>>p->num>>p->name>>p->age>>p->score;
if (head==NULL) {head=p;last=p;last->next=NULL;}
else
{
last->next=p;
last=p;
last->next=NULL;
}
}

int grade::delet()
{
char* dnum ;/* 要删除的学号*/
struct student * p, *p1;
cout<<"请你输入要删除的学号:"<<endl;
cin>>dnum;
if (head==NULL) {cout<<"no student can be found"<<endl;return 0;}
if (head->next=NULL && strcpy(head->num,dnum)==0)/* 只有一个记录且是要删除的数据*/
{head=NULL;last=NULL;return 0;}
p=head;
while(p->next!=NULL)
{
p1=p->next;
if (strcpy(p->num,dnum)==0 && p1->next==NULL )/* 数据在到数第二的位置*/
{p->next=last;cout<<"one student has been deleted"<<endl;return 0;}
else if (p1==NULL && strcpy(p1->num,dnum)==0)/* 数据在到数第一的位置*/
 {p->next=NULL;last=p;cout<<"one student has been deleted"<<endl;return 0;}
else if (strcpy(p->num,dnum)==0 && p1->next!=NULL ) 
{p->next=p1->next;p=p1;/*p=p1;等一下次执行p=p->next;实际p已经指到p1->next了*/
cout<<"one student has been deleted"<<endl;return 0;}
p=p->next;
}
cout<<"no student can be found"<<endl;return 0;
}

int grade::select()
{
char* snum;/* 要查询的学号*/
struct student * p;
cout<<"请你输入要查询的学号:"<<endl;
cin>>snum;
p=head;
while(p!=NULL)
{
if (strcpy(p->num,snum)==0)
{
cout<<"num:"<<p->num<<"\nname"<<p->name<<"\nage"<<p->age<<"\nscore"<<p->score<<endl;
return 0;
}
p=p->next;
}
cout<<"no student can be found"<<endl;return 0;
}

int grade::modify()
{
char* mnum;/* 要修改的学号*/
struct student *p;
cout<<"请你输入要修改的学号:"<<endl;
cin>>mnum;
p=head;
while(p!=NULL)
{
if (strcpy(p->num,mnum)==0)
{
cout<<"please insert the new name,age,score"<<endl;
cin>>p->name>>p->age>>p->score;
cout<<"one student has been modify"<<endl;
return 0;
}
p=p->next;
}
cout<<"no student can be found"<<endl;return 0;
}

int grade::display()
{
struct student *p;
p=head;
if (head==NULL) {cout<<"no student can be found"<<endl;return 0;}
while(p!=NULL)
{
cout<<"num:"<<p->num<<"\nname"<<p->name<<"\nage"<<p->age<<"\nscore"<<p->score<<endl;
p=p->next;
}
return 0;
}

int grade::total()
{
int max,jg_num=0;
struct student *p;
p=head;
if (head==NULL) {cout<<"no student can be found"<<endl;return 0;}
max=p->score;
while(p!=NULL)
{
if (p->score>max) max=p->score;
if (p->score<60) jg_num++;
p=p->next;
}
cout<<"the high score:"<<max<<endl;
cout<<"不及格学生人数:"<<jg_num<<endl;
return 0;
}

void grade::savefile()
{
struct student * p;
ifstream input;
input.open("student");
p=head;
while(p!=head)
{
input>>p->num>>p->name>>p->age>>p->score;
p=p->next; 
}
cout<<"the file save over"<<endl;
}

int main()
{
int choice;
grade Grade;
Grade.init();
while(1)
{
cin>>choice;
switch(choice)
{
case 1:
Grade.insert(); 

break;
case 2:
Grade.delet(); 
break;
case 3:
Grade.select(); 
break;
case 4:
Grade.modify(); 
break;
case 5:
Grade.display();
break;
case 6:Grade.total(); 
break;
case 7:
Grade.savefile();
break;
case 0: 
return 0; 
}
}
return 0;
}

19楼

以前的哪个很多错误了。

20楼

以前我用了
last,head两个指针,结果发现很难用。所以现在只用head一个。
还有strcpy(p->num,mnum)==0)这个记错了,应该是strcmp(),这个才是比较两个字符的函数。
还有 char mnum;改为了char mnum[10];
主要是这几个了。

21楼

elva6401 ,你看了我改过的程序了吗??为什么在完成一个操作的时候不能执行下一个操作
慕容

22楼

strcpy(p->num,mnum)==0)你没有改很大的错误,
还有你把char mnum;改为char * mnum行吗,我也不知道.
你还是仔细看一下我的程序了,如果还有问题,加我QQ吧 303890400

218.7.49.*

23楼

你们都很强啊真的
我学的时候走要累死了

211.69.2.*

24楼

真厉害 第一个有错误
后面的还不错

25楼

我有个问题想请教大家一下 谁能帮我写一个
运动会成绩管理
成绩录入
成绩查询
按项目排名
按系排名
要求
(1) 成绩数据应包括系名、姓名、学号、项目名称、成绩等并保存到某文件中
(2) 采用模块化程序设计方法,主函数用菜单形式调用各功能函数,程序可读性强,界面设计友好,输出形式美观
需求分析
程序框图(总体框图和个功能模块框图,使用结构化流程图或N-S流程图)

的程序啊 
谢谢了 我后天就要交了是课程设计 我原来就挂了好多了不能再挂了希望打击啊帮一下 真的感谢大家了

218.58.61.*

26楼

什么C 语言啊 ,看不懂
218.25.56.*

27楼

郁闷1984:我也是这个课题 我也不会  
218.57.64.*

28楼

在键盘上输入正整数和求出和之间的所有的回文素数并按每行五个整数输出来
我是初学者希望好心的人帮我尽快的作出来
谢谢!!!!

218.57.64.*

29楼

好心的人快一点吧我在等着呀

30楼

哈哈,不错
61.132.1.*

31楼

我是第一次做课程设计,大家多多指教啊!

发表回复

内 容:
用户名:
  
©2010 Baidu 贴吧协议  意见反馈