C++实现:简单的学生信息管理系统(控制台程序)
- 格式:docx
- 大小:14.59 KB
- 文档页数:34


学生信息管理系统c语言程序设计
一、主要思想。
(1)使用结构体数组来存储学生信息;
(2)创建查询、添加、修改、删除等操作函数来实现学生信息的管理;
(3)设置菜单,程序通过switch-case语句来识别用户输入,实现
不同的操作。
二、具体实现。
(1)定义一个学生信息的结构体,存储学号、姓名、年龄、性别等
信息;
(2)为学生信息管理系统添加菜单,当用户输入要求时,通过
switch语句来调用响应的函数;
(3)定义查询函数:用户可以根据学号、姓名或性别查询学生信息;
(4)定义添加函数:根据用户输入添加学生信息,需要排重处理;
(5)定义修改函数:根据学号查询到学生的信息后,用户可以修改
相应的内容;
(6)定义删除函数:根据学号查询学生信息后,用户可以删除学生
信息;
(7)定义退出系统函数:用户输入0,就可以退出学生信息管理系统。
c++学生信息管理系统设计代码以下是一个简单的C++学生信息管理系统的设计代码:```cpp#include <iostream>#include <vector>#include <string>using namespace std;// 学生类class Student {private:string name;string id;string gender;int age;public:Student(string name, string id, string gender, int age) { this->name = name;this->id = id;this->gender = gender;this->age = age;}string getName() {return name;}string getId() {return id;}string getGender() {return gender;}int getAge() {return age;}};// 学生信息管理系统类class StudentManagementSystem {private:vector<Student> students; // 学生信息容器public:// 添加学生信息void addStudent(string name, string id, string gender,int age) {Student student(name, id, gender, age);students.push_back(student);cout << "学生信息添加成功!" << endl;}// 查找学生信息void findStudent(string id) {bool found = false;for (int i = 0; i < students.size(); i++) {if (students[i].getId() == id) {cout << "学生姓名:" << students[i].getName() << endl;cout << "学生学号:" << students[i].getId() << endl;cout << "学生性别:" <<students[i].getGender() << endl;cout << "学生年龄:" << students[i].getAge() << endl;found = true;}}if (!found) {cout << "未找到该学生信息!" << endl;}}};int main() {StudentManagementSystem sms;cout << "欢迎使用学生信息管理系统!" << endl;cout << "1. 添加学生信息" << endl;cout << "2. 查找学生信息" << endl;cout << "3. 退出" << endl;int choice;string name, id, gender;int age;while (true) {cout << "请输入选项:";cin >> choice;if (choice == 1) {cout << "请输入学生姓名:";cin >> name;cout << "请输入学生学号:";cin >> id;cout << "请输入学生性别:";cin >> gender;cout << "请输入学生年龄:";cin >> age;sms.addStudent(name, id, gender, age);}else if (choice == 2) {cout << "请输入要查找学生的学号:";cin >> id;sms.findStudent(id);}else if (choice == 3) {break;}else {cout << "无效选项,请重新输入!" << endl;}}cout << "谢谢使用学生信息管理系统,再见!" << endl;return 0;}```这个程序实现了一个简单的学生信息管理系统,可以添加学生信息和查找学生信息。
#include〈stdio。
h〉#include<stdlib。
h〉#include<conio。
h>#include<string。
h〉struct student{int id;char name[10];int age;char sex[10];char birthady[20];int tel;char nativeplace[50];}st[50];int i=0;void shuru() {char a;do{printf("\n请输入学号:");scanf("%d”,&st[i].id);fflush(stdin);printf(”\n请输入姓名:”);gets(st[i]。
name);printf(”\n") ;printf(”请输入年龄:”);scanf(”%d",&st[i]。
age);fflush(stdin);printf("\n请输入姓别:");gets(st[i]。
sex);fflush(stdin);printf("\n请输入生日:”);gets(st[i]。
birthady);printf(”\n请输入电话:”);scanf(”%d",&st[i].tel);fflush(stdin);printf(”\n请输入籍贯:”);gets(st[i].nativeplace);printf("\n是否继续输入另外一个学生信息?(y/n)”);fflush(stdin);a=getchar();i++;}while(a=='y’ &&i<=50);}void xianshi(){int j;printf(”\t学号\t姓名\t年龄\t性别\t生日\t\t电话\t籍贯\n");for(j=0;j〈i;j++)printf(”\t%d\t%s\t%d\t%s\t%s\t%d\t%s\n",st[j]。
#include <iostream.h> #include <iomanip.h>#include <fstream>#include <vector>#include <malloc.h>#include <stdlib.h>#include <string>#include <process.h>#include <stdio.h>#define LEN sizeof(struct student)using namespace std;int n=0; //定义一个全局变量统计学生人数struct student//定义一个学生信息的构造体char name[20]; //用来存放姓名的char sex[20]; //用来存放性别的char yuanxi[20];//用来存放院系的long int id; //用来存放学号的int score[4]; //用来存放分数的int total; //用来存放总分数的struct student *next;vector <student> stu;class Informationpublic:Information() ; //构造函数.~Information() ; //析构函数.student *creat();//建立链表函数。
void output(student *head);int count(student *head);//定义函数count()统计考生总数student *insert(student*head);//指针函数*insert()用来添加考生信息.student *cancel(student *head,long int num);//指针函数*cancel()用来删除考生信息.student *find(student *head,long int num); //指针函数*find()用来查找考生信息.void inorder(student *head);//定义inorder()函数将考生的总分从大到小排列并输出void average( student *head);//求学生成绩的平均分的函数void save(student *head);//保存函数student *Read();//读取函数private:student *p1,*p2,*p3,*head,st;Information::Information() //构造函数cout<<"******************************************************************************\n";cout<<" ------------------------<<欢送您使用学生信息管理系统>>------------------------\n";cout<<"******************************************************************* ***********\n\n";Information::~Information() //构造函数cout<<"******************************************************************* ***********\n";cout<<" ------------------------<<谢谢您使用学生信息管理系统>>------------------------\n";cout<<"******************************************************************* ***********\n";student *Information::creat(void) //定义一个指向struct student的构造体指针函数*creat()用来增加学生信息.char ch[20];n=0; //用来存放姓名的p1=p2=(student *)malloc(LEN);//调用malloc()函数用来开辟一个新的存储单元cout<<" -------------<<请建立学生考试信息表,在姓名处输入! 完毕输入。