//Matthew Gyurgyik //Jan. 29, 2007 //This program will graph tempatures that from a file #include #include #include #include using namespace std; ifstream datafile; float currtemp; int counter; int counter2; int numofstars; int main() { datafile.open("data.txt"); datafile >> currtemp; counter = 1; cout << "Temperatures for 24 Hours\n"; cout << endl; cout << " -30 0 30 60 90 120" << endl; while (datafile) { //cout << currtemp << endl; //currtemp = currtemp + 0.5; numofstars = currtemp / 5; numofstars = abs(numofstars); if (currtemp < 0) { counter2 = 0; //cout << setw(3); cout << int(currtemp); //convert type int to type float int width; //lets declare width width = 9 - numofstars; //take 9 char and subtract from how many stars need to be displayed (allow for right align - this is ugly) cout << setw(width); while (counter2 < numofstars ) //loops the stars { cout << "*"; counter2++; } cout << "|"; } else { counter2 = 0; cout << setw(3); //allows room for the temperature cout << int(currtemp); //convert float to type int cout << setw(9); //set the width so it is aligned with 0 cout << "|"; //add the fancy pipe while (counter2 < numofstars) //this loops the stars { cout << "*"; counter2++; } } cout << endl; counter++; datafile >> currtemp; } datafile.close(); } /* * Temperatures for 24 Hours * * -30 0 30 60 90 120 * -30 ******| * 120 |************************ * 30 |****** * -25 *****| * 53 |********** * 120 |************************ * -10 **| * 23 |***** * 86 |***************** * 70 |************** * 60 |************ * -32 ******| * 89 |***************** * 90 |****************** * 23 |**** * 102 |******************** * */