⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csstuinfo.cpp

📁 课程设计 学籍管理系统 这个比较简单
💻 CPP
字号:
#include "CsStuInfo.h"
#include <string.h>
#include <conio.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>

void CsStuInfo::mypass(char *password)
{
	char c;
	int i = 0;

	while (1)							//控制密码输入
	{
		c = getch();
		if (c == 8)						//如果是backspace键则回退一个字符
		{
			if (i == 0)					//已经没有字符无需回退
			{
				continue;
			}
			cout << '\b' << flush << ' ' << flush << '\b' << flush; 
			i--;	//下标减1
			password[i] = '\0';			//保证已输入的密码的最后一位是\0
			continue;
		}

		if (c == 13)
		{
			break;
		}

		if ((c>47 && c<58 || c>64 && c<91 || c>96 && c<123) && i<19)	//密码只能包含字母和数字
		{
			cout << '*' << flush;
			password[i] = c;
			i++;
		}
		else
		{
			continue;
		}

		password[i] = '\0';			//正常输入则在末尾加上结束标志
	}
}
CsStuInfo::CsStuInfo()
{
	strcpy(password, "123456");
	
	int i;
	char *p;
	for (i=0; i<5; i++)
	{
		p = new char [20];
		course[i] = p;
	}

	strcpy(course[0], "高等数学");
	credit[0] = 5;
	strcpy(course[1], "大学英语");
	credit[1] = 3;
	strcpy(course[2], "军事理论");
	credit[2] = 3;
	strcpy(course[3], "思修");
	credit[3] = 2;
	strcpy(course[4], "体育");
	credit[4] = 1.5;

	total_credit = 0;
}

CsStuInfo::~CsStuInfo()
{
	int i;
	
	for (i=0; i<course_number; i++)
	{
		delete course[i];
	}
}

void CsStuInfo::set_course()
{
	if (strcmp(major, "通信工程") == 0)
	{
		course[5] = new char [20];
		strcpy(course[5], "通信原理");
		credit[5] = 2;
		course[6] = new char [20];
		strcpy(course[6], "C++");
		credit[6] = 3;
	}

	if (strcmp(major, "某某工程") == 0)
	{
		course[5] = new char [20];
		strcpy(course[5], "某某课1");
		credit[5] = 3;
		course[6] = new char [20];
		strcpy(course[6], "某某课2");
		credit[6] = 3;
		course[7] = new char [20];
		strcpy(course[7], "某某课3");
		credit[7] = 3;
	}
	
	if (strcmp(major, "计算机科学与技术") == 0)
	{
		course[5] = new char [20];
		strcpy(course[5], "计算机科学导论");
		credit[5] = 1;
		course[6] = new char [20];
		strcpy(course[6], "C语言");
		credit[6] = 3;
		course[7] = new char [20];
		strcpy(course[7], "数据结构");
		credit[7] = 4;
		course[8] = new char [20];
		strcpy(course[8], "算法设计与分析");
		credit[8] = 1;
	}
	
	if (strcmp(major, "信息安全") == 0)
	{
		course[5] = new char [20];
		strcpy(course[5], "加密技术");
		credit[5] = 2;
		course[6] = new char [20];
		strcpy(course[6], "C++");
		credit[6] = 3;
		course[7] = new char [20];
		strcpy(course[7], "破译原理");
		credit[7] = 1;
	}
}

void CsStuInfo::output_info()
{
	cout << "\n\n\t\t\t个人信息" << endl;
	cout << "\t\t姓名:" << name << endl
		 << "\t\t学号:" << number << endl
		 << "\t\t性别:" << gender << endl
		 << "\t\t专业:" << major << endl
		 << "\t\t籍贯:" << place <<endl
		 << "\t\t民族:" << nation << endl
		 << "\t\t生日:" << birth << endl
		 << "\t\t政治面貌:" << party << endl
		 << "\t\t身份证号:" << ID << endl;
}

void CsStuInfo::output_score()
{
	int i;
	cout << "\n\n\t\t学期成绩" << endl << endl;
	for (i=0; i<course_number; i++)
	{
		cout << setprecision(1) << setiosflags(ios::fixed)
			 << '\t' << course[i] << ':' << score[i] 
			 << '\t' << "绩点:" << course_gpa[i] 
			 << '\t' << "所获学分:" << credit[i] << endl; 
	}
	cout << "\n\t平均绩点:" << setprecision(3) << setiosflags(ios::fixed) << ave_gpa << "    " 
		 << "所获得的总学分:"  << setprecision(1) << total_credit << endl;
}

void CsStuInfo::calc_gpa()
{
	int i;
	for (i=0; i<course_number; i++)
	{
		if (score[i] < 60)
		{
			course_gpa[i] = 0;
			credit[i] = 0;
		}
		else 
		{
			course_gpa[i] = (float)((score[i] - 50) / 10.0);
		}
		total_credit += credit[i];
	}
}
void CsStuInfo::input()			//从屏幕输入学生信息
{
	char ch;
	bool t;
	cout << "\t\t\t请按提示输入:" << endl;

	cout <<	"\t\t学号:";
	cin >> number;

	cout << "\t\t姓名:";
	cin >> name;

	cout << "\t\t性别:" << endl;
	t = true;
	while (t)
	{
		cout << "\t\t1.男 2.女" << "\n\t\t请选择:" << flush;
		ch = getch();
		switch(ch)
		{
			case '1':
				strcpy(gender, "男\0");
				cout << "男" << endl;
				t = false;
				break;
			case '2':
				strcpy(gender, "女\0");
				cout << "女" << endl;
				t = false;
				break;
			default:
				cout << "错误!" << endl;
				break;
		}//end of switch
	}//end of while
				
	cout << "\t\t籍贯:";
	cin >> place;

	cout << "\t\t民族:";
	cin >> nation;

	cout << "\t\t生日(如19890718):";
	cin >> birth;

	cout << "\t\t政治面貌:" << endl;
	t = true;
	while (t)
	{
		cout << "\t\t1.团员 2.党员 3.群众" << "\n\t\t请选择:" << flush;
		ch = getch();
		switch(ch)
		{
			case '1':
				strcpy(party, "团员\0");
				cout << "团员" << endl;
				t = false;
				break;
			case '2':
				strcpy(party, "党员\0");
				cout << "党员" << endl;
				t = false;
				break;
			case '3':
				strcpy(party, "群众\0");
				cout << "群众" << endl;
				t = false;
				break;
			default:
				cout << "错误!" << endl;
				break;
		}//end of switch
	}//end of while
	
	cout << "\t\t身份证号:";
	cin >> ID;

	cout << "\t\t专业:" << endl;;
	t = true;
	while (t)
	{
		cout << "\t\t1.通信工程	2.某某工程" << endl;
		cout << "\t\t3.计算机科学与技术 4.信息安全" << endl;
		cout << "\t\t请选择:" << flush;
		ch = getch();
		switch(ch)
		{
			case '1':
				strcpy(major, "通信工程");
				cout << "通信工程" << endl;
				course_number = 7;
				t = false;
				break;
			case '2':
				strcpy(major, "某某工程");
				cout << "某某工程" << endl;
				course_number = 8;
				t = false;
				break;
			case '3':
				strcpy(major, "计算机科学与技术");
				cout << "计算机科学与技术" << endl;
				course_number = 9;
				t = false;
				break;
			case '4':
				strcpy(major, "信息安全");
				cout << "信息安全" << endl;
				course_number = 8;
				t = false;
				break;
			default:
				cout << endl;
				break;
		}
	}

	set_course();
	int i;
	cout << "\n\n\t请输入对应科目的成绩:" << endl;
	for (i=0; i<course_number; i++)
	{
		cout << "\t\t" << course[i] << ":";
		cin >> score[i];
	}
	calc_gpa();
	calc_ave_gpa();
}

void CsStuInfo::output()
{
	cout << "\n\n\t\t姓名:" << name << endl
		 << "\t\t学号:" << number << endl
		 << "\t\t性别:" << gender << endl
		 << "\t\t专业:" << major << endl
		 << "\t\t籍贯:" << place <<endl
		 << "\t\t民族:" << nation << endl
		 << "\t\t生日:" << birth << endl
		 << "\t\t政治面貌:" << party << endl
		 << "\t\t身份证号:" << ID << endl;

	int i;
	cout << "\t学科成绩:" << endl;
	for (i=0; i<course_number; i++)
	{
		cout << setprecision(1) << setiosflags(ios::fixed)
			 << '\t' << course[i] << ':' << score[i] 
			 << '\t' << "绩点:" << course_gpa[i] 
			 << '\t' << "所获学分:" << credit[i] << endl; 
	}
	cout << "\n\t平均绩点:" << setprecision(3) << setiosflags(ios::fixed) << ave_gpa << "    " 
		 << "所获得的总学分:"  << setprecision(1) << total_credit << endl;
}

void CsStuInfo::calc_ave_gpa()
{
	int i;
	ave_gpa = 0;
	for (i=0; i<course_number; i++)
	{
		ave_gpa += course_gpa[i] * (credit[i] / total_credit);
	}
}
void CsStuInfo::finput(CsStuInfo *p, ifstream &datafile)		//从文件中读取学生信息
{
	datafile >> p->name >> p->number >> p->gender >> p->major >> p->place >> p->nation >> p->birth >> p->party >> ID
			 >> p->course_number >> p->password;

	int i;
	for (i=0; i<course_number; i++)
	{
		course[i] = new char [20];
		datafile >> p->course[i] >> p->score[i] >> p->credit[i] >> p->course_gpa[i];
	}
	datafile >> p->total_credit >> p->ave_gpa;
}

void CsStuInfo::foutput(ofstream &datafile)		//将学生信息存入文件
{
	datafile << name 
			 << ' ' << number 
			 << ' ' << gender 
			 << ' ' << major 
			 << ' ' << place 
			 << ' ' << nation 
			 << ' ' << birth 
			 << ' ' << party 
			 << ' ' << ID 
			 << ' ' <<course_number 
			 << ' ' << password;

	int i;
	for (i=0; i<course_number; i++)
	{
		datafile << ' ' << course[i] 
				 << ' ' << score[i] 
				 << ' ' << credit[i] 
			     << ' ' << course_gpa[i] << ' ';
	}
	datafile << total_credit << ' ' 
			 << ave_gpa << ' ';
}		

void CsStuInfo::reset_password()
{
	char s[20], s1[20], s2[20];

	cout << "\n\n\t\t修改密码" << endl << endl;
	cout << "\t\t密码只能包含字母和数字,且长度小于20!" << endl << endl;
	cout << "\n\t\t请输入原密码:" << flush;
	mypass(s);
	if (strcmp(s, password) != 0)	//原密码错误则直接返回主菜单 
	{
		cout << "\n\t\t\t密码错误!" << endl;
		return ;
	}
	
	while (1)
	{
		system("cls");
		cout << "\n\n\t\t请输入新密码:" << flush;
		mypass(s1);
		cout << "\n\t\t请确认新密码:" << flush;
		mypass(s2);
		if (strcmp(s1, s2) != 0)
		{
			cout << "\n\t\t两次输入的密码不相同!" << flush
				 << "\n\t\t请按任意键重新输入!" << flush;
			getch();
			system("cls");
		}
		else
		{
			strcpy(password, s1);
			cout << "\n\t\t修改密码成功!" << flush;
			return ;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -