当前位置: 首页 > news >正文

工厂打星问题

using namespace std ;
const int NumberOfPlants = 4;

void inputData(int a[],int lastPlantNUmber);

void scale(int a[],int size);

void graph(const int asteriskCount[],int lastPlantNumber);

void getTotal(int &sum);

double round(double number);

void printAsterisks(int n);

int main()
{
using namespace std;
int production[NumberOfPlants];

cout << "This program displays a graph showing\n"<< "production for each plant in the company. \n";
inputData(production , NumberOfPlants);
scale(production , NumberOfPlants);
graph(production, NumberOfPlants);
return 0;

}

void inputData(int a[], int lastPlantNumber)
{
for (int plantNumber = 1;plantNumber <= lastPlantNumber ; plantNumber ++)
{
cout << endl
<< "Enter production data for plant number "
<< plantNumber << endl ;
getTotal(a[plantNumber - 1]);
}
}

void getTotal(int &sum)
{
cout << "Enter number of units produced by each department.\n"
<< "append a negative number to the list.\n";

sum = 0;
int next;
cin >> next;
while (next >= 0)
{sum = sum +next;cin >> next;
}
cout << "Total = " << sum << endl; 

}

void scale(int a[], int size)
{
for (int index = 0; index < size ;index++)
{
a[index] = round(a[index]/ 1000.0);

}

}

double round(double number)
{
return static_cast (floor(number + 0.5));
}

void graph (const int asteriskCount[], int lastPlantNumber)
{
cout << "\nUnits produced in thousands of units:\n";
for (int plantNumber = 1 ; plantNumber <= lastPlantNumber ; plantNumber ++)
{
cout << "Plant #" << plantNumber << " ";
printAsterisks (asteriskCount[plantNumber - 1]);
cout << endl ;
}
}

void printAsterisks (int n)
{
for (int count = 1; count <= n; count ++)
{
cout << "*";
}研究一下,经常回来看看,函数可以直接将数组改变。

http://www.gsyq.cn/news/10234.html

相关文章:

  • MySQL练习题 - 教程
  • 嵌入式系统arm高级系统调试技能-24./proc/slabinfo 记录解读与内存异常分析
  • vscode的ssh-remote插件经常掉线
  • 记录第一次CCPC(2025)网络赛前后
  • 声像新境:东芝电视以火箭炮SOUND重塑家庭艺术馆新标准
  • c语言数组与指针
  • 开发微信机器人/微信协议/个人微信api接口
  • 深入解析:frp实现内网穿透,公网服务器或云服务器配置frps,本地内网配置frpc
  • 【五行】根据天干、地支、生肖起姓名(9月出生的宝宝可参考)
  • [Android]自定义view - 详解
  • 【GPT入门】第58课 感性认识Imdeploy介绍与实践 - 详解
  • 使用Cyclops.PdfKit根据pdf模板生成pdf文件
  • 一款文本编辑器的介绍
  • 面试讲解
  • 如何使用C语言实现Vigenre密码加解密
  • 嵌入式硬件工程师每日提问 - 指南
  • JavaScript获取NHK的附件文件
  • 承兑 背书 贴现区别
  • 完整教程:网络安全期末大论文
  • 基于解析法的四轴SCARA机器人正逆运动学代码
  • redis-list类型基本命令
  • 程序员的未来:从技术岗位到全栈思维的进化之路 - 实践
  • 国产化Excel处理组件Spire.XLS教程:Java在 Excel 表格中轻松添加下标
  • tips图解复杂数组、指针声明
  • 通过perl或awk实现剪切功能
  • 详细介绍:麒麟v10服务器安装libvirt
  • 9.23 资料分析 7/10
  • VMware ESXi 磁盘置备类型详解
  • HWiNFO 硬件信息检测工具下载与安装教程
  • 西电PCB设计指南1~2章学习笔记