求一段C语言程序代码,内容是学生信息管理系统,代码不要太长,有查询和删除就好。我是作为期末作业交的。
1个回答
展开全部
这个我c语言结构与链表的作业:
#include <stdio.h>
#include <string.h>
struct staff {
char num[6]; //学号
char name[20]; //姓名
double wage; //成绩
struct staff *next;
};
/**
*输入数据
*/
struct staff *create(int n) {
struct staff *head=NULL;
struct staff *tail,*newnode;
char num[6],name[20];
double wage;
for(int i=0;i<n;i++) {
newnode = new staff;
scanf("%s",num);
scanf("%s",name);
scanf("%lf",&wage);
strcpy(newnode->num,num);
strcpy(newnode->name,name);
newnode->wage=wage;
if(head==NULL)
head = newnode;
else
tail->next = newnode;
tail=newnode;
}
tail->next=NULL;
return(head);
}
/**
*删除数据
*/
struct staff *deln(struct staff *head,int n) {
struct staff *p,*q;
int i=0;
p=head;
while(++i!=n && p->next!=NULL) {
q=p;
p=p->next;
}
if(i==n) {
if(p==head) head=p->next;
else q->next=p->next;
delete(p);
} else
printf("Not been found!\n");
return(head);
}
/**
*显示数据
*/
void showdate(struct staff *head) {
struct staff *p=head;
int i=1;
while(p!=NULL) {
printf("%d| %s,%s,%.2f\n",i++,p->num,p->name,p->wage);
p=p->next;
}
}
void main() {
struct staff *head;
int n;
printf("请输入初始链表结点数 ");
scanf("%d",&n);
head=create(n);
printf("删除前:\n");
showdate(head);
int m=0;
while(m<1 || m>n) {
printf("请输入要删除的结点号:\n");
scanf("%d",&m);
}
head=deln(head,m);
printf("删除后:\n");
showdate(head);
}
#include <stdio.h>
#include <string.h>
struct staff {
char num[6]; //学号
char name[20]; //姓名
double wage; //成绩
struct staff *next;
};
/**
*输入数据
*/
struct staff *create(int n) {
struct staff *head=NULL;
struct staff *tail,*newnode;
char num[6],name[20];
double wage;
for(int i=0;i<n;i++) {
newnode = new staff;
scanf("%s",num);
scanf("%s",name);
scanf("%lf",&wage);
strcpy(newnode->num,num);
strcpy(newnode->name,name);
newnode->wage=wage;
if(head==NULL)
head = newnode;
else
tail->next = newnode;
tail=newnode;
}
tail->next=NULL;
return(head);
}
/**
*删除数据
*/
struct staff *deln(struct staff *head,int n) {
struct staff *p,*q;
int i=0;
p=head;
while(++i!=n && p->next!=NULL) {
q=p;
p=p->next;
}
if(i==n) {
if(p==head) head=p->next;
else q->next=p->next;
delete(p);
} else
printf("Not been found!\n");
return(head);
}
/**
*显示数据
*/
void showdate(struct staff *head) {
struct staff *p=head;
int i=1;
while(p!=NULL) {
printf("%d| %s,%s,%.2f\n",i++,p->num,p->name,p->wage);
p=p->next;
}
}
void main() {
struct staff *head;
int n;
printf("请输入初始链表结点数 ");
scanf("%d",&n);
head=create(n);
printf("删除前:\n");
showdate(head);
int m=0;
while(m<1 || m>n) {
printf("请输入要删除的结点号:\n");
scanf("%d",&m);
}
head=deln(head,m);
printf("删除后:\n");
showdate(head);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询