実験1 生徒の成績管理システム

                

実験1 生徒の成績管理システム

1. 問題の説明

生徒の成績管理システムのデータ要素は次の形式になります。

学生の成績記録には、学籍番号、氏名、中国語、数学、コンピュータなどのデータ項目が含まれます。

2. 機能要件

スコア登録フォームは、次の機能を完了するために必要です。

⑴ 挿入: 生徒の成績記録を登録フォームに挿入します。

⑵削除:条件を満たすレコードを削除します。

⑶ 変更:スコアレコードのデータ項目を変更します。

⑷ クエリ: 条件を満たす学生を検索します。

⑸ 出力:得点記録登録フォームの全ての(または条件を満たす)得点記録を出力します。

3. 実施のポイント

       成績記録登録テーブルは逐次格納構造を採用しており、成績記録テーブルの記述形式を逐次テーブルの格納構造に変換して作成するとともに、生徒の記述形式も特定のクラスに変換して作成します。

4. クラス定義  

シーケンス テーブルの SeqList を作成します。そのクラス定義は次のとおりです。

SeqListクラスには以下のメンバー関数が提供されています

(1) 関数宣言 SeqList(T a[ ], int n);

       完成した関数構造の長さは n で、要素は配列 a[ ] 内の要素のシーケンス リストです。

   (2) 関数宣言 int Length( ) {return length;}

完成した関数 数列テーブルの長さを求める

   (3) 関数宣言 T Get(int i)

完成した関数は、テーブル内の i 番目の要素を順番に検索して読み取ることです。

(4) 関数宣言 void Insert(int i, T x);

     完成した関数は、値 x を持つ要素をシーケンス テーブルの i 番目の位置に挿入します。

(5) 関数宣言 T Delete(int i);

完成した関数は、シーケンス テーブルの i 番目の要素を検索して削除します。

   (6) 関数宣言 void PrintList( )

       完成した関数はシーケンス テーブルを走査し、シーケンス番号に従って各要素を順番に出力します。

   (7) 関数宣言 void PrintStudent(T x)

       完成した関数は要素 x を出力します。

5. クラス定義

#pragma once

struct Student

{

       string name;//姓名

       long stuNum;//学号

       int chinese;//语文

       int matheMatics;//数学

       int computer;//计算机

       int  tScore;//总分

};

6. コード

#include "SeqList.h"

#include<iostream>

using namespace std;

template<class T>

SeqList<T>::SeqList() {

       length = 0;

}


template<class T>

SeqList<T>::SeqList(T a[], int n) {

       if (n > MaxSize) {

              throw "参数非法";

       }


       for (int i = 0; i < n; i++) {

              data[i] = a[i];

              length = n;

       }

}


//插入算法

template<class T>

void SeqList<T>::Insert(int i, T x) {

       if (length == MaxSize) throw"上溢";

       if (i < 1 || i>length + 1)throw"位置错误";

       for (int j = length; j >= i; j--) {

              data[j] = data[j - 1];

       }

       data[i - 1] = x;

       length++;

}




//删除操作算法

template <class T>

T SeqList<T>::Delete(int i) {

       if (length == 0)throw"UnderFlow";

       if (i < 1 || i>length)throw"Wrong Position";

       T x = data[i - 1];

       for (int j = i; j <= length - 1; j++) {

              data[j - 1] = data[j];


       }

       length--;

       return x;

}


//查找算法操作

//1)按位查找

template<class T>

T SeqList<T>::Get(int i) {

       if (i<1 || i>length)throw"wrong position";

       else {

              return data[i - 1];

       }

}


//2)按值查找

template<class T>

int SeqList<T>::Locate(T x) {

       for (int i = 0; i < length; i++) {

              if (data[i] == x)return i + 1;

              else {

                     return 0;

              }

       }

}

//输出操作算法

template<class T>

void SeqList<T>::PrintList() {

       for (int i = 0; i < length; i++) {

             

              cout << data[i].name << '\t' << data[i].stuNum << '\t' << data[i].chinese << '\t' << data[i].matheMatics << '\t' << data[i].computer << '\t' << Total(data[i]);

             


       }

}


//主函数

#include<iostream>

#include "Seqlist.h"

#include"LinkLeast.h"

#include"student.h";

#include<string>

using namespace std;

void menu() {

       cout << "------------【学生信息管理系统】--------------\n";

       cout << "\t\t0.退出系统\n";

       cout << "\t\t1.录入信息\n";

       cout << "\t\t2.浏览信息\n";

       cout << "\t\t3.删除信息\n";

       cout << "\t\t4.查找信息\n";

       cout << "\t\t5.修改信息\n";


       cout << "--------------------------------------------------\n";

}


float Total(Student stu) {

       return (stu.chinese + stu.computer + stu.matheMatics);

}

void Print(Student stu) {

       cout << "姓名" << '\t'  << "学号" << '\t' << "语文" << '\t' << "数学" << '\t' << "计算机" << '\t' << "总分" << endl;;

       cout << stu.name << '\t'  << stu.stuNum << '\t' << stu.chinese << '\t' << stu.matheMatics << '\t' << stu.computer << '\t' << Total(stu);

}


int main() {

       SeqList<Student> a;

       Student stu;

       Student s1;

       stu.name = 'k';

       stu.stuNum = 1;

       stu.chinese = 90;

       stu.computer = 80;

       stu.matheMatics = 70;

       menu();

       while (1) {

              int chioce;

              cin >> chioce;

              switch (chioce) {

              case 0:

                     cout << "正常退出!";

                     exit(0);

                     break;


              case 1:

                     cout << "-------------------【录入信息】--------\n";

                     cin >> s1.name;

                     cin >> s1.stuNum;

                     cin >> s1.chinese;

                     cin >> s1.computer;

                     cin >> s1.matheMatics;

                     a.Insert(1, stu);

                     cout << endl;


                     a.Insert(2, s1);

                    

                     break;


              case 2:

                     cout << "-------------------【浏览信息】--------\n";

                     cout << "姓名" << '\t' << "学号" << '\t' << "语文" << '\t' << "数学" << '\t' << "计算机" << '\t' << "总分" << endl;

                     a.PrintList();

                     break;

              case 3:

                     cout << "-------------------【删除信息】--------\n";

                     int k;

                     cin >> k;

                     a.Delete(k);

                     break;

              case 4:

                     cout << "-------------------【查找信息】--------\n";

                     int m;

                     cin >> m;

                     a.Get(m);

                     break;

              case 5:

                     cout << "-------------------【修改信息】--------\n";

                     int newchinese,newmatheMatics,newcomputer,i;

                     cin >> i;

                     cin >> newchinese;

                     cin >> newcomputer;

                     cin >> newmatheMatics;

                     s1.chinese = newchinese;

                     s1.computer = newcomputer;

                     s1.matheMatics = newmatheMatics;

                     a.PrintList();

                     break;

              default:

                     break;


              }

              //system("cls");

       }

}

おすすめ

転載: blog.csdn.net/weixin_46279994/article/details/127116451