Experiment 1 Student Performance Management System

                

Experiment 1 Student Performance Management System

1. Problem description

The data elements in the student performance management system have the following form:

The student's achievement records include data items such as student number, name, Chinese, mathematics, and computer.

2. functional requirements

The score registration form is required to complete the following functions:

⑴ Insert: Insert a student's grade record into the registration form;

⑵Delete: delete the records that meet the conditions;

⑶ Modify: Modify the data items of the score record;

⑷ Query: Find students who meet the conditions;

⑸ Output: Output all (or meet the conditions) score records in the score record registration form.

3. Implementation points

       Sequential storage structure is adopted for the grade record registration table. When creating the table, the written form of the grade record table is converted into the storage structure of the sequential table, and the student's written form is also converted into a specific class.

4. class definition  

Create a SeqList for the sequence table, and its class definition is as follows:

In the SeqList class, the following member functions are provided

(1) Function declaration SeqList(T a[ ], int n);

       The length of the completed functional structure is n, and the elements are the sequence list of elements in the array a[ ].

   (2) Function declaration int Length( ) {return length;}

Completed function Find the length of the sequence table

   (3) Function declaration T Get(int i)

The completed function is to search sequentially and read the i-th element in the table

(4) Function declaration void Insert(int i, T x);

     Completed function Insert an element with the value x at the i-th position in the sequence table

(5) Function declaration T Delete(int i);

The completed function finds and deletes the i-th element of the sequence table

   (6) Function declaration void PrintList( )

       The completed function traverses the sequence table and outputs each element in sequence according to the sequence number

   (7) Function declaration void PrintStudent(T x)

       The completed function outputs the element x

5. class definition

#pragma once

struct Student

{

       string name;//姓名

       long stuNum;//学号

       int chinese;//语文

       int matheMatics;//数学

       int computer;//计算机

       int  tScore;//总分

};

6. Code

#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");

       }

}

Guess you like

Origin blog.csdn.net/weixin_46279994/article/details/127116451