:
Using functional decomposition, design and write a C++ program that inputs a series of 24 hourly temperatures
from a file, and you will create your own input data file with necessary data for your test cases. 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.
Temperatures for 24 hours:
-10 0 10 20 30
-20 *******?
0 ?
1
2 ?*
3
4
5 ?**
10 ?***
20 ?*******
30 ?**********
[ Notes ]
1) While the program specified 24 input temperatures, your program should work regardless of
how many data in the input file.
2) You will need to write the output to the screen and also to an output file.
Here is what i have so far now
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int display();
void openFile (ifstream &);
int main(){
ifstream inFile;
int temp;
int i;
openFile(inFile);
int display();
system("PAUSE");
}
int display()
{
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;// This make a new line. Comment it out too see what happens
// When you comment it out, your stuff is posted right after the 10
while(inFile >> temp){
while(temp <-30 || temp >120);
//once we have the temperature between -30 to 120 range, we need to do some logic to draw the stars and bar
//look at example at http://www.cs.uah.edu/~rcoleman/CS121/ProgAssign/PA2_Set1.html see how they explained it
if (temp ==0 || temp ==1 || temp==2){
cout<< "|"<<endl;
}
else if (temp >=3){
//for the numbers from 3 to 120
//NUMBER OF STAR = floor((temp+1)/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){
//for the number from -30 to -1
//NUMBER OF STAR = ceil((temp-2)/3))
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();
}
void openFile (ifstream &)
{
ifstream inFile;
inFile.open("C:\\Dev-Cpp\\temperatures.txt");
if (!inFile) {
cout << "Unable to open file";
exit(13);
}
}
|