1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
#include <iostream> #include <iomanip> #include <fstream> using namespace std; void header(); void pos(int,int); void neg(int,int); int main() { header(); int temp,sym; ifstream inFile; inFile.open("C:\\Users\\Peter\\Documents\\CSP31A\\Assignment3question2.txt"); if(!inFile){ cout << "\nOpen file not successful"; } inFile >> temp; while(inFile) { if( temp>=-30 && temp <=120) { cout << setw(8) << temp; sym = temp/3; if (temp>0) { pos(sym,temp); } else if (temp<0) { neg(sym,temp) ; } } inFile >> temp; cout << endl; } system ("PAUSE"); return 0; } void header() { cout << setw(15) <<"-10" << setw(15) <<"0"<< setw(15)<<"10"<< setw(15)<< "20" << setw(15) << "30" << endl; } void pos(int sym,int j) { int x; if (j!=1 || j!=2) { cout << setw(22) << "|"; } for(x=0;x<sym;x++) { cout << "*"; } } void neg(int sym,int j) { int x; cout <<setw(20); for (x=0;x>sym;x--) { cout << "*" ; } if (j != -1 || j != -2) { cout << "|"; } }