Forgive me for messing with your code but I really think some things need to be fixed before I can show you how to do some of the things you need to do.
[code] {[red] this modification of the program attempts to improve the code by eliminating recursive calls [/red]}
Program schoolSBA; {This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}
uses crt ; (*, dos,graph; *) {[red] "dos" and "graph" have been commented out. "dos" does not appear to be needed. I do not have "graph" so I have comment it out also and have substituted your previous version of "advert" [/red]}
Type MemberDatabaseDDC = record {declaration of record} Member_ID : string[10]; Member_Name:String[30]; Member_TicketPayment:integer; Advert:string; end;
I was composing a post earlier this afternoon about [b]grandtotals[/b] but decided that we need to cover some other ground before I can adequately explain. Below is some code I have extracted from your posts. It is just as you posted except I have tried to restore some indentation (which I hope you are using) and omitted some blank lines.
I want to discuss your procedure [b]add[/b]. [code] (*184*) (*185*) Procedure Add; (*186*) {************************************************************************* (*187*) * This Procedure is used to ask the user which database he would like to * (*188*) * use to add records to the respective groups. * (*189*) *************************************************************************} (*190*) var (*191*) Ans : char; (*192*) choice:integer; (*193*) begin (*194*) clrscr; (*195*) (*196*) Textcolor(Black); (*197*) Textbackground(White); (*198*) GotoXY(8,2); (*199*) Writeln ('
Here is the code for computing the totals. I hope it is self explanatory.
[code] procedure grandtotals ; { ****************************************************** * This Procedure is used to identify the totals that * * each group pays and the total of all three groups. * ****************************************************** }
function getcost (databasefile : databasefiletype) : integer ; { get total of payments from a database } var cost : integer ; i, { loop index } n : longint ; { index of last record } databasefile : databasefiletype ; databaserec : memberdatabase ;
begin { getcost } {$I-} cost := 0 ;
reset(databasefile) ; if ioresult > 0 then begin { cannot open database so ... } getcost := 0 ; { return zero ... } exit { and bug out } end ; n := filesize(databasefile) - 1 ; for i := 0 to n do begin seek(databasefile, i) ; read(databasefile, databaserec) ; with databaserec do cost := cost + member_ticketpayment end ; close(databasefile) ;
getcost := cost {$I+} end ; { getcost } var costddc, costdpi, costdsgo, total : integer ;
begin { first do the work } costddc := getcost(DDCdatabasefile) ; costdpi := getcost(DPIdatabasefile) ; costdsgo := getcost(DSGOdatabasefile) ; total := costddc + costdpi + costdsgo ; { then display results } clrscr ; gotoxy(12,2) ; write('
: i have a query..do i have to do the same thing for add for procedure : viewing...like putting the assigns for viewing in the main menu?
Well, yes and no. That's just the way [italic]I[/italic] would do it. There's almost never just one way to do something.
Here are a couple of examples to show what I was suggesting. The first example shows how I envision the structure of your program.
In lines 7, 8, 9 I define three string constants with the names of the three files. In lines 22, 23, 24 I declare three "file variables." In the main program, lines 168, 169, 170, the three variables are assigned to the three string constants.
In line 50 the procedure [b]add_member[/b] receives the file variable from the calling procedure [b]add[/b], lines 67, 68. 69. In [b]add_member[/b] the file variable [b]f[/b] actually becomes the file variable [b]ddc_file, dpi_file[/b] or [b]dsg_file[/b], depending on which line in [b]add[/b] called it.
A similar thing happens in [b]del_member, edit_member[/b] and [b]view_member[/b]. [code] { 1} { { 2} example of passing "file variables" to procedures { 3} } { 4} program schoolsba ; { 5} { 6} CONST { 7} DDC_NAME = 'memberdb.ddc' ; { 8} DPI_NAME = 'memberdb.dpi' ; { 9} DSG_NAME = 'memberdb.dsg' ; { 10} { 11} type { 12} recordtype = record { 13} id_number : string[10] ; { 14} name : string[30] ; { 15} payment : integer ; { 16} advert : string { 17} end ; { 18} { 19} filetype = file of recordtype ; { 20} { 21} var { 22} ddc_file, { 23} dpi_file, { 24} dsg_file : filetype ; { 25} { 26} procedure viewmenu ; { 27} begin { 28} { { 29} your code here { 30} } { 31} end ; { 32} { 33} procedure mainmenu ; { 34} { 35} procedure advertisement ; { 36} begin { 37} { { 38} your code here { 39} } { 40} end ; { 41} { 42} procedure aboutwcmf ; { 43} begin { 44} { { 45} your code here { 46} } { 47} end ; { 48} { 49} procedure add ; { 50} procedure add_member (var f : filetype) ; { 51} begin { 52} { { 53} your code here { 54} { 55} the file variable f points to whichever file { 56} was passed to the child procedure by the { 57} parent procedure. { 58} } { 59} end ; { 60} begin { 61} repeat { 62} { { 63} your code here { 64} } { 65} read (choice) ; { 66} case choice of { 67} 1 : add_member(ddc_file) ; { 68} 2 : add_member(dpi_file) ; { 69} 3 : add_member(dsg_file) { 70} end { case } { 71} until choice = 4 { 72} end ; { 73} { 74} procedure del ; { 75} procedure del_member (var f : filetype) ; { 76} begin { 77} { { 78} your code here { 79} { 80} the file variable f points to whichever file { 81} was passed to the child procedure by the { 82} parent procedure. { 83} } { 84} end ; { 85} begin { 86} repeat { 87} { { 88} your code here { 89} } { 90} read (choice) ; { 91} case choice of { 92} 1 : del_member(ddc_file) ; { 93} 2 : del_member(dpi_file) ; { 94} 3 : del_member(dsg_file) { 95} end { case } { 96} until choice = 4 { 97} end ; { 98} { 99} procedure edit ; {100} procedure edit_member (var f : filetype) ; {101} begin {102} { {103} your code here {104} {105} the file variable f points to whichever file {106} was passed to the child procedure by the {107} parent procedure. {108} } {109} end ; {110} begin {111} repeat {112} { {113} your code here {114} } {115} read (choice) ; {116} case choice of {117} 1 : edit_member(ddc_file) ; {118} 2 : edit_member(dpi_file) ; {119} 3 : edit_member(dsg_file) {120} end { case } {121} until choice = 4 {122} end ; {123} {124} {125} procedure view ; {126} procedure view_member (var f : filetype) ; {127} begin {128} { {129} your code here {130} {131} the file variable f points to whichever file {132} was passed to the child procedure by the {133} parent procedure. {134} } {135} end ; {136} begin {137} repeat {138} { {139} your code here {140} } {141} read (choice) ; {142} case choice of {143} 1 : view_member(ddc_file) ; {144} 2 : view_member(dpi_file) ; {145} 3 : view_member(dsg_file) {146} end { case } {147} until choice = 4 {148} end ; {149} {150} begin {151} repeat {152} { {153} your code here {154} } {155} read (choice) ; {156} case choice of {157} 1 : advertisement ; {158} 2 : aboutwcmf ; {159} 3 : add ; { to add records } {160} 4 : del ; { to delete records } {161} 5 : edit ; { to edit records } {162} 6 : view { to view records } {163} end { case } {164} until choice = 7 {165} end ; {166} {167} begin {168} assign (ddc_file, DDC_NAME) ; {169} assign (dpi_file, DPI_NAME) ; {170} assign (dsg_file, DSG_NAME) ; {171} {172} viewmenu ; {173} mainmenu {174} end. [/code] In this second example the string constants are declared just as in the first but the file variables are declared in the individual procedures [b]add_member, del_member, edit_member[/b] and [b]view_member[/b]. Instead the file names (the string constants) are each passed to the procedures and assigned in the procedures. The file variables should also be declared inside the individual procedures. [code] { 1} { { 2} example of passing "file names" to procedures { 3} } { 4} program schoolsba ; { 5} { 6} CONST { 7} DDC_NAME = 'memberdb.ddc' ; { 8} DPI_NAME = 'memberdb.dpi' ; { 9} DSG_NAME = 'memberdb.dsg' ; { 10} { 11} type { 12} recordtype = record { 13} id_number : string[10] ; { 14} name : string[30] ; { 15} payment : integer ; { 16} advert : string { 17} end ; { 18} { 19} procedure viewmenu ; { 20} begin { 21} { { 22} your code here { 23} } { 24} end ; { 25} { 26} procedure mainmenu ; { 27} { 28} procedure advertisement ; { 29} begin { 30} { { 31} your code here { 32} } { 33} end ; { 34} { 35} procedure aboutwcmf ; { 36} begin { 37} { { 38} your code here { 39} } { 40} end ; { 41} { 42} procedure add ; { 43} procedure add_member (fname : string) ; { 44} var { 45} f : file of recordtype ; { 46} begin { 47} { { 48} the parent procedure passes a file name, rather than { 49} a file variable, to the child procedure. The child { 50} procedure must have its own assign statement. { 51} } { 52} assign (f, fname) ; { 53} { { 54} your code here { 55} } { 56} end ; { 57} begin { 58} repeat { 59} { { 60} your code here { 61} } { 62} read (choice) ; { 63} case choice of { 64} 1 : add_member(DDC_NAME) ; { 65} 2 : add_member(DPI_NAME) ; { 66} 3 : add_member(DSG_NAME) { 67} end { case } { 68} until choice = 4 { 69} end ; { 70} { 71} procedure del ; { 72} procedure del_member (fname : string) ; { 73} var { 74} f : file of recordtype ; { 75} begin { 76} assign (f, fname) ; { 77} { { 78} your code here { 79} } { 80} end ; { 81} begin { 82} repeat { 83} { { 84} your code here { 85} } { 86} read (choice) ; { 87} case choice of { 88} 1 : del_member(DDC_NAME) ; { 89} 2 : del_member(DPI_NAME) ; { 90} 3 : del_member(DSG_NAME) { 91} end { case } { 92} until choice = 4 { 93} end ; { 94} { 95} procedure edit ; { 96} procedure edit_member (fname : string) ; { 97} var { 98} f : file of recordtype ; { 99} begin {100} assign (f, fname) ; {101} { {102} your code here {103} } {104} end ; {105} begin {106} repeat {107} { {108} your code here {109} } {110} read (choice) ; {111} case choice of {112} 1 : edit_member(DDC_NAME) ; {113} 2 : edit_member(DPI_NAME) ; {114} 3 : edit_member(DSG_NAME) {115} end { case } {116} until choice = 4 {117} end ; {118} {119} procedure view ; {120} procedure view_member (fname : string) ; {121} var {122} f : file of recordtype ; {123} begin {124} assign (f, fname) ; {125} { {126} your code here {127} } {128} end ; {129} begin {130} repeat {131} { {132} your code here {133} } {134} read (choice) ; {135} case choice of {136} 1 : view_member(DDC_NAME) ; {137} 2 : view_member(DPI_NAME) ; {138} 3 : view_member(DSG_NAME) {139} end { case } {140} until choice = 4 {141} end ; {142} {143} begin {144} repeat {145} { {146} your code here {147} } {148} read (choice) ; {149} case choice of {150} 1 : advertisement ; {151} 2 : aboutwcmf ; {152} 3 : add ; { to add records } {153} 4 : del ; { to delete records } {154} 5 : edit ; { to edit records } {155} 6 : view { to view records } {156} end { case } {157} until choice = 7 {158} end ; {159} {160} begin {161} viewmenu ; {162} mainmenu {163} end. [/code] Both ways have their advantages and disadvantages. I prefer the first.
In your program you write several on-screen messages such as:
"Welcome to the DDC database"
which works if you have a different procedure for each database. But if you have only one procedure it has to know which file was passed to it. The only way to do this is with a call such as [code]1 : add_member(ddc_file, DDC_NAME)[/code] and a procedure declaration like [code]procedure add_member(var f : filetype ; fname : string)[/code]
Whichever method you use the message is written out with [code]write('Welcome to the ', copy(fname, 1, 3), ' database') ;[/code]
I hope all this is helping. I sometimes get the feeling that I'm giving you more problems than help.
She wouldn't mind it at all ..she told us to use all the codes we can .."The more complex your program the more marks you get" so yeah,
i watched the grand total codes...thanks alot..i tried to put it in my program and i changed the codes to my program's updated codes but by reset , when i put in my code it says file variable expected...im lost.. can i upload my updated program so you can eradicate the problem..also is it possible to have 3 "seeks","resets" because i have three databases and it wouldn't be nice if i can only work with one database..so tell me what to do..
She wouldn't mind it at all ..she told us to use all the codes we can .."The more complex your program the more marks you get" so yeah,
i watched the grand total codes...thanks alot..i tried to put it in my program and i changed the codes to my program's updated codes but by reset , when i put in my code it says file variable expected...im lost.. can i upload my updated program so you can eradicate the problem..also is it possible to have 3 "seeks","resets" because i have three databases and it wouldn't be nice if i can only work with one database..so tell me what to do..
She wouldn't mind it at all ..she told us to use all the codes we can .."The more complex your program the more marks you get" so yeah,
i watched the grand total codes...thanks alot..i tried to put it in my program and i changed the codes to my program's updated codes but by reset , when i put in my code it says file variable expected...im lost.. can i upload my updated program so you can eradicate the problem..also is it possible to have 3 "seeks","resets" because i have three databases and it wouldn't be nice if i can only work with one database..so tell me what to do..
Listen i tried the recent codes you sent for me (1) the grandtotals (2) the codes for the [b]add[/b]. i tried them separately but there were errors in them...i changed my codes when you told me about the "8.3" bit so instead of ddcdatabasefile i haave "ddcfile". I appreciate the advice on the add procedure but when i typed the codes they gave me errors. i put the codes under "type" "var" and also on the main menu the "assigns" but still no complete compilation..also the grandtotals...when i tried it before i tried the add codes you gave me..it was going good when i was changing the file names but when i reached the "reset" it told me "file variable expected" i tried allot of different codes but it still showed me the same thing. So i was wondering if you could just remove ,add,edit the codes in the bottom with my recently updated codes..
For the add procedure it is very intelligent especially the fact that it tells you which database you are adding but if it cannot work it's fine...and if it works how would i do the same for viewing the members or would it be necessary to have codes like that for viewing "i doubt" i said in my mind..
About the recursive calls "mainmenu" the teacher said she doesn't want to see the source code after she leaves the "AboutWCMF" page and the "Advert" page so i left it there.
I would appreciate it if you would check it out for me please.. thanks here it is , the updated one"different codes, plus yours"
p.s it isn't compiling
Program schoolSBA; {This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}
uses crt, dos;
Type
Databasefiletype = file of Memberdatabase;{THIS IS WHERE THE ERRORS START..ENLIGHTENING ME PLEASE}
Memberdatabase = record DDCFILE, DPIfile, DSGOfile: DatabasefileTYPE; Databasefiletype : file of Memberdatabase;
MemberDatabaseDDC = record {declaration of record}
MemberDatabaseDSGO = record Member_ID : string[10]; Member_Name:String[30]; Member_TicketPayment:integer; end;
var DDCFILE, DPIfile, DSGOfile:Databasefiletype; DDCfile : file of MemberDatabaseDDC; RecDDC: MemberDatabaseDDC; {variable for DDC record}
DPIfile: file of MemberDatabaseDPI; RecDPI: MemberDatabaseDPI;{variable for DPI record}
DSGOfile : file of MemberDatabaseDSGO; RecDSGO :MemberDatabaseDSGO; {variable for DSGO record}
Choice, count,i: integer;
Procedure Mainmenu; Forward;
{************************************************* *This Procedure is used to display the Main Menu * *of the program. * **************************************************}
{**********************************************************************} Procedure info; Begin GotoXY(10,6); Writeln('When viewing members, you will observe a blank'); Writeln('screen press the "up" or "down" arrow to start to view.'); END; {************************************************************************}
Procedure Viewmenu; {Procedure to display intro} Begin clrscr; TextColor(BLACK); Textbackground(WHITE); Clrscr; GotoXY (1,4); WriteLn( '
Listen i tried the recent codes you sent for me (1) the grandtotals (2) the codes for the [b]add[/b]. i tried them separately but there were errors in them...i changed my codes when you told me about the "8.3" bit so instead of ddcdatabasefile i haave "ddcfile". I appreciate the advice on the add procedure but when i typed the codes they gave me errors. i put the codes under "type" "var" and also on the main menu the "assigns" but still no complete compilation..also the grandtotals...when i tried it before i tried the add codes you gave me..it was going good when i was changing the file names but when i reached the "reset" it told me "file variable expected" i tried allot of different codes but it still showed me the same thing. So i was wondering if you could just remove ,add,edit the codes in the bottom with my recently updated codes..
For the add procedure it is very intelligent especially the fact that it tells you which database you are adding but if it cannot work it's fine...and if it works how would i do the same for viewing the members or would it be necessary to have codes like that for viewing "i doubt" i said in my mind..
About the recursive calls "mainmenu" the teacher said she doesn't want to see the source code after she leaves the "AboutWCMF" page and the "Advert" page so i left it there.
I would appreciate it if you would check it out for me please.. thanks here it is , the updated one"different codes, plus yours"
p.s it isn't compiling
Program schoolSBA; {This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}
uses crt, dos;
Type
Databasefiletype = file of Memberdatabase;{THIS IS WHERE THE ERRORS START..ENLIGHTENING ME PLEASE}
Memberdatabase = record DDCFILE, DPIfile, DSGOfile: DatabasefileTYPE; Databasefiletype : file of Memberdatabase;
MemberDatabaseDDC = record {declaration of record}
MemberDatabaseDSGO = record Member_ID : string[10]; Member_Name:String[30]; Member_TicketPayment:integer; end;
var DDCFILE, DPIfile, DSGOfile:Databasefiletype; DDCfile : file of MemberDatabaseDDC; RecDDC: MemberDatabaseDDC; {variable for DDC record}
DPIfile: file of MemberDatabaseDPI; RecDPI: MemberDatabaseDPI;{variable for DPI record}
DSGOfile : file of MemberDatabaseDSGO; RecDSGO :MemberDatabaseDSGO; {variable for DSGO record}
Choice, count,i: integer;
Procedure Mainmenu; Forward;
{************************************************* *This Procedure is used to display the Main Menu * *of the program. * **************************************************}
{**********************************************************************} Procedure info; Begin GotoXY(10,6); Writeln('When viewing members, you will observe a blank'); Writeln('screen press the "up" or "down" arrow to start to view.'); END; {************************************************************************}
Procedure Viewmenu; {Procedure to display intro} Begin clrscr; TextColor(BLACK); Textbackground(WHITE); Clrscr; GotoXY (1,4); WriteLn( '
[blue] : She wouldn't mind it at all ..she told us to use all the codes we : can .."The more complex your program the more marks you get" so : yeah, : : i watched the grand total codes...thanks alot..i tried to put it in : my program and i changed the codes to my program's updated codes but : by reset , when i put in my code it says file variable expected...im : lost.. : can i upload my updated program so you can eradicate the : problem..also is it possible to have 3 "seeks","resets" because i : have three databases and it wouldn't be nice if i can only work with : one database..so tell me what to do.. : : thanks : [/blue] I'm afraid I've only succeeded in confusing you.
My suggestion that you have one procedure to handle all three databases is an "all in" kind of thing. If you are going to use only one procedure to handle all three databases I'm afraid you have to use the same strategy with [b]viewing[/b].
I think it would be simpler to retreat to your original strategy of using three different procedures for each database. On the other hand, if you teacher is giving more credit for more complex code then you may want to go forward with the one procedure approach I suggested.
Your call. Get back with me as soon as possible. I want to help. I'm working on your code.
BTW, do I understand correctly that your teacher is not going to look at your code? Just run the program?
[blue] : She wouldn't mind it at all ..she told us to use all the codes we : can .."The more complex your program the more marks you get" so : yeah, : : i watched the grand total codes...thanks alot..i tried to put it in : my program and i changed the codes to my program's updated codes but : by reset , when i put in my code it says file variable expected...im : lost.. : can i upload my updated program so you can eradicate the : problem..also is it possible to have 3 "seeks","resets" because i : have three databases and it wouldn't be nice if i can only work with : one database..so tell me what to do.. : : thanks : [/blue] This compiles and seems to work. I'm still working on it. Will get back to you.
What I've done really needs to be explained in more detail. [code] Program schoolSBA ; {[RED] version 2.11 -- i.e., Feb 11 [/RED]} {This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}
uses crt, dos ;
CONST DDC_FILE_NAME = 'ddc_file.dat' ; {[RED] These are the 3 file names. Change to suit! [/RED]} DPI_FILE_NAME = 'dpi_file.dat' ; {[RED] Must conform to the DOS 8.3 format. [/RED]} DSGO_FILE_NAME = 'dsgofile.dat' ;
Type MemberDatabase = record {declaration of record} Member_ID : string[10] ; Member_Name : string[30] ; Member_TicketPayment : integer ; Advert : string end ;
DatabaseFileType = file of MemberDatabase ;
var DDCfile, {[RED] the three file variables [/RED]} DPIfile, {[RED] a.k.a. file handles [/RED]} DSGOfile : DatabaseFileType ; {[RED] a.s.a. file descriptors or file identifiers [/RED]} {[RED] Pascal programmers prefer "file variables" and that's what the compiler calls them. [/RED]}
RecDDC, { variable for DDC record } RecDPI, { variable for DPI record } RecDSGO : MemberDatabase ; { variable for DSGO record }
Choice, count, i : integer ;
Procedure Mainmenu ; Forward ; {************************************************* *This Procedure is used to display the Main Menu * *of the program. * **************************************************}
{**********************************************************************} Procedure info ; Begin GotoXY(10,6) ; Writeln('When viewing members, you will observe a blank') ; Writeln('screen press the "up" or "down" arrow to start to view.') ; END ; {************************************************************************}
Procedure Viewmenu ; {Procedure to display intro} Begin clrscr ; TextColor(BLACK) ; Textbackground(WHITE) ; Clrscr ; GotoXY (1,4) ; WriteLn('
Comments
[code]
{[red]
this modification of the program attempts to improve the code
by eliminating recursive calls
[/red]}
Program schoolSBA;
{This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}
uses crt ; (*, dos,graph; *)
{[red]
"dos" and "graph" have been commented out.
"dos" does not appear to be needed.
I do not have "graph" so I have comment it out also and have substituted
your previous version of "advert"
[/red]}
Type
MemberDatabaseDDC = record {declaration of record}
Member_ID : string[10];
Member_Name:String[30];
Member_TicketPayment:integer;
Advert:string;
end;
MemberDatabaseDPI=record
Member_IDdpi : string[10];
Member_Namedpi:String[30];
Member_TicketPaymentdpi:integer;
end;
MemberDatabaseDSGO = record
Member_IDdsgo : string[10];
Member_Namedsgo:String[30];
Member_TicketPaymentdsgo:integer;
end;
var
DDCDatabasefile : file of MemberDatabaseDDC;
DatabaseRecDDC: MemberDatabaseDDC; {variable for DDC record}
DPIDatabasefile: file of MemberDatabaseDPI;
DatabaseRecDPI: MemberDatabaseDPI;{variable for DPI record}
DSGODatabasefile : file of MemberDatabaseDSGO;
DatabaseRecDSGO :MemberDatabaseDSGO; {variable for DSGO record}
Choice, count,i: integer;
Databasename : String;
Var Gd, Gm,
Radius, Grow, IncP, IncQ : Integer;
DecrP, DecrQ : Boolean;
{[red]
the forward declaration for the procedure mainmenu
was at this point. it is eleminated as no longer needed
[/red]}
Procedure Viewmenu;
{Procedure to display intro}
{[red]
this is a well written procedure
[/red]}
Begin
clrscr;
TextColor(white);
Textbackground(Black);
Clrscr;
GotoXY (1,4);
WriteLn('
I want to discuss your procedure [b]add[/b].
[code]
(*184*)
(*185*) Procedure Add;
(*186*) {*************************************************************************
(*187*) * This Procedure is used to ask the user which database he would like to *
(*188*) * use to add records to the respective groups. *
(*189*) *************************************************************************}
(*190*) var
(*191*) Ans : char;
(*192*) choice:integer;
(*193*) begin
(*194*) clrscr;
(*195*)
(*196*) Textcolor(Black);
(*197*) Textbackground(White);
(*198*) GotoXY(8,2);
(*199*) Writeln ('
[code]
procedure grandtotals ;
{
******************************************************
* This Procedure is used to identify the totals that *
* each group pays and the total of all three groups. *
******************************************************
}
function getcost (databasefile : databasefiletype) : integer ;
{
get total of payments from a database
}
var
cost : integer ;
i, { loop index }
n : longint ; { index of last record }
databasefile : databasefiletype ;
databaserec : memberdatabase ;
begin { getcost }
{$I-}
cost := 0 ;
reset(databasefile) ;
if ioresult > 0 then begin { cannot open database so ... }
getcost := 0 ; { return zero ... }
exit { and bug out }
end ;
n := filesize(databasefile) - 1 ;
for i := 0 to n do begin
seek(databasefile, i) ;
read(databasefile, databaserec) ;
with databaserec do
cost := cost + member_ticketpayment
end ;
close(databasefile) ;
getcost := cost
{$I+}
end ; { getcost }
var
costddc,
costdpi,
costdsgo,
total : integer ;
begin
{
first do the work
}
costddc := getcost(DDCdatabasefile) ;
costdpi := getcost(DPIdatabasefile) ;
costdsgo := getcost(DSGOdatabasefile) ;
total := costddc + costdpi + costdsgo ;
{
then display results
}
clrscr ;
gotoxy(12,2) ; write('
thanks for the advice about the assighns and the add procedure..i'll get to it as soon as possible because the deadline is due next month..
i have a query..do i have to do the same thing for add for procedure viewing...like putting the assigns for viewing in the main menu?
thanks
thanks for the advice about the assighns and the add procedure..i'll get to it as soon as possible because the deadline is due next month..
i have a query..do i have to do the same thing for add for procedure viewing...like putting the assigns for viewing in the main menu?
thanks
: viewing...like putting the assigns for viewing in the main menu?
Well, yes and no. That's just the way [italic]I[/italic] would do it. There's almost never just one way to do something.
Here are a couple of examples to show what I was suggesting. The first example shows how I envision the structure of your program.
In lines 7, 8, 9 I define three string constants with the names of the three files. In lines 22, 23, 24 I declare three "file variables." In the main program, lines 168, 169, 170, the three variables are assigned to the three string constants.
In line 50 the procedure [b]add_member[/b] receives the file variable from the calling procedure [b]add[/b], lines 67, 68. 69. In [b]add_member[/b] the file variable [b]f[/b] actually becomes the file variable [b]ddc_file, dpi_file[/b] or [b]dsg_file[/b], depending on which line in [b]add[/b] called it.
A similar thing happens in [b]del_member, edit_member[/b] and [b]view_member[/b].
[code]
{ 1} {
{ 2} example of passing "file variables" to procedures
{ 3} }
{ 4} program schoolsba ;
{ 5}
{ 6} CONST
{ 7} DDC_NAME = 'memberdb.ddc' ;
{ 8} DPI_NAME = 'memberdb.dpi' ;
{ 9} DSG_NAME = 'memberdb.dsg' ;
{ 10}
{ 11} type
{ 12} recordtype = record
{ 13} id_number : string[10] ;
{ 14} name : string[30] ;
{ 15} payment : integer ;
{ 16} advert : string
{ 17} end ;
{ 18}
{ 19} filetype = file of recordtype ;
{ 20}
{ 21} var
{ 22} ddc_file,
{ 23} dpi_file,
{ 24} dsg_file : filetype ;
{ 25}
{ 26} procedure viewmenu ;
{ 27} begin
{ 28} {
{ 29} your code here
{ 30} }
{ 31} end ;
{ 32}
{ 33} procedure mainmenu ;
{ 34}
{ 35} procedure advertisement ;
{ 36} begin
{ 37} {
{ 38} your code here
{ 39} }
{ 40} end ;
{ 41}
{ 42} procedure aboutwcmf ;
{ 43} begin
{ 44} {
{ 45} your code here
{ 46} }
{ 47} end ;
{ 48}
{ 49} procedure add ;
{ 50} procedure add_member (var f : filetype) ;
{ 51} begin
{ 52} {
{ 53} your code here
{ 54}
{ 55} the file variable f points to whichever file
{ 56} was passed to the child procedure by the
{ 57} parent procedure.
{ 58} }
{ 59} end ;
{ 60} begin
{ 61} repeat
{ 62} {
{ 63} your code here
{ 64} }
{ 65} read (choice) ;
{ 66} case choice of
{ 67} 1 : add_member(ddc_file) ;
{ 68} 2 : add_member(dpi_file) ;
{ 69} 3 : add_member(dsg_file)
{ 70} end { case }
{ 71} until choice = 4
{ 72} end ;
{ 73}
{ 74} procedure del ;
{ 75} procedure del_member (var f : filetype) ;
{ 76} begin
{ 77} {
{ 78} your code here
{ 79}
{ 80} the file variable f points to whichever file
{ 81} was passed to the child procedure by the
{ 82} parent procedure.
{ 83} }
{ 84} end ;
{ 85} begin
{ 86} repeat
{ 87} {
{ 88} your code here
{ 89} }
{ 90} read (choice) ;
{ 91} case choice of
{ 92} 1 : del_member(ddc_file) ;
{ 93} 2 : del_member(dpi_file) ;
{ 94} 3 : del_member(dsg_file)
{ 95} end { case }
{ 96} until choice = 4
{ 97} end ;
{ 98}
{ 99} procedure edit ;
{100} procedure edit_member (var f : filetype) ;
{101} begin
{102} {
{103} your code here
{104}
{105} the file variable f points to whichever file
{106} was passed to the child procedure by the
{107} parent procedure.
{108} }
{109} end ;
{110} begin
{111} repeat
{112} {
{113} your code here
{114} }
{115} read (choice) ;
{116} case choice of
{117} 1 : edit_member(ddc_file) ;
{118} 2 : edit_member(dpi_file) ;
{119} 3 : edit_member(dsg_file)
{120} end { case }
{121} until choice = 4
{122} end ;
{123}
{124}
{125} procedure view ;
{126} procedure view_member (var f : filetype) ;
{127} begin
{128} {
{129} your code here
{130}
{131} the file variable f points to whichever file
{132} was passed to the child procedure by the
{133} parent procedure.
{134} }
{135} end ;
{136} begin
{137} repeat
{138} {
{139} your code here
{140} }
{141} read (choice) ;
{142} case choice of
{143} 1 : view_member(ddc_file) ;
{144} 2 : view_member(dpi_file) ;
{145} 3 : view_member(dsg_file)
{146} end { case }
{147} until choice = 4
{148} end ;
{149}
{150} begin
{151} repeat
{152} {
{153} your code here
{154} }
{155} read (choice) ;
{156} case choice of
{157} 1 : advertisement ;
{158} 2 : aboutwcmf ;
{159} 3 : add ; { to add records }
{160} 4 : del ; { to delete records }
{161} 5 : edit ; { to edit records }
{162} 6 : view { to view records }
{163} end { case }
{164} until choice = 7
{165} end ;
{166}
{167} begin
{168} assign (ddc_file, DDC_NAME) ;
{169} assign (dpi_file, DPI_NAME) ;
{170} assign (dsg_file, DSG_NAME) ;
{171}
{172} viewmenu ;
{173} mainmenu
{174} end.
[/code]
In this second example the string constants are declared just as in the first but the file variables are declared in the individual procedures [b]add_member, del_member, edit_member[/b] and [b]view_member[/b]. Instead the file names (the string constants) are each passed to the procedures and assigned in the procedures. The file variables should also be declared inside the individual procedures.
[code]
{ 1} {
{ 2} example of passing "file names" to procedures
{ 3} }
{ 4} program schoolsba ;
{ 5}
{ 6} CONST
{ 7} DDC_NAME = 'memberdb.ddc' ;
{ 8} DPI_NAME = 'memberdb.dpi' ;
{ 9} DSG_NAME = 'memberdb.dsg' ;
{ 10}
{ 11} type
{ 12} recordtype = record
{ 13} id_number : string[10] ;
{ 14} name : string[30] ;
{ 15} payment : integer ;
{ 16} advert : string
{ 17} end ;
{ 18}
{ 19} procedure viewmenu ;
{ 20} begin
{ 21} {
{ 22} your code here
{ 23} }
{ 24} end ;
{ 25}
{ 26} procedure mainmenu ;
{ 27}
{ 28} procedure advertisement ;
{ 29} begin
{ 30} {
{ 31} your code here
{ 32} }
{ 33} end ;
{ 34}
{ 35} procedure aboutwcmf ;
{ 36} begin
{ 37} {
{ 38} your code here
{ 39} }
{ 40} end ;
{ 41}
{ 42} procedure add ;
{ 43} procedure add_member (fname : string) ;
{ 44} var
{ 45} f : file of recordtype ;
{ 46} begin
{ 47} {
{ 48} the parent procedure passes a file name, rather than
{ 49} a file variable, to the child procedure. The child
{ 50} procedure must have its own assign statement.
{ 51} }
{ 52} assign (f, fname) ;
{ 53} {
{ 54} your code here
{ 55} }
{ 56} end ;
{ 57} begin
{ 58} repeat
{ 59} {
{ 60} your code here
{ 61} }
{ 62} read (choice) ;
{ 63} case choice of
{ 64} 1 : add_member(DDC_NAME) ;
{ 65} 2 : add_member(DPI_NAME) ;
{ 66} 3 : add_member(DSG_NAME)
{ 67} end { case }
{ 68} until choice = 4
{ 69} end ;
{ 70}
{ 71} procedure del ;
{ 72} procedure del_member (fname : string) ;
{ 73} var
{ 74} f : file of recordtype ;
{ 75} begin
{ 76} assign (f, fname) ;
{ 77} {
{ 78} your code here
{ 79} }
{ 80} end ;
{ 81} begin
{ 82} repeat
{ 83} {
{ 84} your code here
{ 85} }
{ 86} read (choice) ;
{ 87} case choice of
{ 88} 1 : del_member(DDC_NAME) ;
{ 89} 2 : del_member(DPI_NAME) ;
{ 90} 3 : del_member(DSG_NAME)
{ 91} end { case }
{ 92} until choice = 4
{ 93} end ;
{ 94}
{ 95} procedure edit ;
{ 96} procedure edit_member (fname : string) ;
{ 97} var
{ 98} f : file of recordtype ;
{ 99} begin
{100} assign (f, fname) ;
{101} {
{102} your code here
{103} }
{104} end ;
{105} begin
{106} repeat
{107} {
{108} your code here
{109} }
{110} read (choice) ;
{111} case choice of
{112} 1 : edit_member(DDC_NAME) ;
{113} 2 : edit_member(DPI_NAME) ;
{114} 3 : edit_member(DSG_NAME)
{115} end { case }
{116} until choice = 4
{117} end ;
{118}
{119} procedure view ;
{120} procedure view_member (fname : string) ;
{121} var
{122} f : file of recordtype ;
{123} begin
{124} assign (f, fname) ;
{125} {
{126} your code here
{127} }
{128} end ;
{129} begin
{130} repeat
{131} {
{132} your code here
{133} }
{134} read (choice) ;
{135} case choice of
{136} 1 : view_member(DDC_NAME) ;
{137} 2 : view_member(DPI_NAME) ;
{138} 3 : view_member(DSG_NAME)
{139} end { case }
{140} until choice = 4
{141} end ;
{142}
{143} begin
{144} repeat
{145} {
{146} your code here
{147} }
{148} read (choice) ;
{149} case choice of
{150} 1 : advertisement ;
{151} 2 : aboutwcmf ;
{152} 3 : add ; { to add records }
{153} 4 : del ; { to delete records }
{154} 5 : edit ; { to edit records }
{155} 6 : view { to view records }
{156} end { case }
{157} until choice = 7
{158} end ;
{159}
{160} begin
{161} viewmenu ;
{162} mainmenu
{163} end.
[/code]
Both ways have their advantages and disadvantages. I prefer the first.
In your program you write several on-screen messages such as:
"Welcome to the DDC database"
which works if you have a different procedure for each database. But if you have only one procedure it has to know which file was passed to it. The only way to do this is with a call such as
[code]1 : add_member(ddc_file, DDC_NAME)[/code]
and a procedure declaration like
[code]procedure add_member(var f : filetype ; fname : string)[/code]
Whichever method you use the message is written out with
[code]write('Welcome to the ', copy(fname, 1, 3), ' database') ;[/code]
I hope all this is helping. I sometimes get the feeling that I'm giving you more problems than help.
i watched the grand total codes...thanks alot..i tried to put it in my program and i changed the codes to my program's updated codes but by reset , when i put in my code it says file variable expected...im lost..
can i upload my updated program so you can eradicate the problem..also is it possible to have 3 "seeks","resets" because i have three databases and it wouldn't be nice if i can only work with one database..so tell me what to do..
thanks
i watched the grand total codes...thanks alot..i tried to put it in my program and i changed the codes to my program's updated codes but by reset , when i put in my code it says file variable expected...im lost..
can i upload my updated program so you can eradicate the problem..also is it possible to have 3 "seeks","resets" because i have three databases and it wouldn't be nice if i can only work with one database..so tell me what to do..
thanks
i watched the grand total codes...thanks alot..i tried to put it in my program and i changed the codes to my program's updated codes but by reset , when i put in my code it says file variable expected...im lost..
can i upload my updated program so you can eradicate the problem..also is it possible to have 3 "seeks","resets" because i have three databases and it wouldn't be nice if i can only work with one database..so tell me what to do..
thanks....
you have been a great help
Listen i tried the recent codes you sent for me (1) the grandtotals (2) the codes for the [b]add[/b]. i tried them separately but there were errors in them...i changed my codes when you told me about the "8.3" bit so instead of ddcdatabasefile i haave "ddcfile". I appreciate the advice on the add procedure but when i typed the codes they gave me errors. i put the codes under "type" "var" and also on the main menu the "assigns" but still no complete compilation..also the grandtotals...when i tried it before i tried the add codes you gave me..it was going good when i was changing the file names but when i reached the "reset" it told me "file variable expected" i tried allot of different codes but it still showed me the same thing. So i was wondering if you could just remove ,add,edit the codes in the bottom with my recently updated codes..
For the add procedure it is very intelligent especially the fact that it tells you which database you are adding but if it cannot work it's fine...and if it works how would i do the same for viewing the members or would it be necessary to have codes like that for viewing "i doubt" i said in my mind..
About the recursive calls "mainmenu" the teacher said she doesn't want to see the source code after she leaves the "AboutWCMF" page and the "Advert" page so i left it there.
I would appreciate it if you would check it out for me please..
thanks here it is , the updated one"different codes, plus yours"
p.s it isn't compiling
Program schoolSBA;
{This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}
uses crt, dos;
Type
Databasefiletype = file of Memberdatabase;{THIS IS WHERE THE ERRORS START..ENLIGHTENING ME PLEASE}
Memberdatabase = record
DDCFILE,
DPIfile,
DSGOfile: DatabasefileTYPE;
Databasefiletype : file of Memberdatabase;
MemberDatabaseDDC = record {declaration of record}
Member_ID : string[10];
Member_Name:String[30];
Member_TicketPayment:integer;
Advert:string;
end;
MemberDatabaseDPI=record
Member_ID : string[10];
Member_Name:String[30];
Member_TicketPayment:integer;
end;
MemberDatabaseDSGO = record
Member_ID : string[10];
Member_Name:String[30];
Member_TicketPayment:integer;
end;
var
DDCFILE,
DPIfile,
DSGOfile:Databasefiletype;
DDCfile : file of MemberDatabaseDDC;
RecDDC: MemberDatabaseDDC; {variable for DDC record}
DPIfile: file of MemberDatabaseDPI;
RecDPI: MemberDatabaseDPI;{variable for DPI record}
DSGOfile : file of MemberDatabaseDSGO;
RecDSGO :MemberDatabaseDSGO; {variable for DSGO record}
Choice, count,i: integer;
Procedure Mainmenu; Forward;
{*************************************************
*This Procedure is used to display the Main Menu *
*of the program. *
**************************************************}
{**********************************************************************}
Procedure info;
Begin
GotoXY(10,6);
Writeln('When viewing members, you will observe a blank');
Writeln('screen press the "up" or "down" arrow to start to view.');
END;
{************************************************************************}
Procedure Viewmenu;
{Procedure to display intro}
Begin
clrscr;
TextColor(BLACK);
Textbackground(WHITE);
Clrscr;
GotoXY (1,4);
WriteLn( '
Listen i tried the recent codes you sent for me (1) the grandtotals (2) the codes for the [b]add[/b]. i tried them separately but there were errors in them...i changed my codes when you told me about the "8.3" bit so instead of ddcdatabasefile i haave "ddcfile". I appreciate the advice on the add procedure but when i typed the codes they gave me errors. i put the codes under "type" "var" and also on the main menu the "assigns" but still no complete compilation..also the grandtotals...when i tried it before i tried the add codes you gave me..it was going good when i was changing the file names but when i reached the "reset" it told me "file variable expected" i tried allot of different codes but it still showed me the same thing. So i was wondering if you could just remove ,add,edit the codes in the bottom with my recently updated codes..
For the add procedure it is very intelligent especially the fact that it tells you which database you are adding but if it cannot work it's fine...and if it works how would i do the same for viewing the members or would it be necessary to have codes like that for viewing "i doubt" i said in my mind..
About the recursive calls "mainmenu" the teacher said she doesn't want to see the source code after she leaves the "AboutWCMF" page and the "Advert" page so i left it there.
I would appreciate it if you would check it out for me please..
thanks here it is , the updated one"different codes, plus yours"
p.s it isn't compiling
Program schoolSBA;
{This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}
uses crt, dos;
Type
Databasefiletype = file of Memberdatabase;{THIS IS WHERE THE ERRORS START..ENLIGHTENING ME PLEASE}
Memberdatabase = record
DDCFILE,
DPIfile,
DSGOfile: DatabasefileTYPE;
Databasefiletype : file of Memberdatabase;
MemberDatabaseDDC = record {declaration of record}
Member_ID : string[10];
Member_Name:String[30];
Member_TicketPayment:integer;
Advert:string;
end;
MemberDatabaseDPI=record
Member_ID : string[10];
Member_Name:String[30];
Member_TicketPayment:integer;
end;
MemberDatabaseDSGO = record
Member_ID : string[10];
Member_Name:String[30];
Member_TicketPayment:integer;
end;
var
DDCFILE,
DPIfile,
DSGOfile:Databasefiletype;
DDCfile : file of MemberDatabaseDDC;
RecDDC: MemberDatabaseDDC; {variable for DDC record}
DPIfile: file of MemberDatabaseDPI;
RecDPI: MemberDatabaseDPI;{variable for DPI record}
DSGOfile : file of MemberDatabaseDSGO;
RecDSGO :MemberDatabaseDSGO; {variable for DSGO record}
Choice, count,i: integer;
Procedure Mainmenu; Forward;
{*************************************************
*This Procedure is used to display the Main Menu *
*of the program. *
**************************************************}
{**********************************************************************}
Procedure info;
Begin
GotoXY(10,6);
Writeln('When viewing members, you will observe a blank');
Writeln('screen press the "up" or "down" arrow to start to view.');
END;
{************************************************************************}
Procedure Viewmenu;
{Procedure to display intro}
Begin
clrscr;
TextColor(BLACK);
Textbackground(WHITE);
Clrscr;
GotoXY (1,4);
WriteLn( '
: She wouldn't mind it at all ..she told us to use all the codes we
: can .."The more complex your program the more marks you get" so
: yeah,
:
: i watched the grand total codes...thanks alot..i tried to put it in
: my program and i changed the codes to my program's updated codes but
: by reset , when i put in my code it says file variable expected...im
: lost..
: can i upload my updated program so you can eradicate the
: problem..also is it possible to have 3 "seeks","resets" because i
: have three databases and it wouldn't be nice if i can only work with
: one database..so tell me what to do..
:
: thanks
:
[/blue]
I'm afraid I've only succeeded in confusing you.
My suggestion that you have one procedure to handle all three databases is an "all in" kind of thing. If you are going to use only one procedure to handle all three databases I'm afraid you have to use the same strategy with [b]viewing[/b].
I think it would be simpler to retreat to your original strategy of using three different procedures for each database. On the other hand, if you teacher is giving more credit for more complex code then you may want to go forward with the one procedure approach I suggested.
Your call. Get back with me as soon as possible. I want to help. I'm working on your code.
BTW, do I understand correctly that your teacher is not going to look at your code? Just run the program?
What textbook are you using?
: She wouldn't mind it at all ..she told us to use all the codes we
: can .."The more complex your program the more marks you get" so
: yeah,
:
: i watched the grand total codes...thanks alot..i tried to put it in
: my program and i changed the codes to my program's updated codes but
: by reset , when i put in my code it says file variable expected...im
: lost..
: can i upload my updated program so you can eradicate the
: problem..also is it possible to have 3 "seeks","resets" because i
: have three databases and it wouldn't be nice if i can only work with
: one database..so tell me what to do..
:
: thanks
:
[/blue]
This compiles and seems to work. I'm still working on it. Will get back to you.
What I've done really needs to be explained in more detail.
[code]
Program schoolSBA ; {[RED] version 2.11 -- i.e., Feb 11 [/RED]}
{This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}
uses crt, dos ;
CONST
DDC_FILE_NAME = 'ddc_file.dat' ; {[RED] These are the 3 file names. Change to suit! [/RED]}
DPI_FILE_NAME = 'dpi_file.dat' ; {[RED] Must conform to the DOS 8.3 format. [/RED]}
DSGO_FILE_NAME = 'dsgofile.dat' ;
Type
MemberDatabase = record {declaration of record}
Member_ID : string[10] ;
Member_Name : string[30] ;
Member_TicketPayment : integer ;
Advert : string
end ;
DatabaseFileType = file of MemberDatabase ;
var
DDCfile, {[RED] the three file variables [/RED]}
DPIfile, {[RED] a.k.a. file handles [/RED]}
DSGOfile : DatabaseFileType ; {[RED] a.s.a. file descriptors or file identifiers [/RED]}
{[RED] Pascal programmers prefer
"file variables" and that's what the
compiler calls them. [/RED]}
RecDDC, { variable for DDC record }
RecDPI, { variable for DPI record }
RecDSGO : MemberDatabase ; { variable for DSGO record }
Choice, count, i : integer ;
Procedure Mainmenu ; Forward ;
{*************************************************
*This Procedure is used to display the Main Menu *
*of the program. *
**************************************************}
{**********************************************************************}
Procedure info ;
Begin
GotoXY(10,6) ;
Writeln('When viewing members, you will observe a blank') ;
Writeln('screen press the "up" or "down" arrow to start to view.') ;
END ;
{************************************************************************}
Procedure Viewmenu ;
{Procedure to display intro}
Begin
clrscr ;
TextColor(BLACK) ;
Textbackground(WHITE) ;
Clrscr ;
GotoXY (1,4) ;
WriteLn('