龙空技术网

C++程序设计基础实验报告——学生成绩记录

似是玖月未央 96

前言:

目前看官们对“用c语言来解题实验报告怎么写”大概比较注意,同学们都需要剖析一些“用c语言来解题实验报告怎么写”的相关知识。那么小编同时在网络上网罗了一些关于“用c语言来解题实验报告怎么写””的相关文章,希望你们能喜欢,你们一起来了解一下吧!

成绩记录簿程序设计

1.具体要求:

制作一个系统制作一个系统实现对学生成绩的管理功能,可以对学生信息及成绩信息进行录入、修改、删除等。

2.基本功能:

(1)增加、修改、删除一个学生及成绩信息。

(2)显示学生成绩。

(3)按条件显示学生资料(条件有学号、姓名等)。

(4)按条件显示班级最高分数以及对应的学生姓名(条件有课程名)

(5)计算所有学生的平均成绩。

3. 有了整体设计这一框架,我们逐步进行设计

(1)设计界面

利用 cout 输出一些符号组合成界面,然后利用while循环主界面和switch、case语句进行对功能选择的实现,构成了主函数。

int main()

{

meau2();

int num =0 ;

while ( num != 9)

{

cout << " " << endl;

cout << " ●●●●●●●●●●●●●●●●●●●●●●●● " << endl;

cout << " $$ $$ " << endl;

cout << " $$ ****************************************** $$ " << endl;

cout << " $$ 学生成绩管理系统 $$ " << endl;

cout << " $$ ★1 成绩录入 ★ $$ " << endl;

cout << " $$ ★2 显示学生成绩信息 ★ $$ " << endl;

cout << " $$ ★3 输入您想查找的学生条件 ★ $$ " << endl;

cout << " $$ ★4 增加一个学生及成绩信息 ★ $$ " << endl;

cout << " $$ ★5 修改一个学生及成绩信息 ★ $$ " << endl;

cout << " $$ ★6 删除一个学生及成绩信息 ★ $$ " << endl;

cout << " $$ ★7 按条件进行成绩排序 ★ $$ " << endl;

cout << " $$ ★8 计算所有学生的平均成绩 ★ $$ " << endl;

cout << " $$ ★9 退出系统 ★ $$ " << endl;

cout << " $$ $$ " << endl;

cout << " $$ ****************************************** $$ " << endl;

cout << " ●●●●●●●●●●●●●●●●●●●●●●●● " << endl;

cout << " --------------------------------------------- " << endl;

cout << " 友情提示:在开始操作前,请先录入信息,按1进入 " << endl;

cout << " 行成绩的录入,然后进行操作(*^__^*)(*^__^*) " << endl;

system("color 0A");

student c;

cout << "请输入一个数字进行选择:" << endl;

cin >> num;

switch (num)

{

case 1: system("cls");

c.Newlist(); break;

case 2: system("cls");

c.xianshi(); break;

case 3: system("cls");

c.check(); break;

case 4: system("cls");

c.zengjia(); break;

case 5: system("cls");

c.xiugai(); break;

case 6: system("cls");

c.shanchu(); break;

case 7: system("cls");

c.paixu(); break;

case 8: system("cls");

c.pingjun(); break;

case 9: system("cls");

c.meau1(); break;

default: cout << "请选择序号:" << endl;

}

}

return 0;

}

(2)定义为一个学生类

class student { //定义一个学生类//

public:

//student(){}

student(double i = 0, string n = "#", int a = 0, int b = 0, int c = 0);

string name;

int num;

int zcj;

int sx;

int yy;

void Newlist();

void xianshi();

void zengjia();

void shanchu();

void xiugai();

void paixu();

void pingjun();

void check();

void meau1();

然后进行构造函数

//void meau2();

};

student::student(double i, string n, int a, int b, int c)

{

num = i;

name = n;

zcj = a;

sx = b;

yy = c;

}

(3)新建学生信息

//**************新建学生成绩信息**************//

void student::Newlist()

{

cout << "请输入学生人数";

cin >> n;

ofstream outfile("stu.dat", ios::out); //定义文件流对象,打开磁盘文件"stu.dat"

if (! outfile) //如果打开失败,outfile返回0值

{

cerr << "打开失败" << endl;

abort();

}

for (int i = 0; i < n; i++)

{

cout << "请输入学生学号" << endl;

cin >> stu[i].num;

cout << "输入学生姓名" << endl;

cin >> stu[i].name;

cout << "输入数学成绩" << endl;

cin >> stu[i].sx;

cout << "输入英语成绩" << endl;

cin >> stu[i].yy;

stu[i].zcj = stu[i].sx + stu[i].yy;

//cout<<"输入学生总成绩"<<endl;

//cin>>stu[i].zcj;

}

outfile.close(); //关闭磁盘文件

cout << "学生信息已经建立";

}

//*************显示成绩信息*************//

void student::xianshi()

{

int i;

cout << "所有学生的信息为:" << endl;

cout << "学号 姓名 数学成绩 英语成绩 总成绩 " << endl;

cout << "--------------------------------------------------------------------" << endl;

//ofstream outfile("stu.dat",ios::out); //定义文件流对象,打开磁盘文件"stu.dat"

//if(! outfile) //如果打开失败,outfile返回0值

//{

//cerr<<"打开失败"<<endl;

//abort();

//}

for (i = 0; i < n; i++)

{

cout << stu[i].num << '\t' << ' ' << stu[i].name << '\t' << stu[i].sx << '\t' << stu[i].yy << '\t' << stu[i].zcj << endl;

}

}

(4)增加学生信息

//*************增加成绩信息*****************//

void student::zengjia()

{

cout << "请输入学生学号" << endl;

cin >> stu[n].num;

cout << "输入学生姓名" << endl;

cin >> stu[n].name;

cout << "输入数学成绩" << endl;

cin >> stu[n].sx;

cout << "输入英语成绩" << endl;

cin >> stu[n].yy;

stu[n].zcj = stu[n].yy + stu[n].sx;

n++;

}

(5)删除学生信息

//****************删除成绩信息******************//

void student::shanchu()

{

int a, b, p;

cout << "请输入要删除学生的学号" << endl;

cin >> a;

for (int i = 0; i < n; i++)

for (int j = 0; j < n; j++) //查找学生

{

if (stu[j].num == a)

{

b = 1;

p = j;

}

}

if (b == 1)

{

for (int i = p; i < n; i++)

stu[i] = stu[i + 1];

n--;

cout << "已删除此学生" << endl;

}

else cout << "没有此学生" << endl;

}

(6)修改学生信息

//****************修改成绩信息******************//

void student::xiugai()

{

int a, b, p;

cout << "请输入需要修改学生的学号" << endl;

cin >> a;

for (int j = 0; j < n; j++)

{

if (stu[j].num == a)

{

b = 1;

p = j;

}

}

if (b == 1)

{

cout << "请输入新的学生学号" << endl;

cin >> stu[p].num;

cout << "输入学生姓名" << endl;

cin >> stu[p].name;

cout << "输入数学成绩" << endl;

cin >> stu[p].sx;

cout << "输入英语成绩" << endl;

cin >> stu[p].yy;

stu[p].zcj = stu[p].yy + stu[p].sx;

cout << "已修改为此学生" << endl;

}

else cout << "没有此学生" << endl;

}

(7)课程成绩排序

//****************************课程成绩排序***************************//

void student::paixu()

{

int c, choice, m, j, k, p;

student temp;

cout << "***************请选择成绩统计课程 ***************" << endl;

cout << " ★1 数 学 ★ " << endl;

cout << " ★2 英 语 ★ " << endl;

cout << " ★3 总成绩 ★ " << endl;

cin >> c;

switch (c)

{

case 1: cout << "*******************************************" << endl;

cout << " ★1 降序排列★ " << endl;

cout << " ★2 升序排列★ " << endl; //数学成绩排序

cin >> choice;

if (choice == 2)

{

for (m = 0; m < n - 1; m++) //选择排序法

{

k = m;

for (j = m + 1; j < n; j++)

if (stu[j].sx < stu[k].sx) k = j;

if (k != m)

{

temp = stu[k];

stu[k] = stu[m];

stu[m] = temp;

}

}

}

else if (choice == 1)

{

for (m = 0; m < n - 1; m++)

{

k = m;

for (j = m + 1; j < n; j++)

if (stu[j].sx > stu[k].sx) k = j;

if (k != m)

{

temp = stu[k];

stu[k] = stu[m];

stu[m] = temp;

}

}

}

cout << " 学生学号 姓名 数学成绩 " << endl;

for (p = 0; p < n; p++)

cout << '\t' << stu[p].num << '\t' << stu[p].name << '\t' << '\t' << stu[p].sx << endl;

break;

case 2: cout << "*******************************************" << endl;

cout << " ★1 降序排列★ " << endl;

cout << " ★2 升序排列★ " << endl; //英语成绩排序

cin >> choice;

if (choice == 2)

{

for (m = 0; m < n - 1; m++)

{

k = m;

for (j = m + 1; j < n; j++)

if (stu[j].yy < stu[k].yy) k = j;

if (k != m)

{

temp = stu[k];

stu[k] = stu[m];

stu[m] = temp;

}

}

}

else if (choice == 1)

{

for (m = 0; m < n - 1; m++)

{

k = m;

for (j = m + 1; j < n; j++)

if (stu[j].yy > stu[k].yy) k = j;

if (k != m)

{

temp = stu[k];

stu[k] = stu[m];

stu[m] = temp;

}

}

}

cout << " 学生学号" << '\t' << "姓名" << '\t' << "总成绩" << endl;

for (p = 0; p < n; p++)

cout << '\t' << stu[p].num << '\t' << stu[p].name << '\t' << stu[p].yy << endl;

break;

case 3: cout << "*******************************************" << endl;

cout << " ★1 降序排列★ " << endl;

cout << " ★2 升序排列★ " << endl;

//总成绩排序

cin >> choice;

if (choice == 2)

{

for (m = 0; m < n - 1; m++)

{

k = m;

for (j = m + 1; j < n; j++)

if (stu[j].zcj < stu[k].zcj) k = j;

if (k != m)

{

temp = stu[k];

stu[k] = stu[m];

stu[m] = temp;

}

}

}

else if (choice == 1)

{

for (m = 0; m < n - 1; m++)

{

k = m;

for (j = m + 1; j < n; j++)

if (stu[j].zcj > stu[k].zcj) k = j;

if (k != m)

{

temp = stu[k];

stu[k] = stu[m];

stu[m] = temp;

}

}

}

cout << " 学生学号" << '\t' << "姓名" << '\t' << "总成绩" << endl;

for (p = 0; p < n; p++)

cout << '\t' << stu[p].num << '\t' << stu[p].name << '\t' << stu[p].zcj << endl;

}

}

(8)求平均成绩

//****************求平均成绩******************//

void student::pingjun()

{

float sum = 0;

float ave;

int i;

for (i = 0; i < n; i++)

{

sum += stu[i].zcj;

}

ave = sum / n;

cout << "所有学生的平均成绩为:" << ave << endl;

}

(9)学生成绩查询

//*****************学生成绩查询********************//

void student::check()

{

void Check1();

void Check2();

int c;

cout << " ◤ ◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇ ◥ " << endl;

cout << " ☆ ☆ " << endl;

cout << " ☆ ***********请选择查询方式*********** ☆ " << endl;

cout << " ☆ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ☆ " << endl;

cout << " ☆ ● 1 按姓名查询 ☆ " << endl;

cout << " ☆ ● 2 按学号查询 ☆ " << endl;

cout << " ☆ ● 3 返回上一级 ☆ " << endl;

cout << " ☆ ☆ " << endl;

cout << " ◣ ◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇ ◢ " << endl;

cin >> c;

switch (c)

{

case 1: Check1(); break;

case 2: Check2(); break;

case 3: return;

default: cout << "请选择序号进行操作:" << endl;

}

}

void Check1() //按姓名查找

{

int b, p;

string a;

cout << "请输入要需要查找学生的姓名" << endl;

cin >> a;

for (int i = 0; i < n; i++)

for (int j = 0; j < n; j++)

{

if (stu[j].name == a)

{

b = 1;

p = j;

}

}

if (b == 1)

{

cout << "学号, 姓名, 数学, 英语, 总成绩" << endl;

cout << stu[p].num << '\t' << stu[p].name << '\t' << stu[p].sx << '\t' << stu[p].yy << '\t' << stu[p].zcj << endl;

}

else cout << "没有此学生" << endl;

}

void Check2() //按学号查找

{

int a, b, p;

cout << "请输入要需要查找学生的学号" << endl;

cin >> a;

for (int j = 0; j < n; j++)

{

if (stu[j].num == a)

{

b = 1;

p = j;

}

}

if (b == 1)

{

cout << "学号, 姓名, 数学, 英语,总成绩" << endl;

cout << stu[p].num << '\t' << stu[p].name << '\t' << stu[p].sx << '\t' << stu[p].yy << '\t' << stu[p].zcj << endl;

}

else cout << "没有此学生" << endl;

}

(10)退出界面

void student::meau1()

{

cout << endl;

cout << " ▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽▽ " << endl;

cout << " △ △ " << endl;

cout << " △ △ " << endl;

cout << " △ ※ 感谢使用 ※ △ " << endl;

cout << " △ ' : ` △ " << endl;

cout << " △ .-----: △ " << endl;

cout << " △ .' `. △ " << endl;

cout << " △ , / (o) ` △ " << endl;

cout << " △ \\`._/ ,__) △ " << endl;

cout << " △ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ △ " << endl;

cout << " △ △ " << endl;

cout << " △△△△△△△△△△△△△△△△△△△△△△△△ " << endl;

}

(11)进入界面

void meau2()

{

cout << endl;

cout << endl;

cout << endl;

cout << endl;

cout << endl;

cout << endl;

cout << " △▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△ " << endl;

cout << " ◆ ◆ " << endl;

cout << " ◆ ◆ " << endl;

cout << " ◆ ◆ " << endl;

cout << " ◆ ★ 欢迎进入成绩管理系统 ★ ◆ " << endl;

cout << " ◆ ◆ " << endl;

cout << " ◆ ◆ " << endl;

cout << " ◆ ◆ " << endl;

cout << " △▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△▲△ " << endl;

srand((unsigned)time(NULL));

char stu[20] = {0};

int m = 0;

union utype

{

int i;

char ch;

float a;

} temp;

temp.i = 266;

printf("%d\n", temp.ch);

while (m != 10)

{

int a = rand() % 8;

system(stu);

Sleep(500);

m++;

}

}

标签: #用c语言来解题实验报告怎么写 #c语言实验报告的总结 #c语言实验报告实验总结怎么写 #简单c程序设计实验总结 #武汉科技大学c语言实验报告