(12)高校信息查询系统 基本要求: 以高校为基本单位进行信息存放,高校信息包括:编号、学校名称、地址、省份、建校时间、网址等。 功能要求: 1、设计菜单实现功能选择; 2、能够对高校信息进行维护:新建、修改、删除操作; 3、按照高校任意信息进行查询; 4、按照省份、建校时间等信息项进行排序整理; 5、以文件形式保存相关信息,可以读取默认文件中的信息进行查询等操作。 我要实现的要求: 1.功能选择:
时间: 2023-07-04 22:24:49 浏览: 105
好的,以下是高校信息查询系统的功能选择:
```
=============高校信息查询系统=============
1.新建高校信息
2.修改高校信息
3.删除高校信息
4.查询高校信息
5.按省份排序
6.按建校时间排序
7.保存信息到文件
8.从文件读取信息
0.退出系统
请输入数字选择对应的功能:
```
用户可以根据需要输入对应的数字来选择相应的功能。
相关问题
(12)高校信息查询系统“基本要求:+ 以高校为基本单位进行信息存放,高校信息包括:编号、学校名称、地址、省份、建校时间等。+功能要求:+ 1》能够对高校信息进行维护:新建、修改、删除操作;“ 2)按照高校任意信息进行查询,“ 3)以文件形式保存相关信息,可以读取默认文件中的信息进行查询等操作。C++实现
以下是一个简单的C++实现,实现了高校信息的存储、增删改查和文件读写功能。具体实现可根据需求进行修改和完善。
```
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
// 高校信息结构体
struct School {
int id; // 编号
string name; // 学校名称
string address; // 地址
string province;// 省份
int year; // 建校时间
// 构造函数
School(int _id, string _name, string _address, string _province, int _year) {
id = _id;
name = _name;
address = _address;
province = _province;
year = _year;
}
};
// 保存高校信息至文件
void saveToFile(vector<School>& schools) {
ofstream outfile("schools.txt");
for (auto school : schools) {
outfile << school.id << " " << school.name << " " << school.address << " "
<< school.province << " " << school.year << endl;
}
outfile.close();
}
// 从文件中读取高校信息
vector<School> readFromFile() {
vector<School> schools;
ifstream infile("schools.txt");
int id, year;
string name, address, province;
while (infile >> id >> name >> address >> province >> year) {
schools.push_back(School(id, name, address, province, year));
}
infile.close();
return schools;
}
// 添加高校信息
void addSchool(vector<School>& schools) {
int id, year;
string name, address, province;
cout << "请输入高校编号: ";
cin >> id;
cout << "请输入高校名称: ";
cin >> name;
cout << "请输入高校地址: ";
cin >> address;
cout << "请输入高校所在省份: ";
cin >> province;
cout << "请输入高校建校时间: ";
cin >> year;
schools.push_back(School(id, name, address, province, year));
cout << "添加成功!" << endl;
}
// 修改高校信息
void updateSchool(vector<School>& schools) {
int id, year;
string name, address, province;
cout << "请输入待修改高校编号: ";
cin >> id;
for (auto& school : schools) {
if (school.id == id) {
cout << "请输入高校名称: ";
cin >> name;
cout << "请输入高校地址: ";
cin >> address;
cout << "请输入高校所在省份: ";
cin >> province;
cout << "请输入高校建校时间: ";
cin >> year;
school.name = name;
school.address = address;
school.province = province;
school.year = year;
cout << "修改成功!" << endl;
return;
}
}
cout << "未找到该高校信息!" << endl;
}
// 删除高校信息
void deleteSchool(vector<School>& schools) {
int id;
cout << "请输入待删除高校编号: ";
cin >> id;
for (auto it = schools.begin(); it != schools.end(); ++it) {
if (it->id == id) {
schools.erase(it);
cout << "删除成功!" << endl;
return;
}
}
cout << "未找到该高校信息!" << endl;
}
// 按照编号查询高校信息
void queryById(vector<School>& schools) {
int id;
cout << "请输入待查询高校编号: ";
cin >> id;
for (auto school : schools) {
if (school.id == id) {
cout << "编号: " << school.id << endl;
cout << "名称: " << school.name << endl;
cout << "地址: " << school.address << endl;
cout << "省份: " << school.province << endl;
cout << "建校时间: " << school.year << endl;
return;
}
}
cout << "未找到该高校信息!" << endl;
}
// 按照名称查询高校信息
void queryByName(vector<School>& schools) {
string name;
cout << "请输入待查询高校名称: ";
cin >> name;
for (auto school : schools) {
if (school.name == name) {
cout << "编号: " << school.id << endl;
cout << "名称: " << school.name << endl;
cout << "地址: " << school.address << endl;
cout << "省份: " << school.province << endl;
cout << "建校时间: " << school.year << endl;
return;
}
}
cout << "未找到该高校信息!" << endl;
}
// 按照地址查询高校信息
void queryByAddress(vector<School>& schools) {
string address;
cout << "请输入待查询高校地址: ";
cin >> address;
for (auto school : schools) {
if (school.address == address) {
cout << "编号: " << school.id << endl;
cout << "名称: " << school.name << endl;
cout << "地址: " << school.address << endl;
cout << "省份: " << school.province << endl;
cout << "建校时间: " << school.year << endl;
return;
}
}
cout << "未找到该高校信息!" << endl;
}
// 按照省份查询高校信息
void queryByProvince(vector<School>& schools) {
string province;
cout << "请输入待查询高校省份: ";
cin >> province;
for (auto school : schools) {
if (school.province == province) {
cout << "编号: " << school.id << endl;
cout << "名称: " << school.name << endl;
cout << "地址: " << school.address << endl;
cout << "省份: " << school.province << endl;
cout << "建校时间: " << school.year << endl;
}
}
cout << "未找到该省份的高校信息!" << endl;
}
int main() {
vector<School> schools = readFromFile();
int choice;
while (true) {
cout << "请选择操作:\n";
cout << "1.添加高校信息\n";
cout << "2.修改高校信息\n";
cout << "3.删除高校信息\n";
cout << "4.按照编号查询高校信息\n";
cout << "5.按照名称查询高校信息\n";
cout << "6.按照地址查询高校信息\n";
cout << "7.按照省份查询高校信息\n";
cout << "0.退出程序\n";
cin >> choice;
switch (choice) {
case 1:
addSchool(schools);
saveToFile(schools);
break;
case 2:
updateSchool(schools);
saveToFile(schools);
break;
case 3:
deleteSchool(schools);
saveToFile(schools);
break;
case 4:
queryById(schools);
break;
case 5:
queryByName(schools);
break;
case 6:
queryByAddress(schools);
break;
case 7:
queryByProvince(schools);
break;
case 0:
return 0;
default:
cout << "输入无效,请重新输入!" << endl;
break;
}
}
return 0;
}
```
c++。以高校为基本单位进行信息存放,高校信息包括:编号、学校名称、地址、省份、建校时间等。 功能要求: 以文件形式保存相关信息,可以读取默认文件中的信息进行查询等操作。能够对高校信息进行维护:新建、修改、删除操作:.按照高校任意信息进行查询:
下面是一个简单的 C++ 程序,实现了上述要求:
```c++
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
// 定义高校信息结构体
struct School {
int id; // 编号
string name; // 学校名称
string address; // 地址
string province;// 省份
int year; // 建校时间
// 构造函数
School(int i, string n, string a, string p, int y) {
id = i;
name = n;
address = a;
province = p;
year = y;
}
};
// 文件路径
const string filepath = "schools.txt";
// 读取高校信息
vector<School> readSchools() {
vector<School> schools;
ifstream fin(filepath);
if (fin) {
int id, year;
string name, address, province;
while (fin >> id >> name >> address >> province >> year) {
schools.push_back(School(id, name, address, province, year));
}
fin.close();
}
return schools;
}
// 保存高校信息
void saveSchools(vector<School> schools) {
ofstream fout(filepath);
if (fout) {
for (School school : schools) {
fout << school.id << " " << school.name << " " << school.address << " " << school.province << " " << school.year << endl;
}
fout.close();
}
}
// 新建高校信息
void addSchool(vector<School>& schools) {
int id, year;
string name, address, province;
cout << "请输入高校编号:";
cin >> id;
cout << "请输入高校名称:";
cin >> name;
cout << "请输入高校地址:";
cin >> address;
cout << "请输入高校所在省份:";
cin >> province;
cout << "请输入高校建校年份:";
cin >> year;
schools.push_back(School(id, name, address, province, year));
saveSchools(schools);
}
// 修改高校信息
void editSchool(vector<School>& schools) {
int id, year;
string name, address, province;
cout << "请输入需要修改的高校编号:";
cin >> id;
for (int i = 0; i < schools.size(); i++) {
if (schools[i].id == id) {
cout << "请输入新的高校名称(原值:" << schools[i].name << "):";
cin >> name;
cout << "请输入新的高校地址(原值:" << schools[i].address << "):";
cin >> address;
cout << "请输入新的高校所在省份(原值:" << schools[i].province << "):";
cin >> province;
cout << "请输入新的高校建校年份(原值:" << schools[i].year << "):";
cin >> year;
schools[i] = School(id, name, address, province, year);
saveSchools(schools);
return;
}
}
cout << "找不到编号为 " << id << " 的高校" << endl;
}
// 删除高校信息
void deleteSchool(vector<School>& schools) {
int id;
cout << "请输入需要删除的高校编号:";
cin >> id;
for (int i = 0; i < schools.size(); i++) {
if (schools[i].id == id) {
schools.erase(schools.begin() + i);
saveSchools(schools);
return;
}
}
cout << "找不到编号为 " << id << " 的高校" << endl;
}
// 按照编号查询高校信息
void queryById(vector<School>& schools) {
int id;
cout << "请输入需要查询的高校编号:";
cin >> id;
for (School school : schools) {
if (school.id == id) {
cout << "编号:" << school.id << endl;
cout << "名称:" << school.name << endl;
cout << "地址:" << school.address << endl;
cout << "省份:" << school.province << endl;
cout << "建校年份:" << school.year << endl;
return;
}
}
cout << "找不到编号为 " << id << " 的高校" << endl;
}
// 按照名称查询高校信息
void queryByName(vector<School>& schools) {
string name;
cout << "请输入需要查询的高校名称:";
cin >> name;
for (School school : schools) {
if (school.name == name) {
cout << "编号:" << school.id << endl;
cout << "名称:" << school.name << endl;
cout << "地址:" << school.address << endl;
cout << "省份:" << school.province << endl;
cout << "建校年份:" << school.year << endl;
}
}
}
// 按照省份查询高校信息
void queryByProvince(vector<School>& schools) {
string province;
cout << "请输入需要查询的高校省份:";
cin >> province;
for (School school : schools) {
if (school.province == province) {
cout << "编号:" << school.id << endl;
cout << "名称:" << school.name << endl;
cout << "地址:" << school.address << endl;
cout << "省份:" << school.province << endl;
cout << "建校年份:" << school.year << endl;
}
}
}
// 按照建校时间查询高校信息
void queryByYear(vector<School>& schools) {
int year;
cout << "请输入需要查询的高校建校年份:";
cin >> year;
for (School school : schools) {
if (school.year == year) {
cout << "编号:" << school.id << endl;
cout << "名称:" << school.name << endl;
cout << "地址:" << school.address << endl;
cout << "省份:" << school.province << endl;
cout << "建校年份:" << school.year << endl;
}
}
}
int main() {
vector<School> schools = readSchools();
while (true) {
int choice;
cout << "请选择操作:1.新建 2.修改 3.删除 4.按编号查询 5.按名称查询 6.按省份查询 7.按建校时间查询 0.退出:";
cin >> choice;
if (choice == 0) {
break;
}
switch (choice) {
case 1:
addSchool(schools);
break;
case 2:
editSchool(schools);
break;
case 3:
deleteSchool(schools);
break;
case 4:
queryById(schools);
break;
case 5:
queryByName(schools);
break;
case 6:
queryByProvince(schools);
break;
case 7:
queryByYear(schools);
break;
default:
cout << "无效操作" << endl;
break;
}
}
return 0;
}
```
这个程序使用了一个结构体 `School` 来表示高校信息,定义了一些操作函数来实现新建、修改、删除、查询等功能。在 `main` 函数中,程序通过循环来不断接受用户的输入,根据用户选择的操作调用相应的操作函数。同时,程序在启动时会读取文件中保存的高校信息,退出时会将修改后的高校信息保存到文件中。