write a C program that inputs a series of hourly temperature
write a C++ program that inputs a series of hourly temperatures from a file, and you will create your own input data file with necessary data for your test cases. That is, your data file should have the at least values shown on the first column below. Also include invalid values. You will output a bar chart (using stars) of the temperatures for the day. The temperature should be printed to the left of the corresponding bar, and there should be a heading that gives the scale of the chart. The range of temperatures should be from –30 to 120. Because it is hard to display 150 characters on the screen, you should have each star represent a range of 3 degrees. That way, the bars will be at most 50 characters wide. Here is a partial example, showing the heading, the output for a negative temperature, and the output for various positive temperatures. Note how the temperatures are rounded to the appropriate of stars.
The output and display should look something like this
Solution
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int main(){
ifstream inFile;
int temp;
int i;
cout <<\"Temperatures for 24 hours\"<<endl<<endl;
for(int i= -10; i<30;i+=10){
cout<<i;
cout<<\" \";
}
cout << endl;
inFile.open (\"C:\\\\Dev-Cpp\\\\sources.txt\");
if (!inFile) {
cout << \"Unable to open file\";
return 13;
}
while(inFile >> temp){
while(temp <-30 || temp >120);
if (temp ==0 || temp ==1 || temp==2){
cout<< \"|\"<<endl;
}
else if (temp >=3){
int number_of_star =floor(static_cast<float>((temp+1)/3));
string print=\"|\";
for(int i =0; i < number_of_star; i++){
print+=\"*\";
}
cout<<print<<endl;
}
else if(temp <=-1){
float x = (temp-2)/3;
int number_of_star = ceil(x);
number_of_star *=-1;
string print=\"\";
for(int i=0; i < number_of_star; i++){
print+=\"*\";
}
print +=\"|\";
cout<<print<<endl;
}
}
inFile.close();
system(\"PAUSE\");
}

