|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
//定义学生结构体
struct student {
string name;
string id;
int score[5];//5个课程的成绩
int average;//平均成绩
};
//菜单
void showmenu() {
cout << "***** 成绩管理系统: *****" << endl;
cout << "***** 1.生成成绩 *****" << endl;
cout << "***** 2.计算平均成绩*****" << endl;
cout << "***** 3.冒泡排序 *****" << endl;
cout << "***** 4.选择排序 *****" << endl;
cout << "***** 5.构造链表 *****" << endl;
cout << "***** 6.退出系统 *****" << endl;
cout << "请输入选项: ";
}
//随机输入成绩
void getscores(student students[], int num) {
srand(time(0));
for (int i = 0; i < num; i++)
{
for (int j = 0; j < 5; j++)
{
students[i].score[j] = rand() % 101; // 生成0~100的随机整数
}
}
}
string randomChineseChar()
{
static const char* firstCharList[] = {
"王", "李", "张", "刘", "陈", "杨", "赵", "黄", "周", "吴",
"徐", "孙", "胡", "朱", "高", "林", "何", "郭", "马", "罗"
};
static const int firstCharNum = sizeof(firstCharList) / sizeof(char*);
static const char* secondCharList[] = {
"一", "二", "三", "四", "五", "六", "七", "八", "九", "十",
"莉", "芳", "婷", "敏", "静", "娟", "丽", "华", "洁", "雯",
"军", "勇", "华", "强", "明", "亮", "鹏", "志", "飞", "龙"
};
static const int secondCharNum = sizeof(secondCharList) / sizeof(char*);
int firstIndex = rand() % firstCharNum;
int secondIndex = rand() % secondCharNum;
return string(firstCharList[firstIndex]) + string(secondCharList[secondIndex]);
}
// 随机生成一个名字
string randomName()
{
string firstName = randomChineseChar();
static const char* secondNameList[] = {
"丽", "磊", "峰", "敏", "华", "强", "明", "红", "娟", "伟",
"芳", "婷", "静", "洁", "雯", "龙", "志", "飞", "鹏", "欣"
};
static const int secondNameNum = sizeof(secondNameList) / sizeof(char*);
int secondIndex = rand() % secondNameNum;
return firstName + string(secondNameList[secondIndex]);
}
void getnames(student students[], int num)
{
for (int i = 1; i <= num; i++)
{
students[i].name = randomName();
}
}
void getids(student students[], int num)
{
for (int i = 1; i < +num; i++)
{
students[i].id = 2023217418000 +i;
}
}
void show(student students[], int num)
{
cout << "*************************" << endl;
for (int i = 1; i <= num; i++)
{
cout <<students[i].name << " " << students[i].id << " ";
for (int j = 1; j <= 5; j++)
{
cout << students[i].score[j] << " ";
}
cout << endl;
}
}
int main() {
const int class_num = 4;//班级数量
const int student_num = 45;//每班学生数量
const int nums = class_num * student_num;//学生总数量
student students[nums];//定义数组
while (true) {
showmenu();
int choice;
cin >> choice;
switch (choice) {
case 1://生成成绩
show(students, nums);
cout << "成绩已成功生成" << endl;
system("pause");//清屏操作
system("cls");
break;
case 2://计算平均成绩
system("pause");//清屏操作
system("cls");
break;
case 3://冒泡排序
system("pause");//清屏操作
system("cls");
break;
case 4://选择排序
system("pause");//清屏操作
system("cls");
break;
case 5://构造链表
system("pause");//清屏操作
system("cls");
break;
case 6://退出系统
cout << "你将退出系统" << endl;
system("pause");//清屏操作
return 0;
break;
default:
cout << "你输入了错误的选项" << endl;
system("pause");//清屏操作
system("cls");
break;
}
}
system("pause");
return 0;
} |
|