最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C語言實(shí)現(xiàn)簡(jiǎn)單班級(jí)成績(jī)管理系統(tǒng)

 更新時(shí)間:2022年03月01日 11:24:16   作者:和諧創(chuàng)新  
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)簡(jiǎn)單班級(jí)成績(jī)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

前言:

有朋友最近在做c語言課設(shè),要求寫一個(gè)班級(jí)成績(jī)管理系統(tǒng),便寫份簡(jiǎn)單的代碼來玩。代碼原創(chuàng),未參考任何其他人的代碼

程序要求

說明

  • 本程序主要采用結(jié)構(gòu)體數(shù)組
  • 本文件采用多文件編寫,由于程序規(guī)模小,故未采用編寫頭文件的方式
  • 使用 #pragma once 來防止頭文件重復(fù)包含

代碼

怎么使用本程序看看注釋應(yīng)該就知道了。run main.c 就行。其他各文件作用:

  • def.c 定義了一些常量和全局變量,結(jié)構(gòu)體
  • myIO.c 實(shí)現(xiàn)了成績(jī)錄入和成績(jī)打印輸出
  • file.c 實(shí)現(xiàn)了將成績(jī)保存為文件
  • menu.c 實(shí)現(xiàn)了菜單功能
  • function.c 包含其他一些要用的函數(shù)

main.c

#include "menu.c"

int main()
{
? ? select();
? ? return 0;
}

def.c

// 相同頭文件只包含一次,后不贅述
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define Status int

// 課程
typedef struct Course
{
? ? char name[30];
? ? int score;
} Course, *pCourse;

// 學(xué)生
typedef struct Student
{
? ? char number[30];
? ? char name[30];
? ? pCourse pC;
} Student, *pStudent;

// n是學(xué)生數(shù), m是課程數(shù)
int n, m;
char courseName[30], studentName[30], course[20][30];
pStudent pS = NULL;

myIO.c

#pragma once
#include "def.c"

pStudent inputStudentInfo(void);
void printStudentInfo(pStudent pS);

// 錄入學(xué)生信息
pStudent inputStudentInfo(void)
{
? ? int i, j;
? ? printf("Please input the number of students and courses: ");
? ? scanf("%d %d", &n, &m);
? ? printf("Please input the name of courses: ");
? ? for (i = 0; i < m; i++)
? ? {
? ? ? ? scanf("%s", course[i]);
? ? }
? ? pStudent pS = (pStudent)malloc(sizeof(Student) * n);
? ? if (!pS)
? ? ? ? return NULL;
? ? printf("Please input the info: \n");
? ? for (i = 0; i < n; i++)
? ? {
? ? ? ? pS[i].pC = (pCourse)malloc(sizeof(Course) * m);
? ? ? ? if (!pS[i].pC)
? ? ? ? ? ? return NULL;
? ? ? ? scanf("%s %s", pS[i].name, pS[i].number);
? ? ? ? for (j = 0; j < m; j++)
? ? ? ? {
? ? ? ? ? ? strcpy(pS[i].pC[j].name, course[j]);
? ? ? ? ? ? scanf("%d", &pS[i].pC[j].score);
? ? ? ? }
? ? }
? ? return pS;
}

// 打印所有學(xué)生信息
void printStudentInfo(pStudent pS)
{
? ? int i, j;
? ? // 打印標(biāo)題
? ? printf("Name\tnumber\t");
? ? for (i = 0; i < m - 1; i++)
? ? ? ? printf("%s\t", course[i]);
? ? printf("%s\n", course[i]);
? ? // 顯示信息
? ? for (i = 0; i < n; i++)
? ? {
? ? ? ? printf("%s\t%s\t", pS[i].name, pS[i].number);
? ? ? ? for (j = 0; j < m - 1; j++)
? ? ? ? ? ? printf("%d\t", pS[i].pC[j].score);
? ? ? ? printf("%d\n", pS[i].pC[j].score);
? ? }
}

file.c

#pragma once
#include "def.c"
Status saveStudentInfo(pStudent pS);
Status saveStudentInfo(pStudent pS)
{
? ? FILE *fp;
? ? int i, j;
? ? char filename[30], str[100] = "student number";
? ? printf("please input the filename: ");
? ? scanf("%s", filename);
? ? fp = fopen(filename, "w");
? ? if (!fp)
? ? ? ? return ERROR;
? ? for (i = 0; i < m; i++)
? ? {
? ? ? ? strcat(str, " ");
? ? ? ? strcat(str, course[i]);
? ? }
? ? strcat(str, "\n");
? ? for (i = 0; i < n; i++)
? ? {
? ? ? ? strcat(str, pS[i].name);
? ? ? ? strcat(str, " ");
? ? ? ? strcat(str, pS[i].number);
? ? ? ? for (j = 0; j < m; j++)
? ? ? ? {
? ? ? ? ? ? char score[30];
? ? ? ? ? ? itoa(pS[i].pC[j].score, score, 10);
? ? ? ? ? ? strcat(str, " ");
? ? ? ? ? ? strcat(str, score);
? ? ? ? }
? ? ? ? strcat(str, "\n");
? ? }
? ? fputs(str, fp);
? ? fclose(fp);
? ? return OK;
}

menu.c

#pragma once
#include "def.c"
#include "myIO.c"
#include "file.c"
#include "function.c"
void menu();
void select();
// 菜單
void menu()
{
? ? printf("------------------------------------\n");
? ? printf("| ? ? ? ? ? ? ? ?Menu ? ? ? ? ? ? ?|\n");
? ? printf("| ? ? ? ? ? ? ?1. input ? ? ? ? ? ?|\n");
? ? printf("| ? ? ? ? ? ? ?2. show ? ? ? ? ? ? |\n");
? ? printf("| ? ? ? ? ? ? ?3. save ? ? ? ? ? ? |\n");
? ? printf("| ? ? ? ? ? ? ?4. sort ? ? ? ? ? ? |\n");
? ? printf("| ? ? ? ? ? ? ?5. modify ? ? ? ? ? |\n");
? ? printf("| ? ? ? ? ? ? ?6. count ? ? ? ? ? ?|\n");
? ? printf("| ? ? ? ? ? ? ?0. exit ? ? ? ? ? ? |\n");
? ? printf("------------------------------------\n");
}

void select()
{
? ? int branch;
? ? while (TRUE)
? ? {
? ? ? ? system("cls");
? ? ? ? menu();
? ? ? ? printf("[Input]: ");
? ? ? ? scanf("%d", &branch);
? ? ? ? if (!branch)
? ? ? ? ? ? break;
? ? ? ? switch (branch)
? ? ? ? {
? ? ? ? case 1:
? ? ? ? {
? ? ? ? ? ? pS = inputStudentInfo();
? ? ? ? ? ? if (pS == NULL)
? ? ? ? ? ? ? ? printf("input error! please input again\n");
? ? ? ? ? ? else
? ? ? ? ? ? ? ? printf("Input success!\n");
? ? ? ? ? ? system("pause");
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 2:
? ? ? ? {
? ? ? ? ? ? printStudentInfo(pS);
? ? ? ? ? ? system("pause");
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 3:
? ? ? ? {
? ? ? ? ? ? if (OK == saveStudentInfo(pS))
? ? ? ? ? ? ? ? printf("Save success!\n");
? ? ? ? ? ? else
? ? ? ? ? ? ? ? printf("Save fail!\n");
? ? ? ? ? ? system("pause");
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 4:
? ? ? ? {
? ? ? ? ? ? sort(pS);
? ? ? ? ? ? printf("sort success\n");
? ? ? ? ? ? system("pause");
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 5:
? ? ? ? {
? ? ? ? ? ? int res = modify(pS);
? ? ? ? ? ? if (res)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? printf("change success!\n");
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? printf("change fail!\n");
? ? ? ? ? ? }
? ? ? ? ? ? system("pause");
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? case 6:
? ? ? ? {
? ? ? ? ? ? int choose;
? ? ? ? ? ? // 輸入1 顯示每門課程最高成績(jī)信息
? ? ? ? ? ? // 輸入2 顯示每門課程平均成績(jī)信息
? ? ? ? ? ? printf("choose 1 for the highest score: \n ");
? ? ? ? ? ? printf("choose 2 for the average score: \n");
? ? ? ? ? ? printf("[Input]: ");
? ? ? ? ? ? scanf("%d", &choose);
? ? ? ? ? ? if (choose == 1)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? showMax(pS);
? ? ? ? ? ? }
? ? ? ? ? ? else if (choose == 2)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? showAverage(pS);
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? // 輸入非法提示信息
? ? ? ? ? ? ? ? printf("Input error!\n");
? ? ? ? ? ? }
? ? ? ? ? ? system("pause");
? ? ? ? ? ? break;
? ? ? ? }
? ? ? ? }
? ? }
}

function.c

#include "def.c"

void sort(pStudent pS);
void Swap(pStudent s1, pStudent s2);
void showAverage(pStudent pS);
void showMax(pStudent pS);
Status modify(pStudent pS);

// 按課程成績(jī)排序
void sort(pStudent pS)
{
? ? int courseNumber, i, j, k;
? ? char courseName[30];
? ? printf("please input the course name which you want to sort: ");
? ? scanf("%s", courseName);
? ? for (courseNumber = 0; courseNumber < m; courseNumber++)
? ? ? ? if (strcmp(course[courseNumber], courseName) == 0)
? ? ? ? ? ? break;
? ? // 如果找不到課程,則認(rèn)為是按總分排序
? ? if (courseNumber == m)
? ? {
? ? ? ? printf("Sort as total score: \n");
? ? ? ? // 選擇排序
? ? ? ? for (i = 0; i < n - 1; i++)
? ? ? ? {
? ? ? ? ? ? int flag = i;
? ? ? ? ? ? for (j = i + 1; j < n; j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int totalScore_1 = 0, totalScore_2 = 0;
? ? ? ? ? ? ? ? for (k = 0; k < m; k++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? totalScore_1 += pS[j].pC[k].score;
? ? ? ? ? ? ? ? ? ? totalScore_2 += pS[flag].pC[k].score;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (totalScore_1 > totalScore_2)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? flag = j;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Swap(&pS[i], &pS[flag]);
? ? ? ? }
? ? }
? ? else
? ? {
? ? ? ? // 選擇排序
? ? ? ? for (i = 0; i < n - 1; i++)
? ? ? ? {
? ? ? ? ? ? int flag = i;
? ? ? ? ? ? for (j = i + 1; j < n; j++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (pS[j].pC[courseNumber].score > pS[flag].pC[courseNumber].score)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? flag = j;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? Swap(&pS[i], &pS[flag]);
? ? ? ? }
? ? }
}

// 修改學(xué)生信息
Status modify(pStudent pS)
{
? ? // 密碼是1314
? ? char password[30] = "1314", psd[30];
? ? char number[30];
? ? int score, i, j;
? ? printf("please input password: ");
? ? scanf("%s", psd);
? ? // 密碼正確才繼續(xù),否則返回ERROR
? ? if (strcmp(password, psd) == 0)
? ? {
? ? ? ? printf("please input the student's number: ");
? ? ? ? scanf("%s", number);
? ? ? ? for (i = 0; i < n; i++)
? ? ? ? {
? ? ? ? ? ? // 找到學(xué)生則繼續(xù),否則返回ERROR
? ? ? ? ? ? if (strcmp(pS[i].number, number) == 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? printf("please input the course and score one by one: \n");
? ? ? ? ? ? ? ? scanf("%s %d", courseName, &score);
? ? ? ? ? ? ? ? for (j = 0; j < m; j++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? // 找到課程才繼續(xù),否則返回ERROR
? ? ? ? ? ? ? ? ? ? if (strcmp(pS[i].pC[j].name, courseName) == 0)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? // 修改課程成績(jī)
? ? ? ? ? ? ? ? ? ? ? ? pS[i].pC[j].score = score;
? ? ? ? ? ? ? ? ? ? ? ? return OK;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? return ERROR;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? return ERROR;
? ? }
? ? else
? ? ? ? return ERROR;
}

// 輸出各課程最高分的學(xué)生
void showMax(pStudent pS)
{
? ? int i, j, max;
? ? for (i = 0; i < m; i++)
? ? {
? ? ? ? max = 0;
? ? ? ? for (j = 0; j < n; j++)
? ? ? ? {
? ? ? ? ? ? if (pS[j].pC[i].score > pS[max].pC[i].score)
? ? ? ? ? ? ? ? max = j;
? ? ? ? }
? ? ? ? printf("%s\t%s\t%s\t%d\n", course[i], pS[max].name, pS[max].number, pS[max].pC[i].score);
? ? }
}

// 顯示各課程的平均成績(jī)
void showAverage(pStudent pS)
{
? ? int i, j;
? ? double ave;
? ? for (i = 0; i < m; i++)
? ? {
? ? ? ? ave = 0;
? ? ? ? for (j = 0; j < n; j++)
? ? ? ? {
? ? ? ? ? ? ave += pS[j].pC[i].score;
? ? ? ? }
? ? ? ? printf("%s\t%.2lf\n", course[i], ave / n);
? ? }
}

void Swap(pStudent s1, pStudent s2)
{
? ? int i;
? ? char studentName[30], number[30];
? ? // 交換姓名
? ? strcpy(studentName, s1->name);
? ? strcpy(s1->name, s2->name);
? ? strcpy(s2->name, studentName);
? ? // 交換學(xué)號(hào)
? ? strcpy(number, s1->number);
? ? strcpy(s1->number, s2->number);
? ? strcpy(s2->number, number);
? ? // 交換成績(jī)
? ? for (i = 0; i < m; i++)
? ? {
? ? ? ? int temp = s1->pC[i].score;
? ? ? ? s1->pC[i].score = s2->pC[i].score;
? ? ? ? s2->pC[i].score = temp;
? ? }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C++ 多線程編程建議之 C++ 對(duì)多線程/并發(fā)的支持(下)

    C++ 多線程編程建議之 C++ 對(duì)多線程/并發(fā)的支持(下)

    這篇文章主要介紹的是 C++ 多線程編程建議之 C++ 對(duì)多線程/并發(fā)的支持的相關(guān)資料,承接前文 現(xiàn)代 C++ 對(duì)多線程/并發(fā)的支持,接下來我們看看回發(fā)生什么吧
    2021-10-10
  • C語言數(shù)據(jù)結(jié)構(gòu)的時(shí)間復(fù)雜度和空間復(fù)雜度

    C語言數(shù)據(jù)結(jié)構(gòu)的時(shí)間復(fù)雜度和空間復(fù)雜度

    算法在編寫成可執(zhí)行程序后,運(yùn)行時(shí)需要耗費(fèi)時(shí)間資源和空間(內(nèi)存)資源 。因此衡量一個(gè)算法的好壞,一般是從時(shí)間和空間兩個(gè)維度來衡量的,即時(shí)間復(fù)雜度和空間復(fù)雜度,感興趣的同學(xué)可以參考閱讀
    2023-04-04
  • C++從匯編的視角審視對(duì)象的創(chuàng)建問題

    C++從匯編的視角審視對(duì)象的創(chuàng)建問題

    這篇文章主要介紹了C++從匯編的視角看對(duì)象的創(chuàng)建,從匯編的視角來看,調(diào)用構(gòu)造器和調(diào)用 “返回對(duì)象” 的函數(shù)是一樣的,從匯編的角度來看,對(duì)象就是一堆數(shù)據(jù)的排列,比如說最普通的對(duì)象就是數(shù)據(jù)成員按照聲明順序直接排列,需要的朋友可以參考下
    2022-01-01
  • 詳解C語言和Python中的線程混用

    詳解C語言和Python中的線程混用

    這篇文章主要介紹了C和Python中的線程混用的相關(guān)資料,文中講解非常細(xì)致,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • C++ Boost Serialization庫超詳細(xì)獎(jiǎng)金額

    C++ Boost Serialization庫超詳細(xì)獎(jiǎng)金額

    Boost是為C++語言標(biāo)準(zhǔn)庫提供擴(kuò)展的一些C++程序庫的總稱。Boost庫是一個(gè)可移植、提供源代碼的C++庫,作為標(biāo)準(zhǔn)庫的后備,是C++標(biāo)準(zhǔn)化進(jìn)程的開發(fā)引擎之一,是為C++語言標(biāo)準(zhǔn)庫提供擴(kuò)展的一些C++程序庫的總稱
    2022-12-12
  • C++中多線程間共享數(shù)據(jù)詳解

    C++中多線程間共享數(shù)據(jù)詳解

    這篇文章主要為大家詳細(xì)介紹了C++中多線程間共享數(shù)據(jù)的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2024-01-01
  • C++11中std::packaged_task的使用詳解

    C++11中std::packaged_task的使用詳解

    這篇文章主要介紹了C++11中std::packaged_task的使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-02-02
  • C++中的最小生成樹算法超詳細(xì)教程

    C++中的最小生成樹算法超詳細(xì)教程

    這篇文章主要介紹了C++中的最小生成樹算法超詳細(xì)教程,最小生成樹的最著名的算法有兩個(gè), 一個(gè)是Prim算法, 另一個(gè)當(dāng)然就是Kruskal算法, 接下來, 我將盡我所能的介紹這兩個(gè)算法, 也算是對(duì)自己學(xué)習(xí)的一個(gè)回顧吧,需要的朋友可以參考下
    2023-08-08
  • 使用C語言繪制柱形圖的示例代碼

    使用C語言繪制柱形圖的示例代碼

    常用的統(tǒng)計(jì)圖有條形圖、柱形圖、折線圖、曲線圖、餅圖、環(huán)形圖、扇形圖,這篇文章主要為大家介紹了C語言中繪制條形圖和柱形圖的方法,需要的可以參考下
    2024-02-02
  • 詳解C/C++ 的*和&用法

    詳解C/C++ 的*和&用法

    這篇文章主要介紹了C/C++ 的*和&的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11

最新評(píng)論

邛崃市| 沙洋县| 巩义市| 西盟| 通州市| 内丘县| 永宁县| 长治市| 竹北市| 枣阳市| 利川市| 新平| 三门峡市| 紫云| 和静县| 浮梁县| 赤城县| 来宾市| 咸丰县| 固原市| 泗洪县| 濮阳市| 高平市| 赣州市| 昭通市| 高青县| 青川县| 喀喇沁旗| 兴安县| 汝州市| 东阿县| 柏乡县| 厦门市| 深圳市| 沅陵县| 屏东市| 靖西县| 安国市| 满城县| 盐山县| 南涧|