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] == ',' \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

#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,操作更方便哦

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • QQ盗号软件后门分析与反击

    QQ盗号软件后门分析与反击来源:fhod’sBlog作者:fhod小财说明:文章已发表于***手册07年10期,转载请注明出处!对明小子QQ密码特工软件的分析—-小财今天无聊给一朋友讲解QQ盗取原理,从网上找了一个工具“明小子QQ密码特工”结果发现这个软件有后门。下面就让我带着大家来分析一下。首先我们用nod32来查一下有没有毒。图1看到了吧没有病毒。我们把监控打开…

    2022年6月15日
    42
  • 长亮科技中报业绩_2018年年报汇总

    长亮科技中报业绩_2018年年报汇总长亮科技发布2018年报:营收首破十亿元,直面蚂蚁金服竞争压力

    2022年4月21日
    46
  • mysql 行转列 (带日期)

    mysql 行转列 (带日期)从网上找了很多行转列的。基本都是2行的行转列。不带日期分组的。借鉴了另一个哥们的文章,实现了自己想要的结果,写出来大家可以参考。以后自己遇到同样情况,也可以有个备份借鉴的地址为https://www.cnblogs.com/gisblogs/p/3966822.html处理过程:我自己有的数据,这个已经是处理后的(源数据)图1[img]http:/…

    2022年5月16日
    42
  • 世界一级行政区划图_世界行政区划图册

    世界一级行政区划图_世界行政区划图册序号 国家 省 城市 8168 波兰 下西里西亚省   8169 波兰 下西里西亚省 下布热格 8170 波兰 下西里西亚省 佩希采 8171 波兰 下西里西亚省 克沃兹科 8172 波兰 下西里西亚省 兹戈热莱茨 8173 波兰 下西里西亚省 兹沃托雷亚 8174 波兰 下西里西亚省 博莱斯瓦维茨 8175 波兰 下西里

    2022年9月29日
    5
  • 树莓派python编程入门与实战_树莓派python软件

    树莓派python编程入门与实战_树莓派python软件一、远程连接和远程桌面设置:终端下执行命令:ifconfig,查看树莓派的IP终端下执行命令:sudoapt-getinstallxrdp,安装远程桌面支持。在windows电脑上点开始,输入mstsc,出来远程桌面界面,输入树莓派IP,用户名:pi密码raspberry,就可以连上了。二、关闭树莓派正确操作:方式一:终端下执行命令:sudopoweroff…

    2022年10月15日
    5
  • 网站优化工具-YUI Compressor「建议收藏」

    网站优化工具-YUI Compressor「建议收藏」一、简介YUICompressor,专用于压缩js和css文件,可以有效降低js和css文件占用的空间;如,将使用YUICompressor压缩过的js和css文件部署到网站的生产环境,有效降低浏览器下载相关资源的时延,提升用户体验。二、压缩工具YUI-Compressor英文官网:http://yui.github.io/yuicompressor/GitHub-YUI:https://github.com/yui/yuicompressor在线YUI:http://ganquan.inf

    2022年7月18日
    19

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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