c语言结构体程序设计题目,一个C语言结构体编程题

满意答案

02ae427d08e371d7e90d5b995e828d6d.png

ux32517zk

2013.08.27

02ae427d08e371d7e90d5b995e828d6d.png

采纳率:42%    等级:12

已帮助:7984人

#include #include struct Student { int iNumber; char cName[20]; int iMath; int iChinese; int iEnglish; int iAverage; struct Student *pNext; }; int iCount; struct Student *Create() { char ch; struct Student *pHead = NULL; struct Student *pNew, *pEnd; pNew = pEnd = (struct Student *)malloc(sizeof(struct Student)); printf("please input the student number\n"); scanf("%d", &pNew->iNumber); printf("please input the student name\n"); scanf("%s", pNew->cName); printf("please input the student math\n"); scanf("%d", &pNew->iMath); printf("please input the student Chinese\n"); scanf("%d", &pNew->iChinese); printf("please input the student English\n"); scanf("%d", &pNew->iEnglish); printf("Continue to input information(y)otherwise(n)"); scanf("%c", &ch); if (ch == 'y') { while (pNew->iNumber != 0) { iCount++; if (iCount == 1) { pNew->pNext = NULL; pEnd = pNew; pHead = pNew; } else { pNew->pNext = NULL; pEnd->pNext = pNew; pEnd = pNew; } pNew = (struct Student *)malloc(sizeof(struct Student)); printf("please input the student number\n"); scanf("%d", &pNew->iNumber); printf("please input the student name\n"); scanf("%s", pNew->cName); printf("please input the student math\n"); scanf("%d", &pNew->iMath); printf("please input the student Chinese\n"); scanf("%d", &pNew->iChinese); printf("please input the student English\n"); scanf("%d", &pNew->iEnglish); } free(pNew); return pHead; } else { pNew->pNext = NULL; pEnd = pNew; pHead = pNew; free(pNew); return pHead; } } void Print(struct Student *pHead, iCount) { struct Student *pTemp; int iIndex = 1; pTemp = pHead; for (; iIndex <= iCount; iIndex++) { printf("the %d student", iIndex); printf("number: %d\n", pTemp->iNumber); printf("name: %s", pTemp->cName); printf("math: %d", pTemp->iMath); printf("Chinese: %d", pTemp->iChinese); printf("English: %d\n", pTemp->iEnglish); printf("\n"); pTemp = pTemp->pNext; } } Delete(struct Student *pHead, count) { int i; struct Student *pPre; struct Student *pTemp; pTemp = pHead; pPre = pTemp; for (i = 1; i < count; i++) { pPre = pTemp; pTemp = pTemp->pNext; } pPre->pNext = pTemp->pNext; free(pTemp); iCount--; } struct Student *Insert(struct Student *pHead) { struct Student *pNew; do { printf("input new student information\n"); pNew = (struct Student *)malloc(sizeof(struct Student)); printf("input new student number\n"); scanf("%d", &pNew->iNumber); printf("input new student name\n"); scanf("%s", &pNew->cName); printf("input new student math\n"); scanf("%d", &pNew->iMath); printf("input new student Chinese\n"); scanf("%d", &pNew->iChinese); printf("input new student English\n"); scanf("%d", &pNew->iEnglish); pEnd->pNext = pNew; pNew->pNext = NULL; pEnd = pNew; iCount++; } while (pNew->iNumber != 0); return pHead; } void Print_80(struct Student *pHead) { int count; struct Student *pTemp; pTemp = pHead; while (pTemp != NULL) { pTemp = pTemp->pNext; count = (pTemp->iMath + pTemp->iChinese + pTemp->iEnglish;) / 3; if (count >= 80) printf("%d ", pTemp->iNumber); /* 超过80分的学生的学号 */ } } int main() { int iMum, iDel; struct Student *pHead; printf ("create student list 1\n delete student information 2\n insert student information 3\n print more than 80 of student 4\n exit 5\n"); while (1) { scanf("%d", &iMum); switch (iMum) { case 1: pHead = Create(); break; case 2: printf("input delete student number: "); scanf("%d", &iDel); Delete(pHead, iDel); break; case 3: pHead = Insert(pHead); break; case 4: Print_80(); break; case 5: printf("exit!\n"); exit(1); default: printf("error!\n"); } } return 0; } 没调试过,不知有没有错。我是学生错了望原谅。。

12分享举报

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值