学生消费管理系统(C/C++)《C语言程序实践》

代码可以实现的功能:
(1)直接从终端键盘输入信息
(2)从磁盘文件录入学生信息
(3)可以查询学生消费信息
(4)可以删除学生信息
(5)可以添加学生的消费信息,并显示添加后学生的人数
(6)显示录入的学生信息
(7) 把录入的学生信息保存到指定的文件中

(喜欢的小伙伴记得分享给身边的小伙伴哦!点点赞,谢谢啦!)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN sizeof(struct scorenode)
#define DEBUG
struct scorenode                //定义结构体
{
   int number;/*学号*/
char name[10];/*姓名*/
int xiaofei;/*消费情况*/
struct scorenode *next;
};
typedef struct scorenode score;
int n,k;/*n,k为全局变量,本程序中的函数均可*p3以使用它*/
void menu();
score *creat(void);
score *load(score *head);
score *search(score *head);
score *del(score *head);
score *add(score *head,score *stu);
void print(score *head);
save(score *p1);
/*==============================================================================================*/
/*=========================创建链表,此函数带回一个指向链表头的指针=============================*/
score *creat(void)
{
   

	score *head;
    score *p1,*p2,*p3,*max;
	int i,j;
    char t[10];
	n=0;
    p1=p2=p3=(score *)malloc(LEN);/*head=p3; 开辟一个新单元*/
      printf("请输入学生信息!(以0结束)\n");
repeat1: printf("请输入学生编号(编号>0):");/*输入学号,学号应大于0*/
       scanf("%d",&p1->number);
     while(p1->number<0)
	 {
   
		 getchar();
		 printf("错误,请重新输入号码:");
         scanf("%d",&p1->number);
	 }
/*输入学号为字符或小于0时,程序报错,提示重新输入学号*/
	if(p1->number==0)
		goto end;/*当输入的学号为0时,转到末尾,结束创建链表*/
	else
	{
   
		p3=head;
		if(n>0)
		{
   
			for(i=0;i<n;i++)
			{
   
				if(p1->number!=p3->number)
					p3=p3->next;
				else
				{
   
					printf("number repeate,please input again!\n");
					goto repeat1;
     /*当输入的学号已经存在,程序报错,返回前面重新输入*/
			}
			}
		}
	 }
       printf("请输入学生姓名");
       scanf("%s",&p1->name);/*输入学生姓名*/
       printf("请输入消费情况");/*输入消费情况;*/
	 scanf("%d",&p1->xiaofei);

 while(p1->number!=0)
  {
   
    n=n+1;
 if(n==1)
  head=p1;
 else

    p2->next=p1;
    p2=p1;
    p1=(score *)malloc(LEN);
    printf("请输入学生信息(以0结束)\n");
repeat2:printf("请输入学号(学号应大于0):");
      scanf("%d",&p1->number);/*输入学号,学号应大于0*/

   while(p1->number<0)
   {
   getchar();
    printf("请重新输入学号:");
       scanf("%d",&p1->number);}
/*输入学号为字符或小于0时,程序报错,提示重新输入学号*/
  if(p1->number==0)
   goto end;/*当输入的学号为0时,转到末尾,结束创建链表*/
  else
  {
   
  p3=head;
  if(n>0)
   {
   for(i=0;i<n
  • 18
    点赞
  • 94
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
学生成绩管理系统是一个用于管理学生信息和成绩的软件。在C语言中,可以使用链表来实现学生成绩管理系统。Dev-C++是一个常用的C语言集成开发环境(IDE),可以用于编写和运行C语言程序。 以下是一个使用链表实现学生成绩管理系统的示例代码: ```c #include <stdio.h> #include <stdlib.h> // 定义学生结构体 typedef struct student { int id; char name[50]; float score; struct student* next; } Student; // 添加学生信息 void addStudent(Student** head, int id, char name[], float score) { Student* newStudent = (Student*)malloc(sizeof(Student)); newStudent->id = id; strcpy(newStudent->name, name); newStudent->score = score; newStudent->next = NULL; if (*head == NULL) { *head = newStudent; } else { Student* current = *head; while (current->next != NULL) { current = current->next; } current->next = newStudent; } } // 显示学生信息 void displayStudents(Student* head) { Student* current = head; while (current != NULL) { printf("ID: %d, Name: %s, Score: %.2f\n", current->id, current->name, current->score); current = current->next; } } int main() { Student* head = NULL; // 添加学生信息 addStudent(&head, 1, "Alice", 85.5); addStudent(&head, 2, "Bob", 92.0); addStudent(&head, 3, "Charlie", 78.5); // 显示学生信息 displayStudents(head); return 0; } ``` 这段代码实现了一个简单的学生成绩管理系统,可以添加学生信息并显示学生信息。你可以根据自己的需求进行扩展和修改。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值