當前位置:編程學習大全網 - 編程語言 - C++編程,基於壹維數組的成績管理

C++編程,基於壹維數組的成績管理

#include<iostream>

#include<iomanip>

using namespace std;

int Input();

float Max(float scores[],int n);

float Aver(float scores[],int n);

void Count(float scores[],int n, int& a, int& b, int &c);

float score[100];

void main(){

int n,x,y,z;

float max, aver;

n=Input();

max=Max(score, n);

aver=Aver(score, n);

Count(score, n, x, y, z);

cout <<"最高分: " <<max <<", 平均分: " <<aver <<endl;

cout <<"優良占:" <<float(x)/n*100 <<"%, 合格占:"

<<float(y)/n*100 <<"%, 60以下的占:" <<float(z)/n*100 <<"%\n";

return;

}

int Input() {

char t = 'y';

int n = 0; //n用來記錄考試成績的個數

while(t!='n' && n<=100) {

cout<<"請輸入壹個考試成績:";

cin >> score[n++];

cout<<"是否繼續輸入?(y/n,默認y。)";

cin >>t;

}

return n;

}

float Max(float scores[],int n) //n為考試成績的個數,n<=數組的長度

{

float result = scores[0];

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

{

if(result < scores[i]) result = scores[i];

}

return result;

}

float Aver(float scores[],int n)

{

float result = 0;

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

{

result += scores[i];

}

return result/n;

}

void Count(float scores[],int n, int& a, int& b, int& c)

{

a=b=c=0;

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

{

if(scores[i]>=80) a++;

if(scores[i]>=60 && scores[i]<=70) b++;

if(scores[i]<60) c++;

}

}

  • 上一篇:我學過儀器驅動,那麽怎麽用呢?
  • 下一篇:8192遊戲編程
  • copyright 2024編程學習大全網