C語言:學生成績管理系統(含源代碼)

一.功能

二.源代碼

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NUM 100
typedef struct
{char no[30];char name[10];char sex[10];char phone[20];float cyuyan;float computer;float datastruct;
} *student, student1;typedef struct
{student stu[MAX_NUM];int number;
} *studentDB;void read(studentDB temp)
{FILE *infile;infile = fopen("./數據.txt", "r");if (!infile){printf("文件打開失敗!");exit(0);}while (!feof(infile)){temp->stu[temp->number] = malloc(sizeof(student1));fscanf(infile, "%s %s %s %s %f %f %f", temp->stu[temp->number]->no, temp->stu[temp->number]->name, temp->stu[temp->number]->sex, temp->stu[temp->number]->phone, &(temp->stu[temp->number]->cyuyan), &(temp->stu[temp->number]->computer), &(temp->stu[temp->number]->datastruct));temp->number++;}fclose(infile);
}void write(studentDB temp)
{FILE *outfile;outfile = fopen("./數據.txt", "w");if (!outfile){printf("文件打開失敗!");exit(1);}if (temp && temp->number > 0){int i;for (i = 0; i < temp->number; i++){if (i == temp->number - 1){fprintf(outfile, "%s %s %s %s %.2f %.2f %.2f", temp->stu[i]->no, temp->stu[i]->name, temp->stu[i]->sex, temp->stu[i]->phone, temp->stu[i]->cyuyan, temp->stu[i]->computer, temp->stu[i]->datastruct);}else{fprintf(outfile, "%s %s %s %s %.2f %.2f %.2f\n", temp->stu[i]->no, temp->stu[i]->name, temp->stu[i]->sex, temp->stu[i]->phone, temp->stu[i]->cyuyan, temp->stu[i]->computer, temp->stu[i]->datastruct);}}}fclose(outfile);printf("保存成功");read(temp);
}void display(studentDB temp)
{int i;printf("|   學號   |姓名|性別|  手機號  |c語言|英語|高等數學|\n");for (i = 0; i < temp->number; i++){printf("%s %s %s %s %.2f %.2f %.2f\n", temp->stu[i]->no, temp->stu[i]->name, temp->stu[i]->sex, temp->stu[i]->phone, temp->stu[i]->cyuyan, temp->stu[i]->computer, temp->stu[i]->datastruct);}
}void menu()
{printf("\n\n\t****************************簡單學生信息管理系統*****************************\n");printf("\t*                              1.顯示學生信息                             *|\n");printf("\t*                              2.增加學生信息                             *|\n");printf("\t*                              3.刪除學生信息                             *|\n");printf("\t*                              4.修改學生信息                             *|\n");printf("\t*                              5.查詢學生信息                             *|\n");printf("\t*                              6.排序學生成績                             *|\n");printf("\t*                              7.計算學生平均成績                         *|\n");printf("\t*                              8.保存學生信息                             *|\n");printf("\t*                              9.統計全部課程及格人數                     *|\n");printf("\t*                              10.輸出總成績最高的學生信息                *|\n");printf("\t*                              0.退出系統                                 *|\n");printf("\t***************************************************************************\n");printf("請選擇你的操作并將序號輸入:");
}int countDigits(long long n)
{int count = 0;while (n > 0){n /= 10;count++;}return count;
}void insert(studentDB temp)
{char no[30];printf("請輸入要添加學生的學號:");scanf("%s", no);int n;long long num;sscanf(no, "%lld", &num);n = countDigits(num);if (n != 11){printf("輸入的學號位數有誤,請重新輸入!");return;}else{student1 stu;FILE *outfile;outfile = fopen("./數據.txt", "a");if (!outfile){printf("文件打開失敗!");exit(0);}strcpy(stu.no, no);printf("請輸入姓名:");scanf("%s", stu.name);printf("請輸入性別:");scanf("%s", stu.sex);printf("請輸入手機號:");scanf("%s", stu.phone);printf("請輸入c語言成績(帶小數點):");scanf("%f", &stu.cyuyan);printf("請輸入英語成績(帶小數點):");scanf("%f", &stu.computer);printf("請輸入高等數學成績(帶小數點):");scanf("%f", &stu.datastruct);n = fprintf(outfile, "\n%s %s %s %s %f %f %f", stu.no, stu.name, stu.sex, stu.phone, stu.cyuyan, stu.computer, stu.datastruct);printf("%s %s %s %s %.2f %.2f %.2f", stu.no, stu.name, stu.sex, stu.phone, stu.cyuyan, stu.computer, stu.datastruct);printf("學生信息已成功插入!信息長度:%d\n", n);fclose(outfile);read(temp);return;}
}void delete(studentDB temp)
{printf("請輸入要刪除的學生信息學號:");char no[15];int i, k;scanf("%s", no);printf("%s", no);for (i = 0; i < temp->number; i++){if (strcmp(temp->stu[i]->no, no) == 0){for (k = i; k < temp->number; k++){temp->stu[k] = temp->stu[k + 1];}free(temp->stu[temp->number]);temp->number--;printf("學生信息已成功刪除!\n");return;}}printf("學生學號輸入錯誤!");return;
}void modify(studentDB temp)
{printf("請輸入要修改的學生信息學號:");char no[15];int i, flag = 0;long num;scanf("%s", no);sscanf(no, "%ld", &num);for (i = 0; i < temp->number; i++){if (strcmp(no, temp->stu[i]->no) == 0){printf("\n學號:%s  姓名:%s  性別:%s  手機號:%s  c語言:%.2f  英語:%.2f  高等數學:%.2f\n\n\n", temp->stu[i]->no, temp->stu[i]->name, temp->stu[i]->sex, temp->stu[i]->phone, temp->stu[i]->cyuyan, temp->stu[i]->computer, temp->stu[i]->datastruct);printf("|1.學號|2.姓名|3.性別|4.手機號|5.c語言成績|6.英語成績|7.高等數學成績|8.不改動并返回菜單|9.依次修改全部數據\n\n\n請輸入要改動的數據項:");scanf("%d", &flag);switch (flag){case 1:printf("請輸入要修改的學號:");scanf("%s", temp->stu[i]->no);break;case 2:printf("請輸入姓名:");scanf("%s", temp->stu[i]->name);break;case 3:printf("請輸入性別:");scanf("%s", temp->stu[i]->sex);break;case 4:printf("請輸入手機號:");scanf("%s", temp->stu[i]->phone);break;case 5:printf("請輸入c語言成績(帶小數點):");scanf("%f", &(temp->stu[i]->cyuyan));break;case 6:printf("請輸入英語成績(帶小數點):");scanf("%f", &(temp->stu[i]->computer));break;case 7:printf("請輸入高等數學成績(帶小數點):");scanf("%f", &(temp->stu[i]->datastruct));break;case 8:return;case 9:printf("請輸入姓名:");scanf("%s", temp->stu[i]->name);printf("請輸入性別:");scanf("%s", temp->stu[i]->sex);printf("請輸入手機號:");scanf("%s", temp->stu[i]->phone);printf("請輸入c語言成績(帶小數點):");scanf("%f", &(temp->stu[i]->cyuyan));printf("請輸入英語成績(帶小數點):");scanf("%f", &(temp->stu[i]->computer));printf("請輸入高等數學成績(帶小數點):");scanf("%f", &(temp->stu[i]->datastruct));break;default:printf("請重新選擇!");break;}return;}}
}void search(studentDB temp)
{printf("請輸入要查詢的學生信息學號:");char no[30];int i, n;long long num;scanf("%s", no);sscanf(no, "%lld", &num);n = countDigits(num);if (n != 11){printf("輸入的學號位數有誤,請重新輸入!");return;}else{for (i = 0; i < temp->number; i++){if (strcmp(temp->stu[i]->no, no) == 0){printf("\n學號:%s  姓名:%s  性別:%s  手機號:%s  c語言:%.2f  英語:%.2f  高等數學:%.2f\n\n\n", temp->stu[i]->no, temp->stu[i]->name, temp->stu[i]->sex, temp->stu[i]->phone, temp->stu[i]->cyuyan, temp->stu[i]->computer, temp->stu[i]->datastruct);return;}}printf("學生學號輸入錯誤!");return;}
}void sort(studentDB temp)
{int i, j, n;float t;for (i = 0; i < temp->number; i++){for (j = i + 1; j < temp->number; j++){if ((temp->stu[i]->cyuyan + temp->stu[i]->computer + temp->stu[i]->datastruct) < (temp->stu[j]->cyuyan + temp->stu[j]->computer + temp->stu[j]->datastruct)){student1 *tempstu = temp->stu[i];temp->stu[i] = temp->stu[j];temp->stu[j] = tempstu;}}}printf("已按成績排序完成!\n");
}void average(studentDB temp)
{int i;float ctotal = 0, comtotal = 0, dstotal = 0;for (i = 0; i < temp->number; i++){ctotal += temp->stu[i]->cyuyan;comtotal += temp->stu[i]->computer;dstotal += temp->stu[i]->datastruct;}printf("C語言平均成績:%.2f 英語平均成績:%.2f 高等數學平均成績:%.2f\n", ctotal / temp->number, comtotal / temp->number, dstotal / temp->number);
}void passing(studentDB temp)
{int i, cpass = 0, compass = 0, dpass = 0;for (i = 0; i < temp->number; i++){if (temp->stu[i]->cyuyan >= 60){cpass++;}if (temp->stu[i]->computer >= 60){compass++;}if (temp->stu[i]->datastruct >= 60){dpass++;}}printf("C語言及格人數:%d 英語及格人數:%d 高等數學及格人數:%d\n", cpass, compass, dpass);
}void max(studentDB temp)
{int i, index = 0;float maxScore = 0;for (i = 0; i < temp->number; i++){float totalScore = temp->stu[i]->cyuyan + temp->stu[i]->computer + temp->stu[i]->datastruct;if (totalScore > maxScore){maxScore = totalScore;index = i;}}printf("學號:%s  姓名:%s  性別:%s  手機號:%s  c語言:%.2f  英語:%.2f  高等數學:%.2f 總成績:%.2f\n", temp->stu[index]->no, temp->stu[index]->name, temp->stu[index]->sex, temp->stu[index]->phone, temp->stu[index]->cyuyan, temp->stu[index]->computer, temp->stu[index]->datastruct, maxScore);
}int main()
{int select;studentDB stu = malloc(sizeof(studentDB));stu->number = 0;read(stu);do{menu();scanf("%d", &select);switch (select){case 1:display(stu);break;case 2:insert(stu);break;case 3:delete (stu);break;case 4:modify(stu);break;case 5:search(stu);break;case 6:sort(stu);break;case 7:average(stu);break;case 8:write(stu);break;case 9:passing(stu);break;case 10:max(stu);break;case 0:exit(1);}} while (1);return 0;
}

三.注意事項

(1)事先準備:?數據.txt?文件(可以含有學生信息,可以空白,但是必須有)

(2)學號為11

(3)該代碼不含有C99或者C11

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/21491.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/21491.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/21491.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

滲透測試報告生成工具

目錄 1.前言 1.1 滲透測試報告是什么? 1.2 滲透測試報告的編寫需要考慮以下幾點&#xff1a; 1.3 一份優秀的滲透測試報告應該具備以下特點&#xff1a; 1.4 在編寫滲透測試報告之前&#xff0c;需要進行一些準備工作&#xff1a; 1.5 滲透測試報告一般包括以下部分&…

作為表達式調用時,無法解析類修飾器的簽名。vue3+ts+vite,使用裝飾器時報錯

作為表達式調用時&#xff0c;無法解析類修飾器的簽名。 The runtime will invoke the decorator with 2 arguments, but the decorator expects 1.ts(1238) 頁面也無法打開 解決方案&#xff1a; {"extends": "vue/tsconfig/tsconfig.dom.json","in…

代碼隨想錄算法訓練營Day55 | 583. 兩個字符串的刪除操作 72. 編輯距離 編輯距離總結篇

代碼隨想錄算法訓練營Day55 | 583. 兩個字符串的刪除操作 72. 編輯距離 編輯距離總結篇 LeetCode 583. 兩個字符串的刪除操作 題目鏈接&#xff1a;LeetCode 583. 兩個字符串的刪除操作 思路&#xff1a; 分別刪除 class Solution { public:int minDistance(string word1, …

SEW交頻器 MDX61801110-5A3-4-0T可議價

SEW交頻器 MDX61801110-5A3-4-0T可議價 SEW交頻器 MDX61801110-5A3-4-0T可議價 SEW交頻器 MDX61801110-5A3-4-0T可議價 SEW交頻器 MDX61801110-5A3-4-0T參數表 SEW交頻器 MDX61801110-5A3-4-0T中文說明書 SEW交頻器 MDX61B01110-5A3-4-0T 規格:MOVIDRIVE MDX61B0110-5A3…

【MySQL】探索 MySQL 中的 NVL:使用 IFNULL 和 COALESCE 實現

緣分讓我們相遇亂世以外 命運卻要我們危難中相愛 也許未來遙遠在光年之外 我愿守候未知里為你等待 我沒想到為了你我能瘋狂到 山崩海嘯沒有你根本不想逃 我的大腦為了你已經瘋狂到 脈搏心跳沒有你根本不重要 &#x1f3b5; 鄧紫棋《光年之外》 什么是 NVL…

PyTorch使用tensorboard的SummaryWriter報錯

PyTorch使用tensorboard可以顯示網絡運行情況,但偶爾使用SummaryWriter時遇到Segmentation fault錯誤。 利用python3的faulthandler,可定位到出錯的代碼行,具體操作有兩種方式如下: (1) 在代碼中寫入faulthandler import faulthandler # 在import之后直接添加以下啟用代碼…

探索數據結構:便捷的雙向鏈表

&#x1f511;&#x1f511;博客主頁&#xff1a;阿客不是客 &#x1f353;&#x1f353;系列專欄&#xff1a;漸入佳境之數據結構與算法 歡迎來到泊舟小課堂 &#x1f618;博客制作不易歡迎各位&#x1f44d;點贊?收藏?關注 ?? 前言 前面我們學習了單鏈表&#xff0c;它解…

k8s常用命令(持續更新中)

1. 常用命令 # 查看命名空間下的所有pod kubectl get pod -n 命名空間 # 查看某命名空間下某個pod的日志 kubectl logs -f -n 命名空間 pod名# 查看某命名空間下某pod的詳細信息 kubectl describe pod pod名 -n 命名空間# 查看所有命名空間下pod kubectl pods --all-namespac…

等保測評核心對象概覽及實施要點

等保測評的對象主要包括以下幾個方面&#xff1a; 1. 信息系統&#xff1a;由計算機硬件、網絡和通信設備、計算機軟件、信息資源、信息用戶和規章制度組成的以處理信息流為目的的人機一體化系統。常見的信息系統包括辦公自動化系統(OA)、客戶關系管理系統、進銷存管理系統等。…

ICLR24大模型提示(3/11) | PromptAgent:利用語言模型進行戰略規劃,實現專家級提示優化

【摘要】高效的、針對特定任務的提示通常由專家精心設計&#xff0c;以整合詳細的說明和領域見解&#xff0c;這些見解基于對大型語言模型 (LLM) 的本能和目標任務的復雜性的深刻理解。然而&#xff0c;自動生成這種專家級提示仍然難以實現。現有的提示優化方法往往忽視領域知識…

20240603每日AI------------項目引入Spring Cloud Alibaba AI (二)

項目源碼解析 前端代碼&#xff1a; <div class"container"><h1>Spring Cloud Alibaba AI Example</h1><form id"form"><label for"message">User Message&#xff1a;</label><input type"text&q…

大模型PEFT(一)之推理實踐學習記錄

1. 簡介 多種模型: LLaMA、Mistral、Mixtral-MoE、Qwen、Yi、Gemmha、Baichuan、ChatGLM、Phi等等。集成方法:(增量)預訓練、指令監督微調、獎勵模型訓練、PPO訓練和DPO訓練。多種精度:32比特全參數微調、16比特凍結微調、16比特LORA微調和基于AQLM/AWQ/GPTQ/LLM.int8 的2/4/8…

一篇文章掌握Java的80%:面向對象與并發編程

Java作為一種廣泛使用的計算機編程語言&#xff0c;其強大之處在于其面向對象的特性和對并發編程的良好支持。作為一名程序員&#xff0c;我深知掌握Java的面向對象概念、集合框架、多線程與并發編程&#xff0c;以及JVM基礎對于編寫高效、可維護的代碼至關重要。本文將引導你快…

操作字符串獲取文件名字(包含類型)

記錄一種操作字符串獲取文件名字的操作方式&#xff0c;方便后期的使用。示例&#xff1a; 輸入&#xff1a;"D:/code/Test/Test.txt" 輸出&#xff1a;"Test.txt" 設計思路&#xff1a; 首先查找路徑中最后一個”/“&#xff0c;然后再通過字符串截取的…

湖南源點調研 為什么中小企業產品上市前一定要做市場調研?

本文由湖南長沙&#xff08;產品前測&#xff09;源點調研咨詢編輯發布 可能有很多企業主會表示&#xff0c;市場調研&#xff0c;產品調研&#xff0c;不都是大公司、大品牌、上市公司才會有的流程嗎&#xff0c;像我們這種小企業、小品牌、小廠家沒有必要去那么做&#xff0…

Python文本分詞工具庫-jieba

內容目錄 一、分詞二、設置分詞三、詞性信息四、關鍵詞提取 jieba庫是一個針對中文文本的分詞工具庫&#xff0c;廣泛應用于自然語言處理&#xff08;NLP&#xff09;領域的中文文本預處理階段。 主要功能: 中文分詞&#xff1a;能夠將連續的中文文本切割成有意義的詞語序列&a…

變壓器中性點接地電阻柜的出廠標準是什么

變壓器中性點接地電阻柜的出廠標準是什么&#xff1f; 現代電氣配電系統中&#xff0c;接地電阻是保障人身安全的非常重要的設施。在高壓電氣設備中&#xff0c;中性點接地電阻柜的作用是限制設備中的過電流和短路故障所產生的電流&#xff0c;以保障人身安全。變壓器中性點接…

楊輝三角形及其C語言實現

一、引言 楊輝三角形&#xff08;Pascal’s Triangle&#xff09;&#xff0c;又稱帕斯卡三角形&#xff0c;是一個在數學中經常出現的數表。它的構造規則非常簡單&#xff1a;三角形中的每個數字等于它上方兩數字之和&#xff08;或者說&#xff0c;它是位于它肩上的兩個數字…

開源VS閉源:大模型發展路徑之爭,你站哪一派?

文章目錄 引言一、數據隱私1.1開源大模型的數據隱私1.2 閉源大模型的數據隱私1.3 綜合考量 二、商業應用2.1 開源大模型的商業應用2.2 閉源大模型的商業應用2.3 商業應用的綜合考量 三、社區參與3.1 開源大模型的社區參與3.2 閉源大模型的社區參與3.3 綜合考量 結論 引言 在人…

解析“分層引流”在顱內感染治療中的價值意義

臨床中&#xff0c;化膿性顱內感染的治療一直是界內關注的重點。近年來&#xff0c;得益于醫療技術的持續革新與提升&#xff0c;顱內感染的治療方法也獲得了不斷的更新與優化。在此背景下&#xff0c;北京精誠博愛醫院所倡導的“分層引流”理念&#xff0c;作為一種新興的治療…