帮忙 一个C++的简单程序编写, 急!

来源:百度知道 编辑:UC知道 时间:2024/05/14 06:33:46
Given a float array as follows: float grades[11]; please implement the following functions and then test them in the main() function:
1. void read grades(): read 11 numbers from the keyboard and store them to the array grades.
2. float max(): find and return the maximum number in grades.
3. void print(): print out the numbers in grades in one single line, where neighboring grades are separated by one space character. Print 3 digits after the decimal point for each grade.
4. void add bonus(): add x bonus points to each grade in the array grades, where x is a parameter.
Test the above functions in themain() function in the following order: read grades(), print(),max(),add bonus(), and print().

用C++写一个程序
一个浮点型的数组 float grades[11], 请在主函数 main() 中执行以下操作
1.void read_grades():从键盘读取11个分数 并把它们储存在数组array grades中
2.float max():找到并输出最高分
3.void print():在同一行中 输出所有分数, 并且要求每个分数之间用空格间隔.小数点后保留三位
4.void add_bonus():在每个成绩上加x分奖励,x是一个参数

#include <iostream>
#include <cstdio>
using namespace std;
float grades[11];
int main()
{
void read_grades();//从键盘读取11个分数 并把它们储存在数组grades中
float max();//找到并输出最高分
void print();//在同一行中 输出所有分数, 并且要求每个分数之间用空格间隔.小数点后保留三位
void add_bonus();//在每个成绩上加x分奖励,x是一个参数

cout<<"请输入11个分数"<<endl;
read_grades();
print();
cout<<"最高分为:"<<max()<<endl;
add_bonus();
cout<<"增加奖励后,";
print();

return 0;
}

void read_grades()
{
for(int i=0;i<11;i++)
{
cin>>grades[i];
}
}

float max()
{
float maxScore,temp;
maxScore = grades[0];
for(int i=1;i<11;i++)
{
if(maxScore<grades[i])
{
maxScore = grades[i];
}
}