ch_7.02
来源:互联网 发布:linux 端口查看 编辑:程序博客网 时间:2024/06/05 11:32
// 编程练习_07.02_处理数组的函数.cpp
/**********************************************************************
2.编写一个程序,要求用户输入最多10个高尔夫成绩,并将其存储在一个数组中。
程序允许用户提早结束输入,并在一行上显示所有成绩,然后报告平均成绩。
请使用3个数组处理函数来分别进行输入、显示和计算平均成绩。
***********************************************************************/
#include <iostream>
int const GolfArSize = 10;
int TrueSize = 0;
int main()
{
using namespace std;
cout << "Now, begin to remember the score." << endl;
void SaveGolf(int* Golf);
void ShowGolf (const int * Golf);
void AverageGolf (const int* Golf);
int Golf[GolfArSize];
SaveGolf(Golf);
ShowGolf(Golf);
AverageGolf(Golf);
return 0;
}
void SaveGolf(int* Golf)
{
using namespace std;
int i = 0;
cout << "If you want to end the programme,Please enter a letter." << endl;
for (i; i < GolfArSize; i++)
{
cout << "Please enter " << i+1 << " golf score: ";
if (cin >> Golf[i])
{
}
else
{
TrueSize = i;
break;
}
TrueSize = i;
}
cout << "Enter End" << endl;
}
void ShowGolf (const int * Golf)
{
using namespace std;
int i= 0;
cout << endl;
cout << "Now show the score in next line: " << endl;
for (i; i < TrueSize; i++)
{
cout << Golf[i] << '\t';
}
cout << endl;
}
void AverageGolf (const int* Golf)
{
using namespace std;
int i = 0;
int sum = 0;
for (i; i < TrueSize; ++i)
{
sum += Golf[i];
}
cout << "Average Score is : " << sum / TrueSize << endl;
}
// 本次编程时遇到了可提早结束输入的问题,后来想到多定义一个全局变量解决问题。
// 另外,这里还学习注意用const访问数组。用三种函数对数组实现功能。
/**********************************************************************
2.编写一个程序,要求用户输入最多10个高尔夫成绩,并将其存储在一个数组中。
程序允许用户提早结束输入,并在一行上显示所有成绩,然后报告平均成绩。
请使用3个数组处理函数来分别进行输入、显示和计算平均成绩。
***********************************************************************/
#include <iostream>
int const GolfArSize = 10;
int TrueSize = 0;
int main()
{
using namespace std;
cout << "Now, begin to remember the score." << endl;
void SaveGolf(int* Golf);
void ShowGolf (const int * Golf);
void AverageGolf (const int* Golf);
int Golf[GolfArSize];
SaveGolf(Golf);
ShowGolf(Golf);
AverageGolf(Golf);
return 0;
}
void SaveGolf(int* Golf)
{
using namespace std;
int i = 0;
cout << "If you want to end the programme,Please enter a letter." << endl;
for (i; i < GolfArSize; i++)
{
cout << "Please enter " << i+1 << " golf score: ";
if (cin >> Golf[i])
{
}
else
{
TrueSize = i;
break;
}
TrueSize = i;
}
cout << "Enter End" << endl;
}
void ShowGolf (const int * Golf)
{
using namespace std;
int i= 0;
cout << endl;
cout << "Now show the score in next line: " << endl;
for (i; i < TrueSize; i++)
{
cout << Golf[i] << '\t';
}
cout << endl;
}
void AverageGolf (const int* Golf)
{
using namespace std;
int i = 0;
int sum = 0;
for (i; i < TrueSize; ++i)
{
sum += Golf[i];
}
cout << "Average Score is : " << sum / TrueSize << endl;
}
// 本次编程时遇到了可提早结束输入的问题,后来想到多定义一个全局变量解决问题。
// 另外,这里还学习注意用const访问数组。用三种函数对数组实现功能。
- ch_7.02
- 02
- *02
- #!(02)
- 02
- 02
- 02
- 02
- 02
- 02
- 2007-02-02
- 2010-02-02
- 11 02 02 年三十
- 2012-02-02
- hibernate-2014-02-02
- 02课后作业02
- CVPR 2017-02-02
- 2015/02/02 - 2015/02/03
- 用 C# 轻松读取、改变文件的创建、修改、访问时间
- 数据库检索中,使用exists时,还是配合distinct 来得快。
- note
- SOURCES的文件格式
- 笔试题
- ch_7.02
- GNU C - 关于8086的内存访问机制以及内存对齐(memory alignment)
- 黑马程序员--JAVA之内省、注解与类加载器
- 总结Objective-C中CGGeometry 几何类的常用方法
- C#控制台应用程序Main函数中的参数args
- 塞班领先地位如何被苹果迅速摧毁?
- 如何在javaweb项目中引入jquery库函数,以及如何使用
- WTL 工具条摆放非Button资源
- 红黑树的介绍和实现(一)[原创]