Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Vector Class : Write a C++ program that reads an unspecified number of temperatu

ID: 3869297 • Letter: V

Question

Vector Class: Write a C++ program that reads an unspecified number of temperatures in Fahrenheit from the keyboard (prompt the user to enter them one at a time). The values should be added to a vector using the vector class with the push_back function. Instruct the user to enter an invalid temperature (<-459.4) to indicate that they are done entering values. Use functions and algorithms in the <algorithm> and <numeric> libraries to find the max, min, sum, and count (number of values) and display the results. Also sort the temperatures in increasing order and display the values. Include units with all outputs. Print the program along with an example that includes at least 10 valid temperatures.

** thank you for your help**

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;
int main()
{
vector <int> v;
int size;
int cel;
int i;
cout<<"Enter the vectore size";
cin>>size;
while(size<9){
cout<<"Please enter greater then 10"<<endl;
cin>>size;
}
cout<<"Enter the temp."<<endl;
for (i =0; i<size;i++)
{
cin>>cel;
if(cel<-459.4)
break;
v.push_back(cel);
}
int max=*max_element(v.begin(),v.end());
int min=*min_element(v.begin(),v.end());
cout<<endl;
cout<<"Max value is: "<<max<<endl;
cout<<"Min value is: "<<min<<endl;
int sum=0;
for(i=0;i<v.size();i++)
{
sum+=v[i];
}
cout<<"Sum of is "<<sum<<endl;
cout<<"Size of vector is "<<v.size()<<endl;

}