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

Design and write a C++ program that inputs a series of 24 hourly temperatures fr

ID: 3543258 • Letter: D

Question

Design and write a C++ program that inputs a series of 24 hourly temperatures from a file, and outputs 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 number of stars.

Output should look like this

Explanation / Answer

please rate - thanks


please rate - thanks

any questions ask--best I can do with info provided


#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
int main()
{char filename[30];
cout<<"what is the name of the file you are using? ";
int rain[24],i,j,stars;
cin>>filename;
ifstream input;
input.open(filename); //open file
if(input.fail()) //is it ok?
{ cout<<"file did not open please check it ";
system("pause");
return 1;
}
for(i=0;i<24;i++)
{input>>rain[i] ;
}
cout<<"each * represents 3 degrees (scale is approximate) ";
cout<<"hour temp ";
cout<<"-30";
for(i=-20;i<=120;i+=10)
cout<<setw(4)<<i;
cout<<endl;
for(i=0;i<24;i++)
{cout<<setw(5)<<i+1<<"|";
stars=(int)ceil((rain[i]+30)/3.);
for(j=0;j<stars;j++)
cout<<"*";
cout<<endl;
}
input.close();
system("pause");
return 0;
}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote