To help you guys better help me out ill show you a program that is somewhat similar of what i need that was in my C++ book... for those who dont know, i need to make a bar graph of grades from 3 different classes, the grades must be read from a text file and i need to use at least 1 function... here goes:
this program generates bar graphs of monthly sales by dept for 2 stores
Code:#include <iostream.h> #include<iomanip.h> #include<fstream.h> void GetData(ifstream&, int&, float&); void PrintData(int, int, float); void Printheading(); int main() { int deptID1; //dept id number for store1 int deptID2; //dept id for store 2 float sales1; //dept sales for store 1 float sales2; //dept sales for store2 ifstream store1; //accounting file for store1 ifstream store2; //accounting file for store2 store1.open("store1.txt"); store2.open("store2.txt"); if(!store1 || !store2) { cout<<"Cant open files"<<endl; return 1; } Printheading(); GetData(store1, deptID1, sales1); //process store1 GetData(store2, deptID2, sales2); //process store2 while(store1 && store2) { cout<<endl; PrintData(deptID1, 1, sales1); PrintData(deptID2, 2, sales2); GetData(store1, deptID1, sales1); GetData(store2, deptID2, sales2); } return 0; } void Printheading(); { cout <<"Bar Graph Comparing Depts of Store #1 and #2" <<endl <<endl <<"store sales in 1000s of dollars<< endl <<" # 0 5 10 15 20" <<endl <<"|-----|-----|-----|-----|-----|-----|" <<endl; } void GetData(ifstream& dataFile, //input file int& deptID, //dept number float& deptSales) // dept monthly sales { int numDays int day; float sale; dataFile>> deptID; if(!dataFile) else; dataFile>> numDays; deptSales = 0.0; day=1; //initialize loop control varible while(day<=numDays) { dataFile>> sale; deptSales= deptSales + sale; day++; //update loop control varible } } void PrintDtat(int deptID, int storeNum, float deptSales) { cout<<setw(12)<<"dept"<<deptID<<endl; cout<<setw(3)<<storeNum<<" "; while(deptSales> 250.0) { cout<<"*"; deptSales=deptSales-500.0; } cout<<endl; }
hopefully u can use this to incorporate my grade program, ive tried for days to try to figure this out, my copy is at school, i had forgotten to print it out so someone could tell me where i went wrong but i used the basis of this program for my own, im not good at being given a book and having to figure things out for myself but my teacher thinks thats the best way to learn it... thanks everyone!



LinkBack URL
About LinkBacks


