| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1007 人关注过本帖
标题:国外大一菜鸟求助~
只看楼主 加入收藏
yuanchuanjim
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-4-19
收藏
 问题点数:0 回复次数:7 
国外大一菜鸟求助~

我今年在英国读大一.以前对C语言没有研究,无奈的是我们今年有这一项科目~更无奈还是用英语学习,下面这个题是最近的一个作业,希望有兴趣C语言高手能帮忙指导一下!帮忙暂时度过此难关,菜鸟在此感激不尽...
You are required to write a database program in C. The program should store the following details for each person:

Name
Address
Telephone number
E-mail address

On start-up the program should ask the user how many sets of details you want to store, and then allocate the appropriate space to store them. The user will then be presented with a menu of options as follows:

1. Enter data
2. Edit data
3. Delete data
4. Display data
5. Save data
6. Load data
7. Quit

Select an option (1-7):

Consider the following:

When entering data the program should allow the entry of a single persons details that will be added to the current data. The user should then be questioned “Enter more details (Y/N) ?”, so that additional details can be added or the user can be returned back to the menu.

All the data that space is allocated for does not need to be entered in one go. Imagine a golf club using your software as a customer database. All the customers are not going to join at once. Therefore the first time option 1. is chosen the program should say something like “Enter the details for customer 1”, and so on as the database is filled.

The delete/edit options should deal with deleting/editing a single persons details at one time.

If the user inputs that he/she wants 20 sets of details, the program should not allow more than 20 sets to be entered. A warning that the space is full should be included in your program.

You should clearly demonstrate use of the following features or concepts within your program:

1. A menu
2. Structures
3. File handling
4. Dynamic memory allocation

Additional marks will be given if a sorting algorithm is used to sort the entered data alphabetically, based upon the name entered. This could be added as an option from the menu. Further relevant options can be added if you feel the need.

搜索更多相关主题的帖子: 国外 
2007-04-19 12:26
pinglideyu
Rank: 3Rank: 3
来 自:武汉工程大学
等 级:论坛游侠
威 望:1
帖 子:735
专家分:140
注 册:2007-1-7
收藏
得分:0 

我这有一个学生管理系统,我想你可以参考一下的。
算法应该差不多。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/********定义学生结构体********/
typedef struct Link
{
int number;
char name[10];
char sex[4];
int Chinese;
int English;
int Match;
float average;
struct Link *next;
}Student;
int amount=0;;//记录学生个数
/*****************************/
/***********初始化学生表*************/
Student *InitStudent()
{
Student *Q;
Q=(Student*)malloc(sizeof(Student));
if(Q!=NULL)
{
Q->next=NULL;
return Q;
}
else
return NULL;
}
/***********************************/
/**************创建学生数据表*********************/
int CreatStudent(Student *Q)
{
int flag,n;
Student *s;
n=0;
while(flag)
{
s=(Student*)malloc(sizeof(Student));
if(s==NULL)
{
printf("创建失败!");
return 0;
}
printf("请输入学号(输入0退回上一步):");
scanf("%d",&s->number);
if(s->number==0)
goto endp;
if(n==s->number)
{
printf("输入学号已存在!\n");
goto end;
}
while(s->number<0)
{
getchar();
printf("\n学号不能为小于零!");
printf("\n请输入学号,输入0退回上一步:");
scanf("%d",&s->number);
}
printf("请输入姓名:");
scanf("%s",s->name);
printf("请输入性别m/w:");
scanf("%s",s->sex);
printf("请输入语文成绩:");
scanf("%d",&s->Chinese);
while(s->Chinese>100||s->Chinese<0)
{
getchar();
printf("请输入语文成绩:");
scanf("%d",&s->Chinese);
}
printf("请输入数学成绩:");
scanf("%d",&s->Match);
while(s->Match>100||s->Match<0)
{
getchar();
printf("请输入数学成绩:");
scanf("%d",&s->Match);
}
printf("请输入英语成绩:");
scanf("%d",&s->English);
while(s->English>100||s->English<0)
{
getchar();
printf("请输入英语成绩:");
scanf("%d",&s->English);
}
s->average=(s->Chinese+s->English+s->Match)/3;
n=s->number;
s->next=Q->next;
Q->next=s;
amount++;
end: printf("是否继续输入数据:1/0\n");
scanf("%d",&flag);

}
endp:printf("创建完毕!\n");
printf("输入了%d个学生",amount);
return 1;
}
/******************************************/
/*********************查找学生数据,以学号为前提****************/
Student *FindStudent(Student *Q,int x)
{

Student *q;
q=Q->next;
while(q!=NULL&&q->number!=x)
q=q->next;
if(q!=NULL)
return q;
else
return NULL;
}
/******************************************************/
/**************************修改学生数据**************************/
int ModifStudent(Student *Q,int x)
{
int flag,n;
Student *q;
q=Q->next;
while(q!=NULL&&q->number!=x)
q=q->next;
if(q!=NULL)
{
while(n)
{
printf("\n修改成绩科目:1.语文 2.英语 3.数学:");
scanf("%d",&flag);
if(flag==1)
{
getchar();
printf("\n请输入语文成绩:");
scanf("%d",&q->Chinese);
while(q->Chinese>100||q->Chinese<0)
{
getchar();
printf("\n请输入语文成绩:");
scanf("%d",&q->Chinese);
}
}
else if(flag==2)
{

getchar();
printf("\n请输入数学成绩:");
scanf("%d",&q->Match);
while(q->Match>100||q->Match<0)
{
getchar();
printf("\n请重新输入数学成绩:");
scanf("%d",&q->Match);
}
}
else if(flag==3)
{
getchar();
printf("\n请输入英语成绩:");
scanf("%d",&q->English);
while(q->English>100||q->English<0)
{
printf("\n请重新英语成绩:");
scanf("%d",&q->English);
}
}
q->average=(q->Chinese+q->English+q->Match)/3;
printf("\n是否继续修改数据:1/0\n");
scanf("%d",&n);
}

return 1;
}

return 0;
}
/******************************************************/
/************************排列学生数据***********************/
Student *Sort(Student *Q,int course)
{

Student *p,*q,*t;
int number,Chinese,English,Match,score;
char name[10],sex[2];
if(Q->next==NULL)
{
printf("没有构造学生表!");
return NULL;
}
switch(course)
{
case 1:for(p=Q->next;p;p=p->next)
{
t=p;
for(q=Q->next;q;q=q->next)
{
if(t->Chinese>=q->Chinese)
{
number=t->number;
Chinese=t->Chinese;
English=t->English;
Match=t->Match;
score=t->average;
t->number=q->number;
t->Chinese=q->Chinese;
t->English=q->English;
t->Match=q->Match;
t->average=q->average;
q->number=number;
q->Chinese=Chinese;
q->English=English;
q->Match=Match;
q->average=score;
strcpy(name,t->name);
strcpy(sex,t->sex);
strcpy(t->name,q->name);
strcpy(t->sex,q->sex);
strcpy(q->name,name);
strcpy(q->sex,sex);
t=q;
}
}
}
break;
case 2:for(p=Q->next;p;p=p->next)
{
t=p;
for(q=Q->next;q;q=q->next)
{
if(t->English>=q->English)
{
number=t->number;
Chinese=t->Chinese;
English=t->English;
Match=t->Match;
score=t->average;
t->number=q->number;
t->Chinese=q->Chinese;
t->English=q->English;
t->Match=q->Match;
t->average=q->average;
q->number=number;
q->Chinese=Chinese;
q->English=English;
q->Match=Match;
q->average=score;
strcpy(name,t->name);
strcpy(sex,t->sex);
strcpy(t->name,q->name);
strcpy(t->sex,q->sex);
strcpy(q->name,name);
strcpy(q->sex,sex);
t=q;
}
}
}
break;
case 3:for(p=Q->next;p;p=p->next)
{
t=p;
for(q=Q->next;q;q=q->next)
{
if(t->Match>=q->Match)
{
number=t->number;
Chinese=t->Chinese;
English=t->English;
Match=t->Match;
score=t->average;
t->number=q->number;
t->Chinese=q->Chinese;
t->English=q->English;
t->Match=q->Match;
t->average=q->average;
q->number=number;
q->Chinese=Chinese;
q->English=English;
q->Match=Match;
q->average=score;
strcpy(name,t->name);
strcpy(sex,t->sex);
strcpy(t->name,q->name);
strcpy(t->sex,q->sex);
strcpy(q->name,name);
strcpy(q->sex,sex);
t=q;
}
}
}
break;



}
return Q;

}
int SaveStudent(Student *Q)
{
int i=0;
Student *p;
FILE *fp;
char open[20];
p=Q->next;
printf("请输入文件路径:");
scanf("%s",open);
if((fp=fopen(open,"w+"))==NULL)
{
printf("打开失败!");
return 0;
}
fprintf(fp,"|学号\t|姓名\t|性别\t|语文\t|英语\t|数学\t|均分\t|\n");

while(p!=NULL&&i<amount)
{
i++;
fwrite(p,sizeof(Student),1,fp);
p=p->next;
//fprintf(fp,"|%d\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",p->number,p->name,p->sex,p->Chinese,p->English,p->Match,p->average);
}
fclose(fp);
return 1;
}

/******************************************************************/
/************************输出学生成绩*******************************************/
void print(Student *Q)
{
Student *p;
p=Q;
if(Q->next==NULL)
printf("没有学生资料!");
else
{
printf("结果为:\n");
while(p->next!=NULL)
{
p=p->next;

printf("|学号\t|姓名\t|性别\t|语文\t|英语\t|数学\t|均分\t|\n");
printf("|%d\t|%s\t|%s\t|%d\t|%d\t|%d\t|%0.2f\t|\n",p->number,p->name,p->sex,p->Chinese,p->English,p->Match,p->average);

}
}

}
/********************************************************************************/
/********************************************************************************/
void LoadStudent()
{
int flag=1;
char FileName[20];
Student *p;
FILE *fp;
printf("请输入调出文件的路径:");
scanf("%s",FileName);
if((fp=fopen(FileName,"r+"))!=NULL)
{
fscanf(fp,"|学号\t|姓名\t|性别\t|语文\t|英语\t|数学\t|均分\t|\n");
printf("|学号\t|姓名\t|性别\t|语文\t|英语\t|数学\t|均分\t|\n");
while(flag)
{
p=(Student*)malloc(sizeof(Student));
fscanf(fp,"%d%s%s%d%d%d%d",&p->number,p->name,p->sex,&p->Chinese,&p->English,&p->Match,&p->average);
if(p->number==NULL)
flag=0;
else
{
printf("|%d\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",p->number,p->name,p->sex,p->Chinese,p->English,p->Match,p->average);
flag=1;
}
}

}
else
printf("调出失败!");
fclose(fp);

}
/***************************************菜单界面********************************/
void Menu()
{
int flag,n,sure,course;
Student *Q,*p,*L;
n=0;
Q=InitStudent();
begin:
printf("\n\t\t\t 学生管理系统(可输入汉字)\n");
printf("|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n");
printf("|1输入学生数据\t\t\t2修改学生数据\t\t\t3查找学生成绩|\n");
printf("|4排列学生数据\t\t\t5保存学生成绩\t\t\t6调出文件资料|\n");
printf("|7显示学生资料\t\t\t0结束程序 \t\t\t |\n");
printf("|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n");
printf("\n操作方式:");
scanf("%d",&flag);
switch(flag)
{
case 0:goto end;break;
case 1:CreatStudent(Q);
print(Q);
goto begin;
case 2:while(n==0)
{
printf("请输入查找学生学号:");
scanf("%d",&n);
}
sure=ModifStudent(Q,n);
if(sure==1)
printf("修改成功\n");
else
printf("修改失败\n");
n=0;
goto begin;
case 3:while(n==0)
{
printf("请输入查找学生学号:");
scanf("%d",&n);
}
p=FindStudent(Q,n);
if(p!=NULL)
{
printf("\n查询结果为:\n");
printf("|学号\t|姓名\t|性别\t|语文\t|英语\t|数学\t|均分\t|\n");
printf("|%d\t|%s\t|%s\t|%d\t|%d\t|%d\t|%d\t|\n",p->number,p->name,p->sex,p->Chinese,p->English,p->Match,p->average);
}
else
printf("查找失败\n");
n=0;
goto begin;


case 4:printf("请输入排序规则(输入0返回上一步)\n1.语文 2.英语 3.数学:");
scanf("%d",&course);
if(course==0)
goto begin;
else
{
L=Sort(Q,course);
if(L!=NULL)
print(L);
}
goto begin;
case 5:SaveStudent(Q);
goto begin;
case 6:LoadStudent();
goto begin;
case 7:print(Q);
goto begin;
}

end:printf("\n\t\t\t\t 学生管理系统\n");
printf("|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n");
printf("|1输入学生数据\t\t\t2修改学生数据\t\t\t3查找学生成绩|\n");
printf("|0退出程序\n");
printf("|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n");
}
/************************************结束*************************************/
/*****************************************************/
void main()
{
Menu();
}


~~我的明天我知道~~
2007-04-19 12:53
小墨墨
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-4-17
收藏
得分:0 
欣赏
2007-04-19 14:39
yuanchuanjim
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-4-19
收藏
得分:0 
不好意思啊~你给我的这个例子不是很明白,可不可以详细点,最好是帮我搞定他,因为我们也只有这半学期会学C语言,毕竟我的专业不是以此为主,谢谢2楼给我的帮助哈~
(这道破题占我COMPUTER MODULE的40%呢,希望高手们能帮帮我)
2007-04-19 15:00
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
二搂的很好了,基本上你改改就可以用了啊.

学习需要安静。。海盗要重新来过。。
2007-04-19 15:05
crackerwang
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:833
专家分:0
注 册:2007-2-14
收藏
得分:0 
回复:(pinglideyu)我这有一个学生管理系统,我想你...
这个姐姐好崇拜你哦
一个字---------

2007-04-19 21:55
lhhsoft
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-4-14
收藏
得分:0 
羡慕 强人

无论你在那里,我离你只有一转身的距离.
2007-04-20 09:22
ibiancheng
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2007-4-3
收藏
得分:0 

啥时候我才能到这种水平哇....哎....
路漫漫其修远兮,吾将上下而求索.......

[此贴子已经被作者于2007-4-21 11:42:31编辑过]


执著的信念,坚定的自信,勤奋的努力才是通向成功的捷径! !!
2007-04-21 11:20
快速回复:国外大一菜鸟求助~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016727 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved