某班有最多不超過30人(具體人數(shù)由鍵盤輸入)參加某門課程的考試,用一維數(shù)組作函數(shù)參數(shù)編程實(shí)現(xiàn)如下學(xué)生成績(jī)管理:
(1)錄入每個(gè)學(xué)生的學(xué)號(hào)和考試成績(jī);
(2)計(jì)算課程的總分和平均分;
(3)按成績(jī)由高到低排出名次表;
(4)按學(xué)號(hào)由小到大排出成績(jī)表;
(5)按學(xué)號(hào)查詢學(xué)生排名及其考試成績(jī);
(6)按優(yōu)秀(90~100)、良好(80~89)、中等(70~79)、及格(60~69)、不及格(0~59)5個(gè)類別,統(tǒng)計(jì)每個(gè)類別的人數(shù)以及所占的百分比;文章來源:http://www.zghlxwxcb.cn/news/detail-643884.html
(7)輸出每個(gè)學(xué)生的學(xué)號(hào)、考試成績(jī)。文章來源地址http://www.zghlxwxcb.cn/news/detail-643884.html
#include <iostream>
#include <iomanip>
using namespace std;
void input(int a[], float b[],int);
void caculate(float a[],int);
void sort_in_descending_order_by_score(int a[], float b[],int);
void sort_in_ascending_order_by_number(int a[],float b[],int);
void search(int a[],float b[],int);
void statistic(float a[],int);
int main()
{
int n;
cout << "Input student number(n<30):";
cin >> n;
int choice;
int xvehao[30];
float score[30];
while (1)
{
cout << endl;
cout << "Management for Students' scores" << endl;
cout << "1.Input record" << endl;
cout << "2.Caculate total and average score of course" << endl;
cout << "3.Sort in descending order by score" << endl;
cout << "4.Sort in ascending order by number" << endl;
cout << "5.Search by number" << endl;
cout << "6.Statistic analysis" << endl;
cout << "7.List record" << endl;
cout << "0.Exit" << endl;
cout << "Please Input your choice:";
cin >> choice;
if (choice == 1)input(xvehao, score, n);
else if (choice == 2)caculate(score, n);
else if (choice == 3)sort_in_descending_order_by_score(xvehao, score, n);
else if (choice == 4)sort_in_ascending_order_by_number(xvehao, score, n);
else if (choice == 5)search(xvehao, score, n);
else if (choice == 6)statistic(score, n);
else if (choice == 7)sort_in_ascending_order_by_number(xvehao, score, n);
else if (choice == 0)break;
else
{
cout << "Please input any number from 0 to 7!"<<endl; continue;
}
}
return 0;
}
void input(int a[], float b[],int n)
{
int i;
cout << "Input student's ID, name and score:" << endl;
for (i = 1; i <= n; i++)
{
cin >> a[i] >> b[i];
}
}
void caculate(float a[], int n)
{
float sum=0,aver;
int i;
for (i = 1; i <= n; i++)
{
sum += a[i];
}
aver = sum / n;
cout << "sum=" << sum << " , aver=" << fixed << setprecision(2) << aver;
cout << endl;
}
void sort_in_descending_order_by_score(int a[], float b[], int n)
{
int i, j,k;
for (i = 1; i <= n; i++)
{
k = i;
for (j = i+1; j <= n ; j++)
{
if (b[k] < b[j])k = j;
}
int x = a[i], y = b[i];
a[i] = a[k]; b[i] = b[k];
a[k] = x; b[k] = y;
}
for (i = 1; i <= n; i++)
{
cout << a[i] << " " << b[i] << endl;
}
}
void sort_in_ascending_order_by_number(int a[], float b[], int n)
{
int i, j,k;
for (i = 1; i <= n; i++)
{
k = i;
for (j = i + 1; j <= n; j++)
{
if (a[j] < a[k])k = j;
}
int x = a[i], y = b[i];
a[i] = a[k]; b[i] = b[k];
a[k] = x; b[k] = y;
}
for (i = 1; i <= n; i++)
{
cout << a[i] << " " << b[i] << endl;
}
}
void search(int a[], float b[], int n)
{
int number;
cin >> number;
int i,k;
for (i = 1; i <= n; i++)
{
if (a[i] == number)
{
cout << a[i] << " " << b[i]<<endl;
k = 1;
break;
}
else k = 0;
}
if (k == 0)cout << "Can't find this student!"<<endl;
}
void statistic(float a[], int n)
{
int i;
int A = 0, B = 0, C = 0, D = 0, E = 0, F = 0;
for (i = 1; i <= n; i++)
{
if (a[i] == 100)A++;
else if (a[i] >= 90 && a[i] <= 99)B++;
else if (a[i] >= 80 && a[i] <= 89)C++;
else if (a[i] >= 70 && a[i] <= 79)D++;
else if (a[i] >= 60 && a[i] <= 69)E++;
else F++;
}
cout << "<60 " << F<< " " <<fixed<<setprecision(2)<< ((float)F / n) * 100 << "%" << endl;
cout << "60-69 " << E<< " " << fixed << setprecision(2) << ((float)E / n) * 100 << "%" << endl;
cout << "70-79 " << D<< " " << fixed << setprecision(2) << ((float)D / n) * 100 << "%" << endl;
cout << "80-89 " << C<< " " << fixed << setprecision(2) << ((float)C / n) *100<< "%"<<endl;
cout << "90-99 " << B<< " " << fixed << setprecision(2) << ((float)B / n) * 100 << "%" << endl;
cout << "100 " << A<< " " << fixed << setprecision(2) << ((float)A / n) * 100 << "%" << endl;
}
到了這里,關(guān)于學(xué)生成績(jī)管理系統(tǒng)V1.0的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!