用C++写的学生成绩管理系统(比较简单的没有使用链表,只是用到了类和对象)

本人是菜鸟,所以编的比较简单,这里是我一次小尝试,希望大家可以批评指正,本菜鸟将不胜感激。

输入学生数据,还有命令操作界面

图1 输入数据和操作命令界面

 

效果2

                              图2 计算均值列成绩清单命令

 

#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
using std::string;

string s,name,code,name1,code1;
char comd;
float chinese,english,math,tchinese = 0,tenglish = 0,tmath = 0;
int i = 0;


class studentrecord
{
private:
 string name;
 string code;
 float chinese;
 float english;
 float math;
 float total;
 float average;
public:
 studentrecord(){}
 studentrecord(string n,string co,float c,float e,float m):name(n),code(co),chinese(c),english(e),math(m)
 {
       total = c + e + m;
    average = total/3;
 }
 string getname()
 {return name;}
 string getcode()
 {return code;}
 float getchinese()
 {return chinese;}
 float getenglish()
 {return english;}
 float getmath()
 {return math;}
 float gettotal()
 {return total;}
 void print()
 {
  cout << "---------------------------------------------" << endl;
  cout << "Name    : " << name << endl;
  cout << "Code    : " << code << endl;
  cout << "Marks   : " << endl;
  cout << "        Chinese      :   " << chinese << endl;
        cout << "        English      :   " << english << endl;
        cout << "        Math         :   " << math << endl;
  cout << "Total   : " << total << endl;
  cout << "Average : " << average << endl;
  cout << "---------------------------------------------" << endl;
 }

};

void list(studentrecord *pobj,int i);  //声明列学生清单的函数
void fname(studentrecord *pobj,int i); //声明按名字查找学生的函数
void fcode(studentrecord *pobj,int i); //声明按学号查找学生的函数
void getaverage(studentrecord *pobj,int i); //声明计算平均成绩的函数
void sortlist(int i); //声明按总分排序后输出清单的函数
void getfirst(int k,int i); //排序函数

studentrecord obj[20]; //定义20个studentrecord的对象


int _tmain(int argc, _TCHAR* argv[])
{
 cout << "***********************************" << endl;
 cout << "         学生成绩管理程            " << endl;
 cout << "        制作人:Dragonfly          " << endl;
 cout << "          谢谢使用!!!           " << endl;
 cout << "***********************************" << endl;
 do                                                         //输入学生信息阶段
    {
     if(s == "end") break;
  cout << "Please enter the Name : ";
  cin >> name;
        cout << "Please enter the Code : ";
  cin >> code;
  cout << "Please enter the Chinese mark : ";
  cin >> chinese;
  cout << "Please enter the English mark : ";
  cin >> english;
  cout << "Please enter the Math mark : ";
  cin >> math;
        obj[i] = studentrecord(name,code,chinese,english,math);
  i++;
  cout << "Pass any key to continue......enter end to exit : ";
  
 }while(cin >> s);
    cout << "----------------------------------------------------------" << endl;
 cout << "Now you can input a command to manage the record." << endl;
 cout << "l  :  list all the record." << endl;
 cout << "n  :  search record by student's name." << endl;
    cout << "c  :  search record by student's code." << endl;
 cout << "m  :  mean of the marks." << endl;
 cout << "s  :  sort and list the record by the total." << endl;
 while(cin >> comd)                                         //输入完学生信息开始学生信息处理
 {
  switch(comd)
  {
  case 'l':
   list(obj,i);
   break;
  case 'n':
   fname(obj,i);
   break;
  case 'c':
   fcode(obj,i);
   break;
  case 'm':
   getaverage(obj,i);
   break;
  case 's':
   sortlist(i);
     
    }
   
 }
 
 return 0;
}

 

 

void list(studentrecord *pobj,int i)
{
 for(int j = 0;j<i;j++)
 {
  pobj -> print();
  pobj ++;
 }
 cout << "Please enter the command : ";
}

 

 

void fname(studentrecord *pobj,int i)
{
   cout << "Please enter the name : ";
   cin >> name1;
   for(int j = 0;j<i;j++)
 {
  if (pobj -> getname() == name1)
  {
   pobj -> print();
   break;
  }
  pobj ++;
 }
   cout << "Please enter the command : ";
}

 

 

void fcode(studentrecord *pobj,int i)
{
 cout << "Please enter the code : ";
    cin >> code1;
 for(int j = 0;j<i;j++)
 {
  if (pobj -> getcode() == code1)
  {
   pobj -> print();
   break;
  }
  pobj ++;
 }
 cout << "Please enter the command : ";
}

 

 

void getaverage(studentrecord *pobj,int i)
{
    tchinese = 0;
 tenglish = 0;
 tmath = 0;
 for (int j = 0;j<i;j++)
    {
     tchinese += pobj -> getchinese();
     tenglish += pobj -> getenglish();
      tmath += pobj -> getmath();
   pobj ++;
  }
   
            cout << "---------------------------------------------" << endl;
   cout << "Chinese      's average is : " << (tchinese/i) << endl;
            cout << "English      's average is : " << (tenglish/i) << endl;
   cout << "Math         's average is : " << (tmath/i) << endl;
   cout << "---------------------------------------------" << endl;
   cout << "Please enter the command : ";
}

 

 

void sortlist(int i)
{
    for(int k = 0;k < i;k++)
  getfirst(k,i);
 cout << "Please enter the command : ";
}

 

 

void getfirst(int k,int i)
{
for(int j = k + 1;j < i;j++)
 {
  if(obj[k].gettotal() < obj[j].gettotal())
  {
   studentrecord temp;
   temp = obj[k];
   obj[k] = obj[j];
   obj[j] = temp;
  }
 }
   cout << "第" << (k+1) << "名 : " << obj[k].getname() << endl;
   obj[k].print();
}

  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是一个简单的学生成绩管理系统链表实现,包括添加、删除、修改和查询学生成绩。 ```c #include <stdio.h> #include <stdlib.h> #include <string.h> // 学生结构体 typedef struct student { char name[20]; int id; float score; struct student *next; } Student; // 添加学生 void addStudent(Student **head) { Student *new_student = (Student*)malloc(sizeof(Student)); printf("请输入学生姓名:"); scanf("%s", new_student->name); printf("请输入学生学号:"); scanf("%d", &(new_student->id)); printf("请输入学生分数:"); scanf("%f", &(new_student->score)); new_student->next = *head; *head = new_student; } // 删除学生 void deleteStudent(Student **head, int id) { Student *current = *head; Student *previous = NULL; while (current != NULL) { if (current->id == id) { if (previous == NULL) { *head = current->next; } else { previous->next = current->next; } free(current); printf("删除成功!\n"); return; } previous = current; current = current->next; } printf("没有找到该学生!\n"); } // 修改学生信息 void modifyStudent(Student **head, int id) { Student *current = *head; while (current != NULL) { if (current->id == id) { printf("请输入修改后的学生姓名:"); scanf("%s", current->name); printf("请输入修改后的学生分数:"); scanf("%f", &(current->score)); printf("修改成功!\n"); return; } current = current->next; } printf("没有找到该学生!\n"); } // 查询学生信息 void queryStudent(Student *head, int id) { Student *current = head; while (current != NULL) { if (current->id == id) { printf("学生姓名:%s\n", current->name); printf("学生学号:%d\n", current->id); printf("学生分数:%.1f\n", current->score); return; } current = current->next; } printf("没有找到该学生!\n"); } // 打印所有学生信息 void printAllStudents(Student *head) { Student *current = head; while (current != NULL) { printf("学生姓名:%s\n", current->name); printf("学生学号:%d\n", current->id); printf("学生分数:%.1f\n", current->score); current = current->next; } } int main() { Student *head = NULL; int choice = 0, id; while (1) { printf("\n=====================\n"); printf("1. 添加学生\n"); printf("2. 删除学生\n"); printf("3. 修改学生信息\n"); printf("4. 查询学生信息\n"); printf("5. 打印所有学生信息\n"); printf("0. 退出程序\n"); printf("=====================\n"); printf("请输入操作序号:"); scanf("%d", &choice); switch (choice) { case 1: addStudent(&head); break; case 2: printf("请输入要删除的学生学号:"); scanf("%d", &id); deleteStudent(&head, id); break; case 3: printf("请输入要修改的学生学号:"); scanf("%d", &id); modifyStudent(&head, id); break; case 4: printf("请输入要查询的学生学号:"); scanf("%d", &id); queryStudent(head, id); break; case 5: printAllStudents(head); break; case 0: printf("程序已退出!\n"); return 0; default: printf("输入有误,请重新输入!\n"); break; } } return 0; } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

unicorn713

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值