c语言实现c语言代码课程信息包括:课程编号、课程名称、课程性质、学分、开课学期等信息,设计一个课程信息管理系统,提供以下功能: 系统以菜单方式工作。 输入记录:课程信息录入功能。 查询记录:用户可以按课程名或者课程性质进行查询。 更新记录:对课程信息进行修改、删除、插入操作。 统计记录:对学期课程总学分进行统计。 输出记录:实现对记录的存盘操作,实现将存储记录以表格的形式在屏幕上打

时间: 2024-03-12 16:44:47 浏览: 22
好的,下面是一个简单的示例代码,实现了您提供的功能: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LEN 50 // 课程名称和课程性质的最大长度 // 定义课程信息结构体 typedef struct course_info { int id; // 课程编号 char name[MAX_LEN]; // 课程名称 char property[MAX_LEN]; // 课程性质 float credit; // 学分 int semester; // 开课学期 struct course_info *next; // 指向下一个节点的指针 } CourseInfo; // 定义全局变量,表示链表的头节点 CourseInfo *head = NULL; // 函数声明 void display_menu(); void add_course_info(); void search_course_info(); void update_course_info(); void delete_course_info(); void count_credit(); void display_course_info(); int main() { int choice; do { display_menu(); scanf("%d", &choice); switch (choice) { case 1: add_course_info(); break; case 2: search_course_info(); break; case 3: update_course_info(); break; case 4: delete_course_info(); break; case 5: count_credit(); break; case 6: display_course_info(); break; case 0: printf("Bye!\n"); exit(0); default: printf("Invalid choice!\n"); } } while (1); return 0; } // 显示菜单 void display_menu() { printf("\n"); printf("Course Information Management System\n"); printf("-------------------------------------\n"); printf("1. Add Course Info\n"); printf("2. Search Course Info\n"); printf("3. Update Course Info\n"); printf("4. Delete Course Info\n"); printf("5. Count Credit\n"); printf("6. Display Course Info\n"); printf("0. Exit\n"); printf("-------------------------------------\n"); printf("Please enter your choice: "); } // 输入记录:课程信息录入功能 void add_course_info() { CourseInfo *p = (CourseInfo *) malloc(sizeof(CourseInfo)); if (p == NULL) { printf("Memory allocation failed!\n"); return; } printf("Please enter the course ID: "); scanf("%d", &(p->id)); printf("Please enter the course name: "); scanf("%s", p->name); printf("Please enter the course property: "); scanf("%s", p->property); printf("Please enter the course credit: "); scanf("%f", &(p->credit)); printf("Please enter the semester: "); scanf("%d", &(p->semester)); p->next = head; head = p; printf("Add course info successfully!\n"); } // 查询记录:用户可以按课程名或者课程性质进行查询 void search_course_info() { char keyword[MAX_LEN]; printf("Please enter the keyword: "); scanf("%s", keyword); CourseInfo *p = head; int count = 0; while (p != NULL) { if (strcmp(keyword, p->name) == 0 || strcmp(keyword, p->property) == 0) { printf("%d\t%s\t%s\t%.2f\t%d\n", p->id, p->name, p->property, p->credit, p->semester); count++; } p = p->next; } if (count == 0) { printf("No course info found!\n"); } } // 更新记录:对课程信息进行修改、删除、插入操作 void update_course_info() { int id, choice; printf("Please enter the course ID: "); scanf("%d", &id); CourseInfo *p = head; while (p != NULL) { if (p->id == id) { printf("Course Info:\n"); printf("%d\t%s\t%s\t%.2f\t%d\n", p->id, p->name, p->property, p->credit, p->semester); printf("1. Update Course Name\n"); printf("2. Update Course Property\n"); printf("3. Update Course Credit\n"); printf("4. Update Semester\n"); printf("5. Delete Course Info\n"); printf("0. Back to Menu\n"); printf("Please enter your choice: "); scanf("%d", &choice); switch (choice) { case 1: printf("Please enter the new course name: "); scanf("%s", p->name); printf("Update course name successfully!\n"); break; case 2: printf("Please enter the new course property: "); scanf("%s", p->property); printf("Update course property successfully!\n"); break; case 3: printf("Please enter the new course credit: "); scanf("%f", &(p->credit)); printf("Update course credit successfully!\n"); break; case 4: printf("Please enter the new semester: "); scanf("%d", &(p->semester)); printf("Update semester successfully!\n"); break; case 5: if (p == head) { head = head->next; } else { CourseInfo *prev = head; while (prev->next != p) { prev = prev->next; } prev->next = p->next; } free(p); printf("Delete course info successfully!\n"); break; case 0: return; default: printf("Invalid choice!\n"); } return; } p = p->next; } printf("Course info not found!\n"); } // 删除记录 void delete_course_info() { int id; printf("Please enter the course ID: "); scanf("%d", &id); CourseInfo *p = head; CourseInfo *prev = NULL; while (p != NULL) { if (p->id == id) { if (prev == NULL) { head = p->next; } else { prev->next = p->next; } free(p); printf("Delete course info successfully!\n"); return; } prev = p; p = p->next; } printf("Course info not found!\n"); } // 统计记录:对学期课程总学分进行统计 void count_credit() { int semester; float total_credit = 0; printf("Please enter the semester: "); scanf("%d", &semester); CourseInfo *p = head; while (p != NULL) { if (p->semester == semester) { total_credit += p->credit; } p = p->next; } printf("Total credit of semester %d is %.2f\n", semester, total_credit); } // 输出记录:实现对记录的存盘操作,将存储记录以表格的形式在屏幕上打印 void display_course_info() { CourseInfo *p = head; printf("ID\tName\tProperty\tCredit\tSemester\n"); while (p != NULL) { printf("%d\t%s\t%s\t%.2f\t%d\n", p->id, p->name, p->property, p->credit, p->semester); p = p->next; } } ``` 注意事项: 1. 在输入、更新、查询等操作时,需要对用户的输入进行合法性检查,防止输入错误的数据导致程序崩溃。 2. 在存档时需要将链表中的所有数据保存到文件中,以便下次程序启动时能够读取之前的数据。 3. 为了程序的易用性,可以添加用户友好的界面,让用户更方便地进行操作。

相关推荐

最新推荐

recommend-type

C语言实现学生选修课程系统设计

主要为大家详细介绍了C语言实现学生选修课程系统设计,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

C语言课程设计游戏代码.docx

本次C语言课程设计游戏为一款飞行射击类游戏,名字为飞机大战。 用EasyX实现的小游戏,作为课程设计。
recommend-type

c语言课程设计报告 会员卡计费系统源代码.docx

c语言课程设计报告 会员卡计费系统源代码,c语言课程设计报告 会员卡计费系统源
recommend-type

funcode C语言课程设计_海底世界.doc

funcode C语言课程设计_海底世界
recommend-type

C语言课程设计-电话簿管理系统

用C语言实现的简单的电话簿管理系统,其中包含完整的代码以及程序的流程框图
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

SQL怎么实现 数据透视表

SQL可以通过使用聚合函数和GROUP BY子句来实现数据透视表。 例如,假设有一个销售记录表,其中包含产品名称、销售日期、销售数量和销售额等信息。要创建一个按照产品名称、销售日期和销售额进行汇总的数据透视表,可以使用以下SQL语句: ``` SELECT ProductName, SaleDate, SUM(SaleQuantity) AS TotalQuantity, SUM(SaleAmount) AS TotalAmount FROM Sales GROUP BY ProductName, SaleDate; ``` 该语句将Sales表按照ProductName和SaleDat
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。