![]() |
| | #1 |
| Registered User Join Date: Nov 2001
Posts: 15
| Need a suggestion on a school project.. Code: /*
Pay Roll Program
All C++ members
Work Begin: 9-18-01
Status: Incomplete, MENU SYSTEM AND FILE REWRITE UNDER CONSTRUCTION
*/
#include <stdio.h> /*needed for basic printf statement and FILE statement*/
#include <conio.h> /*needed for getch command to work*/
#include <iostream.h> /*needed for cout command*/
#include <stdlib.h> /*needed for exit(0); statement to work*/
/*Non-working section begin*/
//void info()
//{
// int x;
/*Begin FILE section*/
// FILE *mattb;
// FILE *davec;
// FILE *curlee;
// FILE *timd;
// FILE *kurte;
// FILE *randym;
// FILE *shawnm;
// FILE *gennam;
// FILE *ryanr;
// FILE *carlosr;
// FILE *nicks;
// FILE *tias;
// FILE *ronw;
// FILE *austinw;
// FILE *fiorella;
/*End FILE section*/
/*Begin file name definitions*/
// mattb = fopen("mattb.txt","w");
// davec = fopen("davec.txt","w");
// curlee = fopen("curlee.txt","w");
// timd = fopen("timd.txt","w");
// kurte = fopen("kurte.txt","w");
// randym = fopen("randym.txt","w");
// shawnm = fopen("shawnm.txt","w");
// gennam = fopen("gennam.txt","w");
// ryanr = fopen("ryanr.txt","w");
// carlosr = fopen("carlosr.txt","w");
// nicks = fopen("nicks.txt","w");
// tias = fopen("tias.txt","w");
// ronw = fopen("ronw.txt","w");
// austinw = fopen("austinw.txt","w");
// fiorella = fopen("fiorella.txt","w");
/*End file name definitions*/
/*End non-working section*/
//}
void view()
{
int c;
/*Begin FILE section*/
FILE *mattb;
FILE *davec;
FILE *curlee;
FILE *timd;
FILE *kurte;
FILE *randym;
FILE *shawnm;
FILE *gennam;
FILE *ryanr;
FILE *carlosr;
FILE *nicks;
FILE *tias;
FILE *ronw;
FILE *austinw;
FILE *fiorella;
/*End FILE section*/
/*Begin file name definitions*/
mattb = fopen("files/mattb.txt","r");
davec = fopen("files/davec.txt","r");
curlee = fopen("files/curlee.txt","r");
timd = fopen("files/timd.txt","r");
kurte = fopen("files/kurte.txt","r");
randym = fopen("files/randym.txt","r");
shawnm = fopen("files/shawnm.txt","r");
gennam = fopen("files/gennam.txt","r");
ryanr = fopen("files/ryanr.txt","r");
carlosr = fopen("files/carlosr.txt","r");
nicks = fopen("files/nicks.txt","r");
tias = fopen("files/tias.txt","r");
ronw = fopen("files/ronw.txt","r");
austinw = fopen("files/austinw.txt","r");
fiorella = fopen("files/fiorella.txt","r");
/*End file name definitions*/
system("CLS"); /*Very cool clear screen command*/
cout << "\n\tVIEW PAY ROLL INFORMATION";
cout << endl;
cout << endl << "\t1.) Matt B.\t2.) Dave C.";
cout << endl << "\t3.) Brandon C.\t4.) Tim D.";
cout << endl << "\t5.) Kurt E.\t6.) Randy M.";
cout << endl << "\t7.) Shawn M.\t8.) Genna M.";
cout << endl << "\t9.) Ryan R.\t10.) Carlos R.";
cout << endl << "\t11.) Nick S.\t12.) Tia S.";
cout << endl << "\t13.) Ron W.\t14.) Austin W.";
cout << endl << "\t15.) Fiorella\t16.) Exit the Pay Roll program";
cout << endl;
cout << endl << "\tPlease make your selection now:";
cout << endl;
cout << endl << "\t";
cin >> c;
/*Start Matt B.*/
if(c == 1)
{
if(!mattb)
{
cout << "\n\tTHIS FILE CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(mattb);
putchar(c);
}
while(c != EOF);
fclose(mattb);
}
/*End Matt B.*/
/*Start Dave C.*/
else if(c == 2)
{
if(!davec)
{
cout << "\n\tMATT'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(davec);
putchar(c);
}
while(c != EOF);
fclose(davec);
}
/*End Dave C.*/
/*Start Curlee*/
else if(c == 3)
{
if(!curlee)
{
cout << "\n\tCURLEE'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(curlee);
putchar(c);
}
while(c != EOF);
fclose(curlee);
}
/*End Curlee*/
/*Start Tim D.*/
else if(c == 4)
{
if(!timd)
{
cout << "\n\tTIM'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(timd);
putchar(c);
}
while(c != EOF);
fclose(timd);
}
/*End Tim D.*/
/*Start Kurt E.*/
else if(c == 5)
{
if(!kurte)
{
cout << "\n\tKURT'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(kurte);
putchar(c);
}
while(c != EOF);
fclose(kurte);
}
/*End Kurt E.*/
/*Start Randy M.*/
else if(c == 6)
{
if(!randym);
{
cout << "\n\tRANDY'S PAY ROLL CANNOT BE FOUND.\n\n\t";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(randym);
putchar(c);
}
while (c != EOF);
fclose(randym);
}
/*End Randy M.*/
/*Start Shawn M.*/
else if(c == 7)
{
if(!shawnm);
{
cout << "\n\tSHAWN'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(shawnm);
putchar(c);
}
while (c != EOF);
fclose(shawnm);
}
/*End Shawn M.*/
/*Start Genna M.*/
else if(c == 8)
{
if(!gennam);
{
cout << "\n\tGENNA'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(gennam);
putchar(c);
}
while (c != EOF);
fclose(gennam);
}
/*End Genna M.*/
/*Start Ryan R.*/
else if(c == 9)
{
if(!ryanr)
{
cout << "\n\tRYAN'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(ryanr);
putchar(c);
}
while (c != EOF);
fclose(ryanr);
}
/*End Ryan R.*/
/*Start Carlos R.*/
else if(c == 10)
{
if(!carlosr)
{
cout << "\n\tCARLOS'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(carlosr);
putchar(c);
}
while (c != EOF);
fclose(carlosr);
}
/*End Carlos R.*/
/*Start Nick S*/
else if(c == 11)
{
if(!nicks)
{
cout << "\n\tNICK'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(nicks);
putchar(c);
}
while (c != EOF);
fclose(nicks);
}
/*End Nick S.*/
/*Start Tia S.*/
else if(c == 12)
{
if(!tias)
{
cout << "\n\tTIA'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(tias);
putchar(c);
}
while (c != EOF);
fclose(tias);
}
/*End Tia S.*/
/*Start Ron W.*/
else if(c == 13)
{
if(!ronw)
{
cout << "\n\tRON'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(ronw);
putchar(c);
}
while (c != EOF);
fclose(ronw);
}
/*End Ron W.*/
/*Start Austin W.*/
else if(c == 14)
{
if(!austinw)
{
cout << "\n\tAUSTIN'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(austinw);
putchar(c);
}
while (c != EOF);
fclose(austinw);
}
/*End Austin W.*/
/*Start Fiorella*/
else if(c == 15)
{
if(!fiorella)
{
cout << "\n\tFIORELLA'S PAY ROLL CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(fiorella);
putchar(c);
}
while (c != EOF);
fclose(fiorella);
}
/*End Fiorella*/
else if(c == 16)
exit(0);
}
void main()
{
int menu;
cout << "\t\tPAY ROLL PROGRAM\b";
cout << endl << "\n\tSelect 1 to enter pay roll information";
cout << endl << "\tSelect 2 to view pay roll information";
cout << endl << "\tSelect 3 to exit the pay roll program";
cout << endl;
cout << endl << "\tPlease make your selection now:";
cout << endl;
cout << endl << "\t";
cin >> menu;
// if (menu == 1) /*The dreaded if statement, displays function info if 1 is pressed*/
// info();
/*else*/ if (menu == 2)
view();
else if (menu == 3) /*Exits program when 3 is pressed*/
exit(0);
else if (menu == 4)
cout << "\n\tThat is not a proper selection";
}
/*Pay Roll Setup
1 2 3
1.) Matt B. 2.) Dave C. <- Thank you...
3.) Brandon C. 4.) Tim D. <- Goodbye
5.) Kurt E. 6.) Randy M. <-
7.) Shawn M. 8.) Genna M. <-
9.) Ryan R. 10.) Carlos R. <-
11.) Nick S. 12.) Tia S. <-
13.) Ron W. 14.) Austin W. <-
15.) Fiorella D. 16.) Exit <-
1.) MB 2.) MB
Wages - $15/hr Wages - $15/hr
Funds - $0.00 Funds - $0.00
Hours - 0hrs Hours - 0hrs
Press Enter to Return Press 1 to add/subtract $
Press 2 to add/subtract hours
Press 3 to exit
1.) Enter funds to add/subtract
2.) Enter hours to add/subtract
*/
If you like to make any other suggestions that may make things easier for us, that's cool too. Sorry if the code looks a little unusual. Hopefully someone can help us out.--Screwz Luse |
| Screwz Luse is offline | |
| | #2 |
| train spotter Join Date: Aug 2001 Location: near a computer
Posts: 3,359
| For a start try creating a structure to hold the file details ie File handle(return of fopen CreateFile() ect) string for name of file ie "MattB.txt" and anything else for the file handling. then declare an array of the struct and hash define some int indexes ie #define MAX_FILES 15 #define MATTB 0 #define DAVEC 1 then you can use for loops to open/validate the files. Use the string in error msg's ect. If you need a file you can call it with the define Code: if(iChoice==MATTB)
{
FileArray[MATTB].fFile = fopen( FileArray[MATTB].sFileName ,"w" );
if(FileArray[MATTB].fFile==NULL)
sprintf(sErrorBuffer, "File %s has failed to open.", FileArray[MATTB].sFileName );
//ect
__________________ "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter." Friedrich Nietzsche "I spent a lot of my money on booze, birds and fast cars......the rest I squandered." George Best "If you are going through hell....keep going." Winston Churchill |
| novacain is offline | |
| | #3 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| In addition, decide whether this is going to be in C or C++ And use int main And don't open all the files at once - most operating systems have fairly small limits on the number of files you can have open at the same time, and your existing approach will not extend well at all. |
| Salem is offline | |
| | #4 |
| Registered User Join Date: Nov 2001
Posts: 15
| Thanx for the suggestions. I'll deffinately bring it up during the next class and we'll cut down on the size and how many files are open at a time. This is going to be in C. We're using Microsoft Visual C++ to write the program. |
| Screwz Luse is offline | |
| | #5 | |
| Registered User Join Date: Nov 2001
Posts: 15
| Quote:
Code: if(iChoice==MATTB)
{
FileArray[MATTB].fFile = fopen( FileArray[MATTB].sFileName ,"w" );
if(FileArray[MATTB].fFile==NULL)
sprintf(sErrorBuffer, "File %s has failed to open.", FileArray[MATTB].sFileName );
| |
| Screwz Luse is offline | |
| | #6 |
| train spotter Join Date: Aug 2001 Location: near a computer
Posts: 3,359
| Declare the struct in a header. I would make the array global or local to the file operations file if in a multi file project. Depends on WHERE you want it. If local write functions to return the value you need given an index and type of element (use a switch/case) Start by stacking/init the array. ie fill in the strings, set the FILE elements to -1 [-1 is not a possible return from fopen() ] The idea is to group the data. Make it easier to find. If you need data all you have to pass into a function is the array index. All the info relates to this element (a structure) in the array. Take your Code: if(c == 1)
{
if(!mattb)
{
cout << "\n\tTHIS FILE CANNOT BE FOUND.\n\n";
exit(0);
}
do /*Start screwed up "loop"*/
{
c = fgetc(mattb);
putchar(c);
}
while(c != EOF);
fclose(mattb);
}
if(c == 2)
ect
ect
ect
Code: //now the user has made the choice open the file for READING not WRITING
FileArray[iChoice].fFile = fopen( FileArray[iChoice].sFileName , "r" );
if(FileArray[iChoice].fFile==NULL)
{
//write the error, %s is where the file name will be printed
sprintf(sErrorBuffer, "\n\t %s FILE CANNOT BE FOUND.\n\n", FileArray[iChoice].sFileName );
cout << sErrorBuffer; //can you do this with cout??
Exit(0);
}
else
{
do /*Start screwed up "loop"*/
{
c = fgetc(FileArray[iChoice].fFile);
putchar(c);
}
while(c != EOF);
//return should be 0 if closed properly
FileArray[iChoice].fFile = (FILE*) fclose(FileArray[iChoice].fFile);
}
I does not matter which was chosen as long as the iChoice matches the array indexes you have defined. ie #define MATTB 0 then the menu should return 0 if the user chooses Matt B. All of MATTB's info is in the zero element of the array ie FileArray[MATTB] (the same as FileArray[0]) Try and put all the things into the struct you can. The FILE pointer, the file name, the menu strings and even a union/pointer containing the info read. Clear as mud? One last thing. I think it is best to open and close a file in the same function. Data is more likely to be corrupted in file left open at close of the exe. The exe will fail if it tries to open an open file ect.
__________________ "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter." Friedrich Nietzsche "I spent a lot of my money on booze, birds and fast cars......the rest I squandered." George Best "If you are going through hell....keep going." Winston Churchill |
| novacain is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| added start menu crashes game | avgprogamerjoe | Game Programming | 6 | 08-29-2007 01:30 PM |
| Please, suggest a project …. | Dragon227Slayer | Tech Board | 1 | 06-12-2004 10:48 AM |
| I've been slacking off in high school, am I going to hell | Silvercord | A Brief History of Cprogramming.com | 31 | 06-01-2003 01:00 PM |
| Question about going to a technical school | Goalie35 | C++ Programming | 1 | 08-30-2001 11:34 AM |