学生成绩管理系统(简易本地版)

学生成绩管理系统(简易本地版)

一、概述

平台:Windows 10 ,Microsoft Visual Studio 2017
语言:C++,面向过程
完成日期:2018/12/27
主要功能:
1. 添加学生的信息(包括学号,姓名,性别,成绩)
2. 显示学生的信息
3.查询学生的信息( 以学号或姓名的方式查询)
4.修改学生的信息
5.保存学生的信息(txt文件)
6.删除和排序学生的信息,暂不支持
除此外还用Windows.h头文件里面的光标定位函数做了一个键盘操作界面和小动画。

二、 用到了哪些知识?
1.C++基本的语法(结构体,函数,输入输出流,文件操作流等)
2.system函数

  • 函数原型:int system(const char *command);
  • 头文件:<cstdlib> 或 <process.h>
  • 功能:在C++代码中执行 DOS (Disk Operation System,磁盘操作系统) 指令。
  • 常用的函数:
    system(“cls”) //清屏
    system(“pause”) //按任意键
    system(“title xxx”)//设置标题为xxx
    system(“color 02”)// 黑底绿字
    在这里插入图片描述

三、主要功能的说明
1. 头文件预览

//student.h
#pragma once
#include <iostream>
#include <cstdlib>//exit()函数
#include <Windows.h>//光标定位
#include <fstream>//C++ I/O流
#include <string>
#include <conio.h>
using namespace std;
void SetPos(COORD a);//光标定位
void SetPos(int i, int j);
void HideCursor();//隐藏光标
void show();//展现学生信息
void input();//录入信息
void search();//查找信息
void print();//保存本地txt文件
void load();//加载动画
void modify();//修改信息
void menu_flash();//菜单子模块
int menu_choose();
void theme();//选择背景色
void menu();//主菜单
void help();//开局动画之一

2.关于一些变量的说明
首先定义了一个结构体student,并申明了一个students。

struct student
{
	string Number;
	string Name;
	string Sex;
	int Clanguage;
	int English;
	int Math;
};

student students;
const char *txtfile = "2333.txt";//文件名
const char *datfile = "2333.dat";

ifstream a;//a和b都对dat操作
ofstream b;
ofstream d;//d对txt操作
string file;//对txt重命名
string endline = ".txt";//添加后缀,保存为txt文件时用于重命名
int ct = 1;//指针位置+1,用于修改时确认指针的位置

3.主要函数说明
(1)录入学生信息
直接打开dat文件进行输入,最后记得要关闭文件。

void input()
{
	system("cls");
	b.open(datfile, ios_base::binary | ios_base::out | ios_base::app);
	if (!b.is_open())
	{
		cout << "\a文件打开失败,请稍后重试." << endl;
		exit(EXIT_FAILURE);
	}

	int c = 1;
	cout << "格式:\t";
	cout << "学号\t\t姓名\t性别\t\tC++成绩\t\t英语成绩\t\t高等数学" << endl;
	cout << "               各项信息间以空格隔开\n";
	while (c)
	{
		cin >> students.Number;
		cin >> students.Name;
		cin >> students.Sex;
		cin >> students.Clanguage;
		cin >> students.English;
		cin >> students.Math;
		b.write((char *)&students, sizeof students);
		cout << "0 ———— 退出   1 ———— 继续输入:";
		cin >> c;
	}
	b.close();
}

(2)显示学生的信息
其中的变量ct为序号,用于修改信息时确认指针的位置。

void show()//打开dat文件并输出到界面上
{
	system("cls");
	ct = 1;
	a.open(datfile, ios_base::binary | ios_base::in);
	if (a.is_open())
	{
		cout << "\t\t\t学生信息表:\n\n";
		cout << "序号\t学号\t\t姓名\t性别\tC++\t英语\t高等数学" << endl;
		while (a.read((char *)&students, sizeof students))
		{
			cout << ct++ << "\t"
				<< students.Number << "\t"
				<< students.Name << "\t"
				<< students.Sex << "\t"
				<< students.Clanguage << "\t"
				<< students.English << "\t"
				<< students.Math << endl;
		}
		a.close();
	}
	else
	{
		cout << "\a信息加载失败!请初始化后重试!";
	}
}

(3)查询学生的信息
打开dat文件,获取学生的信息,根据用户的选择来搜索比较对应信息。如果相等,则输出该学生信息,否则代表无该学生的信息。
变量choose用来响应用户的操作(退出,姓名查找和学号查找);
变量flag用来确认是否查找成功;
最后别忘了关闭文件。

void search()//
{
	system("cls");
	int choose;
	while (1)
	{
		a.open(datfile, ios_base::binary | ios_base::in);
		cout << "0 ———— 退出  1 ———— 按姓名查找  2 ———— 按学号查找\n";
		cin >> choose;
		string name;
		string num;
		if (choose == 0)
		{
			a.close();
			return;
		}
		if (choose == 1)
		{
			cout << "请输入查找姓名:";
			cin >> name;
		}
		if (choose == 2)
		{
			cout << "请输入查找学号";
			cin >> num;
		}
		if (a.is_open())
		{
			int flag = 0;//判断是否找到
			cout << "学号\t姓名\t性别\tC++\t英语\t高等数学" << endl;
			while (a.read((char *)&students, sizeof students))
			{
				if (choose == 1 && students.Name == name)
				{
					cout << students.Number << "\t"
						<< students.Name << "\t"
						<< students.Sex << "\t"
						<< students.Clanguage << "\t" << students.English << "\t"
						<< students.Math << endl;
					flag = 1;
				}
				if (choose == 2 && students.Number == num)
				{
					cout << students.Number << "\t"
						<< students.Name << "\t"
						<< students.Sex << "\t"
						<< students.Clanguage << "\t" << students.English << "\t"
						<< students.Math << endl;
					flag = 1;
				}
			}
			if (flag == 0)
			{
				cout << "查询不到此信息!\n";
			}
		}
		else
		{
			cout << "\a信息加载失败!请初始化后重试!";
		}
		a.close();
	}
}

(4)修改学生的信息
变量a_1的类型为fstream,可读可写。
根据序号确认被修改的学生的信息在文件中的位置,并进行重新输入。

void modify()//修改
{
	fstream a_1;
	a_1.open(datfile, ios_base::in | ios_base::out | ios_base::binary);
	if (a_1.is_open())
	{
		int point;//想修改的数字
		int end = 1;//
		while (end)
		{
			show();
			cout << "0 ———— 退出";
			cout << "请输入对应序号:";
			cin >> point;
			if (point >= 1 && point <= ct - 1)
			{
				streampos place = (point - 1) * sizeof students;
				a_1.seekg(place);
				if (a_1.fail())
				{
					cout << "查找错误...\n";
					exit(EXIT_FAILURE);
				}

				a_1.read((char *)&students, sizeof students);
				cout << "您即将修改的信息如下:\n";
				cout << point << "\t\t"
					<< students.Number << "\t"
					<< students.Name << "\t"
					<< students.Sex << "\t"
					<< students.Clanguage << "\t"
					<< students.English << "\t"
					<< students.Math << endl;


				if (a_1.eof())
				{
					a_1.clear();
				}

				cout << "学号:________\b\b\b\b\b\b";
				cin >> students.Number;
				cout << "姓名:________\b\b\b\b\b\b";
				cin >> students.Name;
				cout << "性别:___\b\b\b";
				cin >> students.Sex;
				cout << "C++:___\b\b\b";
				cin >> students.Clanguage;
				cout << "英语:___\b\b\b";
				cin >> students.English;
				cout << "高等数学:___\b\b\b";
				cin >> students.Math;

				a_1.seekp(place);
				a_1.write((char *)&students, sizeof students);
				if (a_1.fail())
				{
					cout << "写入错误\n";
					exit(EXIT_FAILURE);
				}


				show();
				cout << "是否继续修改?\n"
					<< "0 ———— 退出  1 ———— 继续";
				cin >> end;
				if (end == 0)
					a_1.close();
				system("cls");
			}
			else if (point == 0)
			{
				a_1.close();
				return;
			}
			else
			{
				cout << "\a输入的数字不在有效范围" << "(" << 1 << "~" << ct - 1 << ")"
					<< "内,请重新输入.\n";
				system("pause");
				system("cls");
			}
		}

	}
	else
	{
		cout << "\a无法打开" << datfile << endl;
	}
}

(5)保存学生的信息
打开dat文件,创建并打开txt文件,将dat文件内的信息写入txt文件,写入后关闭dat和txt文件,完成操作。
在这里,提供了重命名操作,最终文件会以txt格式保存在程序所在的目录。

void print()
{
	system("cls");
	a.open(datfile, ios_base::binary | ios_base::in);
	if (a.is_open())
	{
		cout << "文件名:" << txtfile << ",是否修改文件名?\n";
		cout << "  /\\  0 ———— 否" << endl;
		cout << " /!!\\ 1 ———— 是" << endl;
		cout << "/    \\若文件夹中出现同名文件,可能将其覆盖.\n"
			<< " ̄ ̄ ̄\n";

		int answer;
		while (1)//修改文件名
		{
			cin >> answer;
			if (answer == 1)
			{
				cout << "请输入文件名 (不要加后缀):";
				cin >> file;
				d.open((file + endline), ios_base::out);
				break;
			}
			else if (answer == 0)
			{
				d.open(txtfile, ios_base::out);
				break;
			}
			else
			{
				cout << "输入错误,请重新输入!\n";
				continue;
			}
		}

		if (d.is_open())
		{
			d << "学号\t姓名\t性别\t\tC++\t\t英语\t\t高等数学\n";
			while (a.read((char *)&students, sizeof students))
			{
				d << students.Number << "\t"
					<< students.Name << "\t"
					<< students.Sex << "\t\t"
					<< students.Clanguage << "\t\t" << students.English << "\t\t"
					<< students.Math << endl;
			}
			cout << "保存成功!";
			cout << "您的文件名为" << (answer == 1 ? (file + endline) : txtfile);
			cout << "请及时提取相关文件,以免文件失效或损坏\n";
			d.close();
		}
		a.close();
	}
	else
	{
		cout << "\a文件载入失败,请稍后重试.\n";
	}
}

(6)其他部分
加载动画

void load()//动画1
{
	system("pause");
	system("cls");
	SetPos(50, 14);
	string LOAD = "加载中";
	cout << LOAD;
	for (int i = 0; i < 6; i++)
	{
		Sleep(150);
		cout << ".";
	}
	system("cls");
}

void help()//动画2
{
	Sleep(100);
	system("cls");
	system("color 0E");
	SetPos(12, 7);
	cout << "☆☆★★★★★★★★★★★★★★★★★★★☆☆";
	SetPos(12, 8);
	cout << "☆★                 ★☆";
	SetPos(12, 9);
	cout << "☆★                   ★★★   ★★★ ★☆";
	SetPos(12, 10);
	cout << "☆★ 	       ★☆☆☆★☆★☆☆☆★ ★☆  ";
	SetPos(12, 11);
	cout << "☆★  ★★    ★★☆☆☆★☆☆☆☆★ ★☆";
	SetPos(12, 12);
	cout << "☆★ ★☆☆★ ★★☆★☆☆☆☆☆☆☆★ ★☆ ";
	SetPos(12, 13);
	cout << "☆★ ★☆☆☆★☆☆★★☆☆☆☆☆☆★  ★☆ ";
	SetPos(12, 14);
	cout << "☆★  ★☆☆☆☆☆★★☆☆☆☆☆★   ★☆";
	SetPos(12, 15);
	cout << "☆★   ★☆☆☆★  ★☆☆☆★    ★☆  ";
	SetPos(12, 16);
	cout << "☆★    ★☆★     ★      ★☆  ";
	SetPos(12, 17);
	cout << "☆★     ★                 ★☆  ";
	SetPos(12, 18);
	cout << "☆★  Ich/liebe/dich制作       ★☆";
	SetPos(12, 19);
	cout << "☆☆★★★★★★★★★★★★★★★★★★★☆☆★★★";
	Sleep(1000);
	system("cls");
	system("color 0F");
}

菜单界面(键盘操作)
主要思路:用户输入操作时,光标会向指定方向移动,移动后对应的值会发生改变,当用户确认操作时,对应的值会代入特定函数计算,并返回这个计算出的值,根据这个值来确认要调用哪一个函数(switch)。

/***************************
*****以下为菜单操作子模块***
*************************/

void menu_flash()
{
	for (int i = 12; i <= 18; i++)
	{
		SetPos(42, i);
		cout << " ";
	}
}

/***************************
*****以下为菜单操作模块*****
**************************/

int menu_choose()
{
	int j = 13;
	while (1)
	{
		if (_kbhit())
		{
			char x = _getch();
			switch (x)
			{
			case 'w':
			{
				if (j == 13 || j == 14 || j == 15 || j == 16 || j == 17 || j == 18 || j == 19)
				{
					menu_flash();
					j = j - 1;
					SetPos(42, j);
					cout << ">>";
				}
				else if (j == 12 && x == 'w')
				{
					j = 19;
				}
				break;
			}
			case 's':
			{
				if (j == 11 || j == 12 || j == 13 || j == 14 || j == 15 || j == 16 || j == 17)
				{
					menu_flash();
					j = j + 1;
					SetPos(42, j);
					cout << ">>";
				}
				else if (j == 18 && x == 's')
				{
					j = 11;
				}
				break;
			}
			case 'k':
			{
				return j - 11;
			}
			}
		}
	}
}

/***************************
*******以下为菜单界面*******
**************************/
void menu()
{
	system("cls");
	SetPos(43, 5);
	string title = "学生成绩管理系统";

	for (int i = 0; i < title.size(); i++)
	{
		Sleep(40);
		cout << title[i];
	}
	SetPos(12, 7);
	cout << " ______________________________________________________________________________ ";
	SetPos(12, 8);
	cout << "|             w : 上            s : 下          k : 确认                        |";
	for (int i = 9; i <= 10; i++)
	{
		SetPos(12, i);
		cout << "|                                                                               |";
	}
	SetPos(12, 11);
	cout << "|  ***************************************************************************  |";
	SetPos(12, 12);
	cout << "|  ************************      1.录入信息     ******************************  |";
	SetPos(12, 13);
	cout << "|  ************************      2.查看信息     ******************************  |";
	SetPos(12, 14);
	cout << "|  ************************      3.修改信息     ******************************  |";
	SetPos(12, 15);
	cout << "|  ************************      4.打印文件     ******************************  |";
	SetPos(12, 16);
	cout << "|  ************************      5.  搜索       ******************************  |";
	SetPos(12, 17);
	cout << "|  ************************      6.  主题       ******************************  |";
	SetPos(12, 18);
	cout << "|  ************************      7.  关于       ******************************  |";
	SetPos(12, 19);
	cout << "|  ***************************************************************************  |";
	for (int i = 20; i <= 22; i++)
	{
		SetPos(12, i);
		cout << "|                                                                               |";
	}
	SetPos(12, 23);
	cout << "  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ";
}

四,效果
打开界面时的动画
在这里插入图片描述
主界面
在这里插入图片描述
在没有初始化(录入信息)前进行操作
在这里插入图片描述
录入信息
在这里插入图片描述
查看信息
在这里插入图片描述
保存本地文档:
在这里插入图片描述

保存本地txt文档:
在这里插入图片描述

五,源代码
1.头文件(student.h)

#pragma once
#include <iostream>
#include <cstdlib>//exit()函数
#include <Windows.h>//光标定位
#include <fstream>//C++ I/O流
#include <string>
#include <conio.h>
using namespace std;
void SetPos(COORD a);//光标定位
void SetPos(int i, int j);
void HideCursor();//隐藏光标
void show();//展现学生信息
void input();//录入信息
void search();//查找信息
void print();//保存本地txt文件
void load();//加载动画
void modify();//修改信息
void menu_flash();//菜单子模块
int menu_choose();
void theme();//选择背景色
void menu();//主菜单
void help();//开局动画之一

2.student.cpp

#include "student.h"

struct student
{
	string Number;
	string Name;
	string Sex;
	int Clanguage;
	int English;
	int Math;
};

const char *txtfile = "2333.txt";//文件名
const char *datfile = "2333.dat";
student students;

ifstream a;//a和b都对dat操作
ofstream b;
ofstream d;//d对txt操作
string file;//对txt重命名
string endline = ".txt";//添加后缀
int ct = 1;//指针位置+1

void SetPos(COORD a)// set cursor 
{
	HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(out, a);
}

void SetPos(int i, int j)// set cursor
{
	COORD pos = { i, j };
	SetPos(pos);
}

void show()//打开dat文件并输出到界面上
{
	system("cls");
	ct = 1;
	a.open(datfile, ios_base::binary | ios_base::in);
	if (a.is_open())
	{
		cout << "\t\t\t学生信息表:\n\n";
		cout << "序号\t学号\t\t姓名\t性别\tC++\t英语\t高等数学" << endl;
		while (a.read((char *)&students, sizeof students))
		{
			cout << ct++ << "\t\t"
				<< students.Number << "\t"
				<< students.Name << "\t"
				<< students.Sex << "\t"
				<< students.Clanguage << "\t"
				<< students.English << "\t"
				<< students.Math << endl;
		}
		a.close();
	}
	else
	{
		cout << "\a信息加载失败!请初始化后重试!";
	}
}

/***************************
*****输出为录入信息模块*****
*************************/
void input()
{
	system("cls");
	b.open(datfile, ios_base::binary | ios_base::out | ios_base::app);
	if (!b.is_open())
	{
		cout << "\a文件打开失败,请稍后重试." << endl;
		exit(EXIT_FAILURE);
	}

	int c = 1;
	cout << "格式:\t";
	cout << "学号\t\t姓名\t性别\t\tC++成绩\t\t英语成绩\t\t高等数学" << endl;
	cout << "               各项信息间以空格隔开\n";
	while (c)
	{
		cin >> students.Number;
		cin >> students.Name;
		cin >> students.Sex;
		cin >> students.Clanguage;
		cin >> students.English;
		cin >> students.Math;
		b.write((char *)&students, sizeof students);
		cout << "0 ———— 退出   1 ———— 继续输入:";
		cin >> c;
	}
	b.close();
}

/***************************
*****输出为搜索信息模块*****
*************************/
void search()//
{
	system("cls");
	int choose;
	while (1)
	{
		a.open(datfile, ios_base::binary | ios_base::in);
		cout << "0 ———— 退出  1 ———— 按姓名查找  2 ———— 按学号查找\n";
		cin >> choose;
		string name;
		string num;
		if (choose == 0)
		{
			a.close();
			return;
		}
		if (choose == 1)
		{
			cout << "请输入查找姓名:";
			cin >> name;
		}
		if (choose == 2)
		{
			cout << "请输入查找学号";
			cin >> num;
		}
		if (a.is_open())
		{
			int flag = 0;//判断是否找到
			cout << "学号\t姓名\t性别\tC++\t英语\t高等数学" << endl;
			while (a.read((char *)&students, sizeof students))
			{
				if (choose == 1 && students.Name == name)
				{
					cout << students.Number << "\t"
						<< students.Name << "\t"
						<< students.Sex << "\t"
						<< students.Clanguage << "\t" << students.English << "\t"
						<< students.Math << endl;
					flag = 1;
				}
				if (choose == 2 && students.Number == num)
				{
					cout << students.Number << "\t"
						<< students.Name << "\t"
						<< students.Sex << "\t"
						<< students.Clanguage << "\t" << students.English << "\t"
						<< students.Math << endl;
					flag = 1;
				}
			}
			if (flag == 0)
			{
				cout << "查询不到此信息!\n";
			}
		}
		else
		{
			cout << "\a信息加载失败!请初始化后重试!";
		}
		a.close();
	}
}

/***************************
*****输出为本地txt文件*****
*************************/
void print()
{
	system("cls");
	a.open(datfile, ios_base::binary | ios_base::in);
	if (a.is_open())
	{
		cout << "文件名:" << txtfile << ",是否修改文件名?\n";
		cout << "  /\\  0 ———— 是" << endl;
		cout << " /!!\\ 1 ———— 否" << endl;
		cout << "/    \\若文件夹中出现同名文件,可能将其覆盖.\n"
			<< " ̄ ̄ ̄\n";

		int answer;
		while (1)//修改文件名
		{
			cin >> answer;
			if (answer == 1)
			{
				cout << "请输入文件名 (不要加后缀):";
				cin >> file;
				d.open((file + endline), ios_base::out);
				break;
			}
			else if (answer == 0)
			{
				d.open(txtfile, ios_base::out);
				break;
			}
			else
			{
				cout << "输入错误,请重新输入!\n";
				continue;
			}
		}

		if (d.is_open())
		{
			d << "学号\t姓名\t性别\t\tC++\t\t英语\t\t高等数学\n";
			while (a.read((char *)&students, sizeof students))
			{
				d << students.Number << "\t"
					<< students.Name << "\t"
					<< students.Sex << "\t\t"
					<< students.Clanguage << "\t\t" << students.English << "\t\t"
					<< students.Math << endl;
			}
			cout << "保存成功!";
			cout << "您的文件名为" << (answer == 1 ? (file + endline) : txtfile);
			cout << "请及时提取相关文件,以免文件失效或损坏\n";
			d.close();
		}
		a.close();
	}
	else
	{
		cout << "\a文件载入失败,请稍后重试.\n";
	}
}

/***************************
*****以下为界面加载动画*****
**************************/

void load()
{
	system("pause");
	system("cls");
	SetPos(50, 14);
	string LOAD = "加载中";
	cout << LOAD;
	for (int i = 0; i < 6; i++)
	{
		Sleep(150);
		cout << ".";
	}
	system("cls");
}

/***************************
*****以下为修改信息模块*****
*************************/
void modify()//修改
{
	fstream a_1;
	a_1.open(datfile, ios_base::in | ios_base::out | ios_base::binary);
	if (a_1.is_open())
	{
		int point;//想修改的数字
		int end = 1;
		while (end)
		{
			show();
			cout << "0 ———— 退出";
			cout << "请输入对应序号:";
			cin >> point;
			if (point >= 1 && point <= ct - 1)
			{
				streampos place = (point - 1) * sizeof students;
				a_1.seekg(place);
				if (a_1.fail())
				{
					cout << "查找错误...\n";
					exit(EXIT_FAILURE);
				}

				a_1.read((char *)&students, sizeof students);
				cout << "您即将修改的信息如下:\n";
				cout << point << "\t\t"
					<< students.Number << "\t"
					<< students.Name << "\t"
					<< students.Sex << "\t"
					<< students.Clanguage << "\t"
					<< students.English << "\t"
					<< students.Math << endl;


				if (a_1.eof())
				{
					a_1.clear();
				}

				cout << "学号:________\b\b\b\b\b\b";
				cin >> students.Number;
				cout << "姓名:________\b\b\b\b\b\b";
				cin >> students.Name;
				cout << "性别:___\b\b\b";
				cin >> students.Sex;
				cout << "C++:___\b\b\b";
				cin >> students.Clanguage;
				cout << "英语:___\b\b\b";
				cin >> students.English;
				cout << "高等数学:___\b\b\b";
				cin >> students.Math;

				a_1.seekp(place);
				a_1.write((char *)&students, sizeof students);
				if (a_1.fail())
				{
					cout << "写入错误\n";
					exit(EXIT_FAILURE);
				}


				show();
				cout << "是否继续修改?\n"
					<< "0 ———— 退出  1 ———— 继续";
				cin >> end;
				if (end == 0)
					a_1.close();
				system("cls");
			}
			else if (point == 0)
			{
				a_1.close();
				return;
			}
			else
			{
				cout << "\a输入的数字不在有效范围" << "(" << 1 << "~" << ct - 1 << ")"
					<< "内,请重新输入.\n";
				system("pause");
				system("cls");
			}
		}

	}
	else
	{
		cout << "\a无法打开" << datfile << endl;
	}
}
/***************************
*****以下为菜单操作子模块***
*************************/

void menu_flash()
{
	for (int i = 12; i <= 18; i++)
	{
		SetPos(42, i);
		cout << " ";
	}
}

/***************************
*****以下为菜单操作模块*****
**************************/

int menu_choose()
{
	int j = 13;
	while (1)
	{
		if (_kbhit())
		{
			char x = _getch();
			switch (x)
			{
			case 'w':
			{
				if (j == 13 || j == 14 || j == 15 || j == 16 || j == 17 || j == 18 || j == 19)
				{
					menu_flash();
					j = j - 1;
					SetPos(42, j);
					cout << ">>";
				}
				else if (j == 12 && x == 'w')
				{
					j = 19;
				}
				break;
			}
			case 's':
			{
				if (j == 11 || j == 12 || j == 13 || j == 14 || j == 15 || j == 16 || j == 17)
				{
					menu_flash();
					j = j + 1;
					SetPos(42, j);
					cout << ">>";
				}
				else if (j == 18 && x == 's')
				{
					j = 11;
				}
				break;
			}
			case 'k':
			{
				return j - 11;
			}
			}
		}
	}
}

void theme()
{
	system("cls");
	cout << "0.退出\n1.黄色\n2.绿色\n3.典雅白\n4.经典黑(默认)\n";
	cout << "请选择:";
	int i;
	cin >> i;
	switch (i)
	{
	case 4:
	{
		cout << "经典黑";
		system("color 07");//黑底白字
		system("pause");
		break;
	}
	case 3:
	{
		cout << "典雅白";
		system("color F0");//白底黑字
		system("pause");
		break;

	}
	case 2:
	{
		cout << "绿色";
		system("color 0A");//黑的浅绿
		system("pause");
		break;
	}
	case 1:
	{
		cout << "黄色";
		system("color E0");//浅黄底黑字
		system("pause");
		break;
	}
	case 0:
		return;
	}
}
/***************************
*******以下为菜单界面*******
**************************/
void menu()
{
	system("cls");
	SetPos(43, 5);
	string title = "学生成绩管理系统";

	for (int i = 0; i < title.size(); i++)
	{
		Sleep(40);
		cout << title[i];
	}
	SetPos(12, 7);
	cout << " ______________________________________________________________________________ ";
	SetPos(12, 8);
	cout << "|             w : 上            s : 下          k : 确认                        |";
	for (int i = 9; i <= 10; i++)
	{
		SetPos(12, i);
		cout << "|                                                                               |";
	}
	SetPos(12, 11);
	cout << "|  ***************************************************************************  |";
	SetPos(12, 12);
	cout << "|  ************************      1.录入信息     ******************************  |";
	SetPos(12, 13);
	cout << "|  ************************      2.查看信息     ******************************  |";
	SetPos(12, 14);
	cout << "|  ************************      3.修改信息     ******************************  |";
	SetPos(12, 15);
	cout << "|  ************************      4.打印文件     ******************************  |";
	SetPos(12, 16);
	cout << "|  ************************      5.  搜索       ******************************  |";
	SetPos(12, 17);
	cout << "|  ************************      6.  主题       ******************************  |";
	SetPos(12, 18);
	cout << "|  ************************      7.  关于       ******************************  |";
	SetPos(12, 19);
	cout << "|  ***************************************************************************  |";
	for (int i = 20; i <= 22; i++)
	{
		SetPos(12, i);
		cout << "|                                                                               |";
	}
	SetPos(12, 23);
	cout << "  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ";
}
/*****************
**开局动画之一****
****************/
void help()
{
	Sleep(100);
	system("cls");
	system("color 0E");
	SetPos(12, 7);
	cout << "☆☆★★★★★★★★★★★★★★★★★★★☆☆";
	SetPos(12, 8);
	cout << "☆★                 ★☆";
	SetPos(12, 9);
	cout << "☆★                   ★★★   ★★★ ★☆";
	SetPos(12, 10);
	cout << "☆★ 	       ★☆☆☆★☆★☆☆☆★ ★☆  ";
	SetPos(12, 11);
	cout << "☆★  ★★    ★★☆☆☆★☆☆☆☆★ ★☆";
	SetPos(12, 12);
	cout << "☆★ ★☆☆★ ★★☆★☆☆☆☆☆☆☆★ ★☆ ";
	SetPos(12, 13);
	cout << "☆★ ★☆☆☆★☆☆★★☆☆☆☆☆☆★  ★☆ ";
	SetPos(12, 14);
	cout << "☆★  ★☆☆☆☆☆★★☆☆☆☆☆★   ★☆";
	SetPos(12, 15);
	cout << "☆★   ★☆☆☆★  ★☆☆☆★    ★☆  ";
	SetPos(12, 16);
	cout << "☆★    ★☆★     ★      ★☆  ";
	SetPos(12, 17);
	cout << "☆★     ★                 ★☆  ";
	SetPos(12, 18);
	cout << "☆★  Ich/liebe/dich制作       ★☆";
	SetPos(12, 19);
	cout << "☆☆★★★★★★★★★★★★★★★★★★★☆☆★★★";
	Sleep(1000);
	system("cls");
	system("color 0F");
}

3.main.cpp

#include "student.h"
void main()
{
	system("title 学生成绩管理系统");
	cout << right;
	help();
	while (1)
	{
		load();
		
		menu();
		int k = menu_choose();
		switch (k)
		{
		case 1:
		{
			input();
			break;
		}
		{
		case 2:
			show();
			break;
		}
		case 3:
		{
			modify();
			break;
		}
		case 4:
		{
			print();
			break;
		}
		case 5:
		{
			search();
			break;
		}
		case 6:
		{
			theme();
			break;
		}
		case 7:
			help();
		}
	}
}
MySQL数据库 /* SQLyog 企业 - MySQL GUI v8.14 MySQL - 5.5.13 : Database - student ********************************************************************* */ /*!40101 SET NAMES utf8 */; /*!40101 SET SQL_MODE=''*/; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; CREATE DATABASE /*!32312 IF NOT EXISTS*/`student` /*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_bin */; USE `student`; /*Table structure for table `cour` */ DROP TABLE IF EXISTS `cour`; CREATE TABLE `cour` ( `cour_id` int(11) NOT NULL AUTO_INCREMENT, `cour_name` varchar(255) COLLATE utf8_bin DEFAULT NULL, `cour_addr` varchar(255) COLLATE utf8_bin DEFAULT NULL, `cour_time` varchar(255) COLLATE utf8_bin DEFAULT NULL, `cour_long` varchar(255) COLLATE utf8_bin DEFAULT NULL, PRIMARY KEY (`cour_id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*Data for the table `cour` */ insert into `cour`(`cour_id`,`cour_name`,`cour_addr`,`cour_time`,`cour_long`) values (1,'英语','1-5-502','周一下午','40'),(2,'数学','1-2-202','周二下午','35'); /*Table structure for table `sc` */ DROP TABLE IF EXISTS `sc`; CREATE TABLE `sc` ( `sc_id` int(11) NOT NULL AUTO_INCREMENT, `fk_stu_id` int(11) DEFAULT NULL, `fk_cour_id` int(11) DEFAULT NULL, `sc_score` int(11) DEFAULT NULL, PRIMARY KEY (`sc_id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*Data for the table `sc` */ insert into `sc`(`sc_id`,`fk_stu_id`,`fk_cour_id`,`sc_score`) values (2,1,2,90),(4,2,1,85); /*Table structure for table `stu` */ DROP TABLE IF EXISTS `stu`; CREATE TABLE `stu` ( `stu_id` int(11) NOT NULL AUTO_INCREMENT, `stu_name` varchar(255) COLLATE utf8_bin DEFAULT NULL, `stu_code` varchar(255) COLLATE utf8_bin DEFAULT NULL, `stu_clazz` varchar(255) COLLATE utf8_bin DEFAULT NULL, `stu_tel` varchar(255) COLLATE utf8_bin DEFAULT NULL, `stu_card` varchar(255) COLLATE utf8_bin DEFAULT NULL, `stu_sex` int(11) DEFAULT NULL, `stu_coll` varchar(255) COLLATE utf8_bin DEFAULT NULL, `stu_year` varchar(255) COLLATE utf8_bin DEFAULT NULL, `stu_password` varchar(255) COLLATE utf8_bin DEFAULT '123456', PRIMARY KEY (`stu_id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*Data for the table `stu` */ insert into `stu`(`stu_id`,`stu_name`,`stu_code`,`stu_clazz`,`stu_tel`,`stu_card`,`stu_sex`,`stu_coll`,`stu_year`,`stu_password`) values (1,'张晓明1','20140388','1403','12345678909','2205584412685412258',1,'计算机','2014','123456'),(2,'李晓东','20150655','1506`','256874125681','2205588412655365415',-1,'计算机','2015','123456'),(3,'马晓刚','2060612','1606','12345682415','552658422562145826',1,'计算机','2016','123456'); /*Table structure for table `tea` */ DROP TABLE IF EXISTS `tea`; CREATE TABLE `tea` ( `tea_id` int(11) NOT NULL AUTO_INCREMENT, `tea_name` varchar(255) COLLATE utf8_bin DEFAULT NULL, `account` varchar(255) COLLATE utf8_bin DEFAULT NULL, `password` varchar(255) COLLATE utf8_bin DEFAULT '123456', `status` int(11) DEFAULT NULL, `tea_tel` varchar(255) COLLATE utf8_bin DEFAULT NULL, `tea_card` varchar(255) COLLATE utf8_bin DEFAULT NULL, `tea_coll` varchar(255) COLLATE utf8_bin DEFAULT NULL, `tea_sex` int(11) DEFAULT NULL, `tea_img` varchar(255) COLLATE utf8_bin DEFAULT '1.jpg', PRIMARY KEY (`tea_id`) ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*Data for the table `tea` */ insert into `tea`(`tea_id`,`tea_name`,`account`,`password`,`status`,`tea_tel`,`tea_card`,`tea_coll`,`tea_sex`,`tea_img`) values (1,'孟祥玉','admin','1234',1,'12345678901','112558441255625842','计算机',1,'c50bb77db62d46bc80fad14bc5001b46.jpg'),(4,'1','1','123456',1,'1','1','1',1,'1.jpg'),(5,'1','1','1',1,'1','1','1',1,'1.jpg'),(6,'1','1','1',1,'1','1','1',1,'1.jpg'),(7,'1','1','1',1,'1','1','1',1,'1.jpg'),(8,'1','1','123456',1,'1','1','1',1,'1.jpg'),(9,'1','1','123456',1,'1','1','1',1,'1.jpg'),(10,'1','1','123456',1,'1','1','1',1,'1.jpg'),(11,'1','1','123456',1,'1','1','1',1,'1.jpg'); /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值