1. 程式人生 > >學生成績管理系統(簡易本地版)

學生成績管理系統(簡易本地版)

學生成績管理系統(簡易本地版)

一、概述

平臺: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();
		}
	}
}