Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c++;:关于语句和参数的常规q 我在学习C++的过程中。我遇到一个关于温度的作业,我不明白。你们能帮我澄清一些事情吗_C++ - Fatal编程技术网

c++;:关于语句和参数的常规q 我在学习C++的过程中。我遇到一个关于温度的作业,我不明白。你们能帮我澄清一些事情吗

c++;:关于语句和参数的常规q 我在学习C++的过程中。我遇到一个关于温度的作业,我不明白。你们能帮我澄清一些事情吗,c++,C++,这是密码 // compute mean and median temperatures int main() { vector<double> temps; // temperatures for (double temp; cin>>temp; ) // read into temp temps.push_back(temp); // put temp into vector **// compute me

这是密码

// compute mean and median temperatures
int main()
{
vector<double> temps;              // temperatures
for (double temp; cin>>temp; )     // read into temp
temps.push_back(temp);              // put temp into vector

**// compute mean temperature:
double sum = 0;
for (int x : temps) sum += x;
cout << "Average temperature: " << sum/temps.size() << '\n';**

// compute median temperature:
sort(temps);                     // sort temperatures
cout << "Median temperature: " <<  temps[temps.size()/2] << '\n';
}
这个标识符的名称是什么,以便我可以了解更多有关它的信息(在
intx:temps
中的

谢谢:)

这是在
C++11
中介绍的

这样的陈述:

for (int someVal: someCollection)
将迭代
someCollection
,并将
someVal
设置为集合中的每个项目(每次迭代一个)

在您的特定情况下(将
x
的类型更改为更合适的类型后),代码段:

double sum = 0;
for (double x : temps)
    sum += x;
在功能上等同于:

double sum = 0;
for (int i = 0; i < temps.size(); ++i)
    sum += temps[i];
double sum=0;
对于(int i=0;i
您的第一个问题似乎是关于如何继续并将网站添加到书签中。如果你正在学习C++,它就在这里。这个循环的形式是现代C++(有些循环是C语言和java语言)。MA是基于关键字“前缀”,MAG是单词“Of”,但有教育名称“EAK'”如果你学习C++,你的课程材料应该已经覆盖了包括循环在内的基本C++结构。回顾这些可能是明智的。我希望在作业中包含基于范围的for循环的课程也能在正文中解释
for
循环。
double sum = 0;
for (int i = 0; i < temps.size(); ++i)
    sum += temps[i];