网站导航营销的优势,扬州工程招标网,做网站自己买域名,公司建站 网站设计#x1f31f; 嗨#xff0c;我是LucianaiB#xff01;
#x1f30d; 总有人间一两风#xff0c;填我十万八千梦。
#x1f680; 路漫漫其修远兮#xff0c;吾将上下而求索。 C语言之高校学生信息快速查询系统的实现
目录
任务陈述与分析 问题陈述问题分析 数据结构设… 嗨我是LucianaiB 总有人间一两风填我十万八千梦。 路漫漫其修远兮吾将上下而求索。 C语言之高校学生信息快速查询系统的实现
目录
任务陈述与分析 问题陈述问题分析 数据结构设计 逻辑结构存储结构 算法设计 整体设计思路模块代码实现 运行截图与说明 主界面添加学生删除学生查询学生显示所有学生数据持久化退出系统 系统说明 编程环境数据持久化性能优化 小结
任务陈述与分析
问题陈述 在高校环境中随着学生数量的增加传统的线性搜索方法在查找效率上显得力不从心。为了提高查询效率需要设计一个能够快速响应不同查询条件的学生信息管理系统。该系统需要有效管理大量学生数据并能够根据特定的查询条件快速定位目标信息。
问题分析 设计一个高效的学生信息查询系统需要解决以下几个关键问题
数据结构选择选择合适的数据结构来存储学生信息以支持快速的增删改查操作。查询效率系统应能够快速响应各种查询请求包括但不限于按学号、姓名、学院、专业等条件的查询。用户界面提供简洁明了的用户界面使用户能够轻松进行查询和其他操作。数据持久化学生信息需要能够持久化存储即使系统重启后也能保留数据。性能优化随着数据量的增加系统性能可能会下降需要考虑性能优化措施。安全性保护学生信息的安全防止未授权访问和数据泄露。可扩展性系统设计应考虑未来可能的功能扩展如增加新的查询条件或集成新的数据源。
数据结构设计
逻辑结构 学生信息的逻辑结构通过 Student 结构体定义包含学生的基本信息和用于查询的特定信息。具体字段包括
student_id学生的唯一标识符。name学生的姓名。gender学生的性别。college学生所属的学院。major学生的专业。class_name学生所在的班级。avg_score学生的平均成绩。
typedef struct {char student_id[20];char name[50];char gender[10];char college[50];char major[50];char class_name[10];float avg_score;
} Student;存储结构 系统的存储结构由以下两个主要部分组成
students 数组用于存储所有学生的信息具有 MAX_STUDENTS 的最大容量限制。student_count 变量记录当前存储在 students 数组中的学生数量。
算法设计
整体设计思路 系统采用哈希表或平衡二叉树如 AVL 树作为底层数据结构以提高查询效率。对于更复杂的数据结构可以考虑使用关系型数据库来实现数据持久化。
模块代码实现
#include stdio.h
#include string.h
#include stdlib.h#define MAX_STUDENTS 1000Student students[MAX_STUDENTS];
int student_count 0;void searchStudentsByCollege() {char college[50];printf(Enter college to search students: );scanf(%49s, college);int found 0;for (int i 0; i student_count; i) {if (strcmp(students[i].college, college) 0) {printf(ID: %s, Name: %s, College: %s\n, students[i].student_id, students[i].name, students[i].college);found;}}if (!found) {printf(No students found in this college.\n);}
}void displayAllStudents() {for (int i 0; i student_count; i) {printf(ID: %s, Name: %s, College: %s\n, students[i].student_id, students[i].name, students[i].college);}
}void saveToFile(const char* filename) {FILE *file fopen(filename, w);if (!file) {perror(Error opening file);return;}for (int i 0; i student_count; i) {fprintf(file, ID: %s, Name: %s, College: %s\n, students[i].student_id, students[i].name, students[i].college);}fclose(file);printf(Data saved successfully.\n);
}运行截图与说明
1.主界面
2.加入
3.删除
4.查看信息
5.显示所有学生
6.保存
7.退出
系统说明
编程环境Visual Studio 2022。数据持久化使用文件系统存储学生信息。性能优化通过哈希表或平衡二叉树提高查询效率。
小结
本学生信息管理系统是一个用C语言编写的简单而实用的程序旨在帮助用户管理学生数据。系统提供了以下核心功能
添加学生用户可以输入学生的各项信息并将其存储在内存中。删除学生通过学生ID删除特定的学生记录。查询学生支持按学院名称搜索学生。显示所有学生显示所有存储在内存中的学生信息。数据持久化将学生数据保存到文件中确保数据不会因程序关闭而丢失。
尽管该系统提供了基本的 CRUD创建、读取、更新、删除操作但它还有改进的空间例如增加数据验证、错误处理机制、更复杂的查询功能以及用户友好的图形界面。
参考文献
大厂性能优化的10大顶级方案 万字图文史上最全-阿里云开发者社区通过关系型数据库实现数据持久化-应用数据持久化-ArkData方舟数据管理-应用框架数据结构教程初学者必备指南_慕课手记AI智能客服实战详解从零到一搭建系统Python语言之学生信息管理系统设计-腾讯云开发者社区-腾讯云
附录代码
#include stdio.h
#include stdlib.h
#include string.h#define MAX_MENU 100 // 定义菜单项的最大数量
#define MAX_ORDER 100 // 定义订单的最大数量// 定义菜单项结构体
typedef struct {int id; // 菜品IDchar name[50]; // 菜品名称float price; // 菜品价格
} MenuItem;// 定义订单结构体
typedef struct {int order_id; // 订单IDchar customer_phone[20]; // 顾客电话char customer_name[50]; // 顾客姓名char address[100]; // 顾客地址char order_time[20]; // 订单时间MenuItem items[MAX_MENU]; // 订单包含的菜品列表int items_count; // 订单中菜品的数量float total_amount; // 订单总金额
} Order;// 定义全局变量
MenuItem menu[MAX_MENU] {0};
Order orders[MAX_ORDER] {0};
int menu_count 0;
int order_count 0;// 函数声明
void addMenuItem(); // 添加菜单项
void modifyMenuItem(int id); // 修改菜单项
void displayMenu(); // 显示菜单
void placeOrder(); // 下订单
void cancelOrder(int order_id); // 取消订单
void searchOrderByID(int order_id); // 通过订单ID搜索订单
void searchOrderByPhone(const char *phone); // 通过电话号码搜索订单
void statistics(); // 统计信息
void applyDiscount(float *amount); // 应用折扣
void printOrder(const Order *order); // 打印订单详情
void clearOrder(Order *order); // 清除订单数据// 主函数
int main() {int choice;do {printf(\n1. 添加/修改菜单项\n2. 下订单\n3. 取消订单\n4. 搜索订单\n5. 统计信息\n6. 退出\n);printf(输入你的选择: );scanf(%d, choice);switch (choice) {case 1:addMenuItem();break;case 2:placeOrder();break;case 3:printf(输入要取消的订单ID: );scanf(%d, choice);cancelOrder(choice);break;case 4:printf(通过 (1) 订单ID 或 (2) 电话号码搜索: );scanf(%d, choice);if (choice 1) {int order_id;printf(输入订单ID: );scanf(%d, order_id);searchOrderByID(order_id);} else if (choice 2) {char phone[20];printf(输入电话号码: );scanf(%s, phone);searchOrderByPhone(phone);}break;case 5:statistics();break;case 6:printf(退出系统.\n);break;default:printf(无效选择请重新输入.\n);}} while (choice ! 6);return 0;
}// 添加菜单项
void addMenuItem() {if (menu_count MAX_MENU) {printf(菜单已满无法添加更多菜品。\n);return;}printf(输入菜品ID名称和价格: );scanf(%d %49s %f, menu[menu_count].id, menu[menu_count].name, menu[menu_count].price);menu_count;
}// 修改菜单项
void modifyMenuItem(int id) {for (int i 0; i menu_count; i) {if (menu[i].id id) {printf(输入新的名称和价格: );scanf(%49s %f, menu[i].name, menu[i].price);return;}}printf(未找到菜品。\n);
}// 显示菜单
void displayMenu() {printf(菜单:\n);for (int i 0; i menu_count; i) {printf(%d. %s - $%.2f\n, menu[i].id, menu[i].name, menu[i].price);}
}// 下订单
void placeOrder() {if (order_count MAX_ORDER) {printf(订单数量已达上限无法下新订单。\n);return;}int item_id;float total 0;orders[order_count].items_count 0;displayMenu();printf(输入顾客的电话、姓名、地址和下单时间: );scanf(%19s %49s %99s %19s, orders[order_count].customer_phone, orders[order_count].customer_name, orders[order_count].address, orders[order_count].order_time);while (1) {printf(输入菜品ID0结束: );scanf(%d, item_id);if (item_id 0) break;for (int i 0; i menu_count; i) {if (menu[i].id item_id) {if (orders[order_count].items_count MAX_MENU) {orders[order_count].items[orders[order_count].items_count] menu[i];total menu[i].price;} else {printf(一个订单中不能添加超过 %d 个菜品。\n, MAX_MENU);break;}}}}applyDiscount(total);orders[order_count].total_amount total;orders[order_count].order_id order_count 1; // 简单的订单ID生成逻辑printf(订单成功创建。订单ID: %d\n, orders[order_count].order_id);order_count;
}// 取消订单
void cancelOrder(int order_id) {for (int i 0; i order_count; i) {if (orders[i].order_id order_id) {printf(订单 %d 已取消。\n, order_id);clearOrder(orders[i]); // 清除订单数据for (int j i; j order_count - 1; j) {memcpy(orders[j], orders[j 1], sizeof(Order));}order_count--;return;}}printf(未找到订单。\n);
}// 通过订单ID搜索订单
void searchOrderByID(int order_id) {int found 0; // 用于标记是否找到订单for (int i 0; i order_count; i) {if (orders[i].order_id order_id) {printOrder(orders[i]);found 1; // 标记找到订单break;}}if (!found) {printf(没有找到订单。\n);}
}// 通过电话号码搜索订单
void searchOrderByPhone(const char *phone) {int found 0; // 用于标记是否找到订单for (int i 0; i order_count; i) {if (strcmp(orders[i].customer_phone, phone) 0) {printOrder(orders[i]);found 1; // 标记找到订单}}if (!found) {printf(没有找到该电话号码的订单。\n);}
}// 统计信息
void statistics() {// 示例统计信息 - 可以根据实际需求扩展int order_count_per_item[MAX_MENU] {0};float total_revenue 0;for (int i 0; i order_count; i) {total_revenue orders[i].total_amount;for (int j 0; j orders[i].items_count; j) {int item_id orders[i].items[j].id;order_count_per_item[item_id];}}printf(今日总收入: %.2f\n, total_revenue);for (int i 0; i menu_count; i) {if (order_count_per_item[menu[i].id] 0) {printf(%s 被订购了 %d 次。\n, menu[i].name, order_count_per_item[menu[i].id]);}}
}// 应用折扣
void applyDiscount(float *amount) {if (*amount 300) *amount * 0.85f;else if (*amount 200) *amount * 0.9f;else if (*amount 100) *amount * 0.95f;
}// 打印订单详情
void printOrder(const Order *order) {if (order NULL) {printf(订单为空。\n);return;}// 打印订单头部信息printf(订单ID: %d\n, order-order_id);printf(顾客电话: %s\n, order-customer_phone);printf(顾客姓名: %s\n, order-customer_name);printf(地址: %s\n, order-address);printf(下单时间: %s\n, order-order_time);// 检查是否有订单项if (order-items_count 0) {printf(该订单没有包含任何菜品。\n);} else {printf(订单项:\n);for (int i 0; i order-items_count; i) {// 打印每个订单项的名称和价格printf( - %s ($%.2f)\n, order-items[i].name, order-items[i].price);}}// 打印订单总金额printf(总金额: $%.2f\n, order-total_amount);
}
// 清除订单数据
void clearOrder(Order *order) {memset(order, 0, sizeof(Order));
}嗨我是[LucianaiB](https://lucianaib.blog.csdn.net/ “LucianaiB”)。如果你觉得我的分享有价值不妨通过以下方式表达你的支持 点赞来表达你的喜爱 关注以获取我的最新消息 评论与我交流你的见解。我会继续努力为你带来更多精彩和实用的内容。 点击这里[LucianaiB](https://lucianaib.blog.csdn.net/ “LucianaiB”) 获取最新动态⚡️ 让信息传递更加迅速。 文章转载自: http://www.morning.lsmgl.cn.gov.cn.lsmgl.cn http://www.morning.wknj.cn.gov.cn.wknj.cn http://www.morning.wjlkz.cn.gov.cn.wjlkz.cn http://www.morning.kpxzq.cn.gov.cn.kpxzq.cn http://www.morning.cgstn.cn.gov.cn.cgstn.cn http://www.morning.xrsqb.cn.gov.cn.xrsqb.cn http://www.morning.pmmrb.cn.gov.cn.pmmrb.cn http://www.morning.llcgz.cn.gov.cn.llcgz.cn http://www.morning.hxxwq.cn.gov.cn.hxxwq.cn http://www.morning.wkmpx.cn.gov.cn.wkmpx.cn http://www.morning.rnfwx.cn.gov.cn.rnfwx.cn http://www.morning.qkgwz.cn.gov.cn.qkgwz.cn http://www.morning.dkqr.cn.gov.cn.dkqr.cn http://www.morning.lhxrn.cn.gov.cn.lhxrn.cn http://www.morning.kqpxb.cn.gov.cn.kqpxb.cn http://www.morning.jklns.cn.gov.cn.jklns.cn http://www.morning.nwbnt.cn.gov.cn.nwbnt.cn http://www.morning.xwrhk.cn.gov.cn.xwrhk.cn http://www.morning.kxnjg.cn.gov.cn.kxnjg.cn http://www.morning.hnmbq.cn.gov.cn.hnmbq.cn http://www.morning.pwgzh.cn.gov.cn.pwgzh.cn http://www.morning.hbtarq.com.gov.cn.hbtarq.com http://www.morning.xxlz.cn.gov.cn.xxlz.cn http://www.morning.bloao.com.gov.cn.bloao.com http://www.morning.rhph.cn.gov.cn.rhph.cn http://www.morning.rqwwm.cn.gov.cn.rqwwm.cn http://www.morning.brrxz.cn.gov.cn.brrxz.cn http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn http://www.morning.ybqlb.cn.gov.cn.ybqlb.cn http://www.morning.dygqq.cn.gov.cn.dygqq.cn http://www.morning.hydkd.cn.gov.cn.hydkd.cn http://www.morning.ccphj.cn.gov.cn.ccphj.cn http://www.morning.rzjfn.cn.gov.cn.rzjfn.cn http://www.morning.hwlmy.cn.gov.cn.hwlmy.cn http://www.morning.gqtzb.cn.gov.cn.gqtzb.cn http://www.morning.hrzky.cn.gov.cn.hrzky.cn http://www.morning.ljxxl.cn.gov.cn.ljxxl.cn http://www.morning.lpcct.cn.gov.cn.lpcct.cn http://www.morning.rjrz.cn.gov.cn.rjrz.cn http://www.morning.wlfxn.cn.gov.cn.wlfxn.cn http://www.morning.trpq.cn.gov.cn.trpq.cn http://www.morning.mllmm.cn.gov.cn.mllmm.cn http://www.morning.mtbth.cn.gov.cn.mtbth.cn http://www.morning.ctsjq.cn.gov.cn.ctsjq.cn http://www.morning.yktr.cn.gov.cn.yktr.cn http://www.morning.llqch.cn.gov.cn.llqch.cn http://www.morning.ghwtn.cn.gov.cn.ghwtn.cn http://www.morning.wpcfh.cn.gov.cn.wpcfh.cn http://www.morning.qwpdl.cn.gov.cn.qwpdl.cn http://www.morning.blznh.cn.gov.cn.blznh.cn http://www.morning.ttnfc.cn.gov.cn.ttnfc.cn http://www.morning.gagapp.cn.gov.cn.gagapp.cn http://www.morning.jqmqf.cn.gov.cn.jqmqf.cn http://www.morning.jghty.cn.gov.cn.jghty.cn http://www.morning.tnfyj.cn.gov.cn.tnfyj.cn http://www.morning.mhybs.cn.gov.cn.mhybs.cn http://www.morning.fsfz.cn.gov.cn.fsfz.cn http://www.morning.ogzjf.cn.gov.cn.ogzjf.cn http://www.morning.hxpff.cn.gov.cn.hxpff.cn http://www.morning.tbcfj.cn.gov.cn.tbcfj.cn http://www.morning.fqyxb.cn.gov.cn.fqyxb.cn http://www.morning.tqxtx.cn.gov.cn.tqxtx.cn http://www.morning.cniedu.com.gov.cn.cniedu.com http://www.morning.qlrwf.cn.gov.cn.qlrwf.cn http://www.morning.nnykz.cn.gov.cn.nnykz.cn http://www.morning.zkrzb.cn.gov.cn.zkrzb.cn http://www.morning.lbssg.cn.gov.cn.lbssg.cn http://www.morning.chgmm.cn.gov.cn.chgmm.cn http://www.morning.jmbfx.cn.gov.cn.jmbfx.cn http://www.morning.rmtxp.cn.gov.cn.rmtxp.cn http://www.morning.wbns.cn.gov.cn.wbns.cn http://www.morning.cwgn.cn.gov.cn.cwgn.cn http://www.morning.mxnrl.cn.gov.cn.mxnrl.cn http://www.morning.rtsx.cn.gov.cn.rtsx.cn http://www.morning.rzbgn.cn.gov.cn.rzbgn.cn http://www.morning.rnwmp.cn.gov.cn.rnwmp.cn http://www.morning.kllzy.com.gov.cn.kllzy.com http://www.morning.wckrl.cn.gov.cn.wckrl.cn http://www.morning.mqffm.cn.gov.cn.mqffm.cn http://www.morning.bxgpy.cn.gov.cn.bxgpy.cn