C语言链表实现修改成绩,C++写程序:设置类、利用线性链表实现学生成绩管理系统,学生信息包含学号、姓名、成绩1、成绩2、总分...

满意答案

02ae427d08e371d7e90d5b995e828d6d.png

z99625622

2013.04.23

02ae427d08e371d7e90d5b995e828d6d.png

采纳率:54%    等级:13

已帮助:6625人

给你个简单的例子,虽然不是你想要的,你可以把这个看懂,然后改改就可以了

// 链表e.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include

#include

#include

#include

#include

/*---------------------结构体定义部分------------------------------*/

struct Node

{

char name[10];

int score;

struct Node *next;

};

typedef struct Node ListNode;

/*---------------------函数声明部分-----------------------------------*/

ListNode* CreateNode(int n);

void PrinfListNode(ListNode *h);

void InsertList(ListNode *h,int i,char name[],int e,int n);

void DeleteList(ListNode *h,int i,int n);

void DisplayNote(void);

/*---------------------函数实现部分-----------------------------------*/

int main(int argc, char* argv[])

{

ListNode *h;

int i=1,n,score;

char name[10];

int *m=0;

cout<

while(i)

{

DisplayNote();

scanf("%d",&i);

switch(i)

{

case 1:

printf("Please input the number of the list\n");

scanf("%d",&n);

h=CreateNode(n);

printf("List elements is:\n");

PrinfListNode(h);

break;

case 2:

printf("Please input the position of the element:");

scanf("%d",&i);

printf("Please input name of the student:");

scanf("%s",&name);

printf("Please input score of the student:");

scanf("%d",&score);

InsertList(h,i,name,score,n);

printf("List elements is:\n");

PrinfListNode(h);

break;

case 3:

printf("Please input the position of the element:");

scanf("%d",&i);

DeleteList(h,i,n);

printf("List elements is:\n");

PrinfListNode(h);

break;

case 4:

printf("List elements is:\n");

PrinfListNode(h);

break;

case 0:

return 0;

break;

default:

printf("ERROR! Please try again");

}

}

return 0;

}

/*-----------------建立链表函数实现部分-----------------------------------*/

ListNode *CreateNode(int n)

{

ListNode *head;

ListNode *pre,*p;

int i;

head=(ListNode*)malloc(sizeof(ListNode));

head->next=NULL;

pre=head;

for (i=1;i<=n;i++)

{

printf("Please input name of the %d student:",i);

p=(ListNode*)malloc(sizeof(ListNode));

scanf("%s",&p->name);

printf("Please input score of the %d student:",i);

scanf("%d",&p->score);

pre->next=p;

pre=p;

}

p->next=NULL;

return head;

}

/*-----------------输出链表函数实现部分-----------------------------------*/

void PrinfListNode(ListNode *h)

{

ListNode *p;

p=h->next;

while(p)

{

printf("name:%s\tscore:%d",p->name,p->score);

p=p->next;

printf("\n");

}

}

/*-----------------插入链表函数实现部分-----------------------------------*/

void InsertList(ListNode *h,int i,char name[],int e,int n)

{

ListNode *p,*q;

int j;

if (i<1||i>n+1)

{

printf("Error ! Please input again.\n");

}

else

{

j=0;p=h;

while(j

{

p=p->next;

j++;

}

q=(ListNode *)malloc(sizeof(ListNode));

strcpy(q->name,name);

q->score=e;

q->next=p->next;

p->next=q;

}

}

/*-----------------删除链表函数实现部分-----------------------------------*/

void DeleteList(ListNode *h,int i,int n)

{

ListNode *p,*q;

int j;

char name[10];

int score;

if (i<1||i>n)

{

printf("Error ! Please input again.\n");

}

else

{

j=0;p=h;

while(j

{

p=p->next;

j++;

}

q=p->next;

p->next=q->next;

strcpy(name,q->name);

score=q->score;

free(q);

printf("name=%s,score=%d",name,score);

}

}

void DisplayNote(void)

{

printf("1--建立新的链表\n");

printf("2--添加元素\n");

printf("3--删除元素\n");

printf("4--输出当前链表中的内容\n");

printf("0--建立新的链表\n");

}

01分享举报

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值