C++实现学生选课管理系统

C++实现学生选课管理系统这是主函数逻辑部分#include<iostream>#include”class.h”#include”student.h”usingnamespacestd;intmain(){ courseA; studentB[10];//10个学生 intstucnt=0; intdengluflag=-1;…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

C++实现学生选课管理系统

这是主函数逻辑部分

#include <iostream>
#include "class.h"
#include "student.h"
using namespace std;
int main()
{

	course A;   
	student B[10];  //10个学生
	int stucnt=0;   
	int dengluflag=-1;
	while (1)
	{
		int SW;
		cout << "欢迎来到选课系统,请选择编号进行操作" << endl;
		cout << "1.注册账号" << endl;
		cout << "2.登陆已有账号" << endl;
		cin >> SW;
		switch (SW)
		{
		case 1:
			char temp[20];
			cout << "请输入注册学号账号" << endl;
			scanf("%s", temp);
			B[stucnt].setxuehao(temp);
			cout << "请输入登陆验证密码" << endl;
			scanf("%s", temp);
			B[stucnt].setyanz(temp);
			cout << "注册成功,注册信息如下" << endl;
			B[stucnt].checkC();
			stucnt++;
			system("pause");
			break;
		case 2:
			char temp1[10];
			cout << "请输入学号账号" << endl;
			scanf("%s", temp);
			go1:cout << "请输入登陆验证密码" << endl;
			scanf("%s", temp1);
			for (int i = 0; i < stucnt; i++)
			{
				if (B[i].xuehaopipei(temp) == true)
				{
					if (B[i].yanzpipei(temp1) == true)
					{
						cout << "登陆成功" << endl;
						dengluflag = i;
					}
					else
					{
						cout << "验证密码错误,重试" << endl;
						goto go1;
					}
				}
			}
			if (dengluflag < 0)cout << "学号不存在" << endl;
			system("pause");
			break;
		default:
			break;
		}
		if(dengluflag>=0)
			while (1)
			{
				system("cls");
				int SW1=0;
				cout << "欢迎登陆,请选择功能编号" << endl;
				cout << "1.课程信息录入" << endl;
				cout << "2.课程信息修改" << endl;
				cout << "3.课程信息删除" << endl;
				cout << "4.课程信息浏览" << endl;
				cout << "5.开始选课" << endl;
				cout << "6.选课结果查询" << endl;
				cin >> SW1;
				switch (SW1)
				{
					char temp[20];
				case 1:
					A.getinf();
					system("pause");
					break;
				case 2:
					A.reinf();
					system("pause");
					break;
				case 3:
					A.deinf();
					system("pause");
					break;
				case 4:
					A.printfc();
					system("pause");
					break;
				case 5:
					A.printfc();
					cout << "请输入要选的课程编号" << endl;
					scanf("%s", temp);
					B[dengluflag].choiceC(temp);
					cout << "选课成功" << endl;
					system("pause");
					break;
				case 6:
					system("cls");
					int sw=0;
					cout << "1.按学号查询学生选课情况" << endl;
					cout << "2.按课程查询学生选课情况" << endl;
					cin >> sw;
					switch (sw)
					{
					case 1:
						cout << "请输入学号" << endl;
						scanf("%s", temp);
						for (int i = 0; i < stucnt; i++)
						{
							if (B[i].xuehaopipei(temp))B[i].checkC();
						}
						system("pause");
						break;
					case 2:
						char temp62[20];
						cout << "请输入查询课程编号" << endl;
						scanf("%s", temp62);
						cout << "选择此门课程的学号有" << endl;
						for (int i = 0; i < stucnt; i++)
						{
							for (int j = 1; j <= B[i].kecnt; j++)
							{
								char temp1[20];
								B[i].getkc(j, temp1);
								if (strcmp(temp1, temp62) == 0)cout << B[i].xuehao<<",";
							}
						}
						cout << endl;
						break;
					}
					system("pause");
					break;


				}
				_sleep(1000);
				system("cls");
			}
		_sleep(1000);
		system("cls");
	}



	system("pause");
	return 0;
}

下面为自己定义的头文件,分别为学生类与课程类

#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <vector>
#include<string.h>
using namespace std; 
class student
{
public:
	char yixuankec[256];
	char yanz[10]="000000";
	char xuehao[20];
	int kecnt = 0;            //已选课程数目
public:
	
	student(char *_xuehao=NULL,char *_yanz=NULL);
	void choiceC(char* _bianhao);                              //选课功能
	void checkC();                             //查询功能
	void getkc(int cnt, char* temp);           //返回第cnt个课程的编号
	void setyanz(char *_yanz);                 //重新设置验证码
	void setxuehao(char *_xuehao);			  //设置学号
	bool xuehaopipei(char *_xuehao);          //学号是否匹配
	bool yanzpipei(char*_yanz);               //验证码是否匹配
};
student::student(char *_xuehao, char *_yanz)
{
	kecnt = 0;
	yixuankec[0] = 0;
	if (_xuehao != NULL)strcpy(xuehao, _xuehao);
	if (_yanz!=NULL)strcpy(yanz, _yanz);
}

void student::choiceC(char* _bianhao)                              //选课功能
{
	int i = 0;
	for (i = 0; i < 256; i++)
	{
		if (yixuankec[i] == 0)
		{
			if (kecnt != 0)
			{
				yixuankec[i] = ',';
				i++;
			}
			break;
		}
	}
	strcpy(yixuankec + i, _bianhao);//此处没有判断i是否越界
	kecnt++;
}
void student::checkC()									//查询功能
{
	printf("学号:%s\n", xuehao);
	printf("登陆验证:%s\n", yanz);
	printf("已选课程编号:%s\n", yixuankec);

}
void student::getkc(int cnt, char* temp)    
{
	char temp1[10];
	int c=0;
	for (int i = 0,j=0; i < 256; i++)
	{
		if (yixuankec[i] != 0 && yixuankec[i] != ',')
		{
			temp1[j] = yixuankec[i];
			j++;
		}
		else //yixuankec[i] == ',' 
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
#include <vector>
#include<string.h>
using namespace std; 
class student
{
public:
char yixuankec[256];
char yanz[10]="000000";
char xuehao[20];
int kecnt = 0;            //已选课程数目
public:
student(char *_xuehao=NULL,char *_yanz=NULL);
void choiceC(char* _bianhao);                              //选课功能
void checkC();                             //查询功能
void getkc(int cnt, char* temp);           //返回第cnt个课程的编号
void setyanz(char *_yanz);                 //重新设置验证码
void setxuehao(char *_xuehao);			  //设置学号
bool xuehaopipei(char *_xuehao);          //学号是否匹配
bool yanzpipei(char*_yanz);               //验证码是否匹配
};
student::student(char *_xuehao, char *_yanz)
{
kecnt = 0;
yixuankec[0] = 0;
if (_xuehao != NULL)strcpy(xuehao, _xuehao);
if (_yanz!=NULL)strcpy(yanz, _yanz);
}
void student::choiceC(char* _bianhao)                              //选课功能
{
int i = 0;
for (i = 0; i < 256; i++)
{
if (yixuankec[i] == 0)
{
if (kecnt != 0)
{
yixuankec[i] = ',';
i++;
}
break;
}
}
strcpy(yixuankec + i, _bianhao);//此处没有判断i是否越界
kecnt++;
}
void student::checkC()									//查询功能
{
printf("学号:%s\n", xuehao);
printf("登陆验证:%s\n", yanz);
printf("已选课程编号:%s\n", yixuankec);
}
void student::getkc(int cnt, char* temp)    
{
char temp1[10];
int c=0;
for (int i = 0,j=0; i < 256; i++)
{
if (yixuankec[i] != 0 && yixuankec[i] != ',')
{
temp1[j] = yixuankec[i];
j++;
}
else //yixuankec[i] == ',' \0
{
c++;
temp1[j] = 0;
if (c == cnt)
{
strcpy(temp, temp1);
return;
}
j = 0;
}
}
}
void student::setyanz(char *_yanz)                 //重新设置验证码
{
strcpy(yanz, _yanz);
//cout << "设置成功" << endl;
}
void student::setxuehao(char *_xuehao)			  //设置学号
{
strcpy(xuehao, _xuehao);
//cout << "申请成功" << endl;
}
bool student::xuehaopipei(char *_xuehao)          //学号是否匹配
{
if (strcmp(xuehao, _xuehao) == 0)return true;
else return false;
}
bool student::yanzpipei(char*_yanz)              //验证码是否匹配
{
if (strcmp(yanz, _yanz) == 0)return true;
else return false;
}
#endif
{ c++; temp1[j] = 0; if (c == cnt) { strcpy(temp, temp1); return; } j = 0; } } } void student::setyanz(char *_yanz) //重新设置验证码 { strcpy(yanz, _yanz); //cout << "设置成功" << endl; } void student::setxuehao(char *_xuehao) //设置学号 { strcpy(xuehao, _xuehao); //cout << "申请成功" << endl; } bool student::xuehaopipei(char *_xuehao) //学号是否匹配 { if (strcmp(xuehao, _xuehao) == 0)return true; else return false; } bool student::yanzpipei(char*_yanz) //验证码是否匹配 { if (strcmp(yanz, _yanz) == 0)return true; else return false; } #endif

#ifndef CLASS_H
#define CLASS_H
#include <iostream>
#include <vector>
#include<string.h>
using namespace std;

struct kc
{
	char bianhao[10];
	char name[20];
	int xueshi;
	int xuefen;
	char kaixueinf[10];
};

class course
{
public:
	int cnt=0;    //已添加课程数量
	vector<struct kc> C;
public:
	course();
	void printfc();
	void reinf();
	void deinf();
	void getinf();

};
course::course()
{	
}
void course::printfc()
{
	printf("课程编号,课程名称,课程学时,课程学分,开学时间\n");
	for (int i = 0; i < cnt; i++)
	{
		printf("%s,%s,%d,%d,%s\n", C.at(i).bianhao, C.at(i).name, C.at(i).xueshi, C.at(i).xuefen, C.at(i).kaixueinf);
	}
}
void course::reinf()
{
	char temp[20];
	cout << "请输入课程的编号或者名称" << endl;
	scanf("%s", temp);
	int i = 0;
	for ( i = 0; i < cnt; i++)
	{
		if (strcmp(C.at(i).bianhao, temp) == 0 || strcmp(C.at(i).name, temp) == 0)break;
	}
	printf("查询课程信息为%s,%s,%d,%d,%s\n", C.at(i).bianhao, C.at(i).name, C.at(i).xueshi, C.at(i).xuefen, C.at(i).kaixueinf);
	cout << "请输入修改后的 课程编号,课程名称,课程学时,课程学分,开学时间(xxxx,x,x)" << endl;
	scanf("%s", C.at(i).bianhao);
	scanf("%s", C.at(i).name);
	scanf("%d", &C.at(i).xueshi);
	scanf("%d", &C.at(i).xuefen);
	scanf("%s", C.at(i).kaixueinf);
	cout << "修改成功" << endl;
}
void course::deinf()
{
	char temp[20];
	cout << "请输入课程的编号或者名称" << endl;
	scanf("%s", temp);
	int i = 0;
	for (i = 0; i <cnt; i++)
	{
		if (strcmp(C.at(i).bianhao, temp) == 0 || strcmp(C.at(i).name, temp) == 0)break;
	}
	printf("删除课程信息为%s,%s,%d,%d,%s\n是否确认删除?是输入1,不是输入0", C.at(i).bianhao, C.at(i).name, C.at(i).xueshi, C.at(i).xuefen, C.at(i).kaixueinf);
	int Isde=0;
	cin >> Isde;
	if (Isde)
	{
		C.erase(C.begin() + i);  //参数为迭代器地址
		cnt--;
		cout << "删除成功" << endl;
	}
}
void course::getinf()
{
	int N = 0;
	cout << "请输入要录入的课程数量" << endl;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		struct kc a;
		cout << "请输入 课程编号,课程名称,课程学时,课程学分,开学时间(xxxx.x.x)" << endl;
		scanf("%s", a.bianhao);
		scanf("%s", a.name);
		scanf("%d", &a.xueshi);
		scanf("%d", &a.xuefen);
		scanf("%s", a.kaixueinf);
		//scanf("%s,%s,%d,%s,%d", a.bianhao, a.name, &a.xueshi, a.kaixueinf, &a.xuefen);
		C.push_back(a);
		cnt++;
	}
	cout << "录入完成" << endl;
}


#endif


 直接拿去就可以用了

现有程序在下方的链接里,是完整版哦,比上面的源代码多了文件录入和文件保存

链接:https://pan.baidu.com/s/1Wai-x43E826W3_ZBYA5VaA 
提取码:tgdb 
复制这段内容后打开百度网盘手机App,操作更方便哦

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/181451.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号