**学生信息管理系统链式存储的实现**

学生信息管理系统链式存储的实现
主函数头文件
main.h
#ifndef MAIN_H
#define MAIN_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include “creat_head.h”
#include “menu.h”
#include “add.h”
#include “print.h”
#include “rank.h”
#include “find.h”
#include “insert.h”
#include “delet.h”
#include “change.h”

#endif
主函数
#include “main.h”
int main()
{
int choose;
plink head = NULL;
head = creat_head();
if (head == NULL)
{
printf(“创建头节点失败\n”);
return -1;
}
printf(“创建头节点成功\n”);
while (1)
{
menu();
scanf_s("%d", &choose);
switch (choose)
{
case Add:keep_add(head);
break;
case Find:find(head);
break;
case Delete:delet(head);
break;
case Insert:keep_insert(head);
break;
case Change:change(head);
break;
case Rank:rank(head);
break;
case Print:print(head);
break;
case Exit: return 0;
default:
printf(“错误输入,请重新输入\n”);
}
}
return 0;
}
添加信息功能的头文件
add.h
#ifndef ADD_H
#define ADD_H

#include “NODE.h”
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void add(plink h); //学生管理系统的链表实现
#endif
添加信息函数
#include “add.h”
void add(plink h)//尾插法
{
int num;
plink tmp = h->next;
plink ne = NULL;
printf(“请输入学号\n”);
scanf_s("%d", &num);
while (tmp != NULL)
{
if (tmp->stu.id == num)
{
printf(“学号已存在\n”);
return;
}
tmp = tmp->next;
}
ne = (plink)malloc(sizeof(link));
ne->stu.id = num;
printf(“请输入姓名\n”);
scanf_s("%s", ne->stu.name,20);
printf(“请输入成绩\n”);
scanf_s("%f", &ne->stu.score);
ne->next = NULL;
tmp = h;
while (tmp->next != NULL)
tmp = tmp->next;
tmp->next = ne;
}
修改功能函数的头文件
#ifndef CHANGE_H_
#define CHANGE_H_

#include “NODE.h”

void change(plink head);
#endif

修改函数
#include “change.h”

#include <stdio.h>
#include <stdlib.h>

void change(plink head)
{
int num;
plink tmp = head->next;
printf(“请输入修改的学号\n”);
scanf_s("%d", &num);
while (tmp != NULL)
{
if (tmp->stu.id == num)
{

		printf("请输入姓名\n");
		scanf_s("%s", tmp->stu.name, 20);
		printf("请输入成绩\n");
		scanf_s("%f", &tmp->stu.score);
		printf("修改成功\n");
		return;
	}
	tmp = tmp->next;
}
printf("学生信息不存在\n");

}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个使用链式存储的Java学生信息管理系统的示例: ```java import java.util.Scanner; class Student { int id; String name; double score; public Student(int id, String name, double score) { this.id = id; this.name = name; this.score = score; } } class Node { Student student; Node next; public Node(Student student) { this.student = student; this.next = null; } } class StudentManagementSystem { Node head; public StudentManagementSystem() { this.head = null; } public void addStudent(Student student) { Node newNode = new Node(student); if (head == null) { head = newNode; } else { Node current = head; while (current.next != null) { current = current.next; } current.next = newNode; } } public void displayAllStudents() { Node current = head; while (current != null) { System.out.println("ID: " + current.student.id); System.out.println("Name: " + current.student.name); System.out.println("Score: " + current.student.score); System.out.println("--"); current = current.next; } } public void deleteStudent(int id) { if (head == null) { System.out.println("No students in the system."); return; } if (head.student.id == id) { head = head.next; return; } Node current = head; while (current.next != null) { if (current.next.student.id == id) { current.next = current.next.next; return; } current = current.next; } System.out.println("Student with ID " + id + " not found."); } public void modifyStudent(int id, String newName, double newScore) { Node current = head; while (current != null) { if (current.student.id == id) { current.student.name = newName; current.student.score = newScore; return; } current = current.next; } System.out.println("Student with ID " + id + " not found."); } public void searchByScore(double score) { int count = 0; Node current = head; while (current != null) { if (current.student.score == score) { System.out.println("ID: " + current.student.id); System.out.println("Name: " + current.student.name); System.out.println("Score: " + current.student.score); System.out.println("--"); count++; } current = current.next; } System.out.println("Number of students with score " + score + ": " + count); } } public class Main { public static void main(String[] args) { StudentManagementSystem system = new StudentManagementSystem(); Scanner scanner = new Scanner(System.in); while (true) { System.out.println("1. Add student"); System.out.println("2. Display all students"); System.out.println("3. Delete student"); System.out.println("4. Modify student"); System.out.println("5. Search by score"); System.out.println("6. Exit"); System.out.print("Enter your choice: "); int choice = scanner.nextInt(); if (choice == 1) { System.out.print("Enter student ID: "); int id = scanner.nextInt(); System.out.print("Enter student name: "); String name = scanner.next(); System.out.print("Enter student score: "); double score = scanner.nextDouble(); Student student = new Student(id, name, score); system.addStudent(student); System.out.println("Student added successfully."); } else if (choice == 2) { system.displayAllStudents(); } else if (choice == 3) { System.out.print("Enter student ID to delete: "); int id = scanner.nextInt(); system.deleteStudent(id); } else if (choice == 4) { System.out.print("Enter student ID to modify: "); int id = scanner.nextInt(); System.out.print("Enter new name: "); String newName = scanner.next(); System.out.print("Enter new score: "); double newScore = scanner.nextDouble(); system.modifyStudent(id, newName, newScore); } else if (choice == 5) { System.out.print("Enter score to search: "); double score = scanner.nextDouble(); system.searchByScore(score); } else if (choice == 6) { break; } else { System.out.println("Invalid choice. Please try again."); } } scanner.close(); } } ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值