Cplusplus重写了有关do​​oflingy的代码

时间:2018-12-11 03:04:43

标签: c++ stl

所以我写出了这个可以正常工作的c ++程序,但是在提交它之后,由于没有使用 adjacent_difference ,它被返回说需要重写,问的问题如下:< / p>

Rinky Dooflingy公司记录了在四个星期内每天产生的dooflingies的数量。编写一个程序,读取这些生产级别并将其存储在STL容器中。然后,该程序应查找并显示:

a。最低,最高和平均每日生产水平。

b。一个序列,显示每天产量的上升或下降的幅度。

c。一个序列,显示每天直到当天(包括该天)产生的dooflingies总数。

您必须使用标准容器,并且必须使用标准算法来执行上面a,b和c中显示的所有计算。不使用标准容器且不使用标准算法进行计算的解决方案是不可接受的。

我的反馈是: 有一种标准算法(adjacent_difference)可计算每日变化,但您不使用它。

不符合要求使用标准算法的问题规范。

请帮助,我很困惑,试图重写它,但没有成功 这是我的代码,如下所示:

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
vector<int> product; //set up vector
cout<<"Please enter the number of cases of Dooflingies produced each day:\n";   //prompt user to enter amount produced in a day

for(int i=0; i<5; i++){ //math for vector
    int temp;
    cin>>temp;
    product.push_back(temp);
}
cout<<"-------------------------------";
cout<<"\nHighest Production Level: " <<*std::max_element(product.begin(),product.end())<<"\n"; //display highest production level
cout<<"Lowest Production Level:  " <<*std::min_element(product.begin(),product.end())<<"\n"; //display lowest production level
cout<<"Average Production Level: " <<std::accumulate(product.begin(),product.end(),0.0)/product.size()<< "\n"; //display average production level
cout<<"-------------------------------";
cout<<"\nProduction Level Influx:\n"; //display rise in production, used spaces to make it easier to see

for(int i=1; i<28; i++){ //math for vector
cout <<"Day " <<i<<": "<<product[i]-product[i-1]<<"\n";
}

int cumulative_sum[28]; //the cumulative sum of the whole program
std::partial_sum(product.begin(),product.end(),cumulative_sum);

cout<<"-----------------------------\n";
cout<<"Total Production Until:\n"; //total amount of dooflingies produced

for(int i=0;i<28; i++){
cout<<"Day " <<i+1<<": "<<cumulative_sum[i]<<"\n"; //math
}
return 0;
}

提前谢谢

0 个答案:

没有答案
相关问题