Help(Project crisis)

13

Comments

  • The first error, in [red]red[/red], happens because the compiler does not know what [b]Memberdatabase[/b] is. The compiler is a "single pass" compiler. It does not look ahead.
    [code]
    Program schoolSBA;
    {This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}

    uses crt, dos;

    Type

    [red]Databasefiletype = file of Memberdatabase;[/red]{THIS IS WHERE THE ERRORS START..ENLIGHTENING ME PLEASE}

    Memberdatabase = record
    DDCFILE,
    DPIfile,
    DSGOfile: DatabasefileTYPE;
    Databasefiletype : file of Memberdatabase;
    [/code]
    This declaration needs to be made after you have declared [b]Memberdatabase[/b].
    [code]Program schoolSBA;
    {This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}

    uses crt, dos;

    Type

    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;

    [red]Databasefiletype = file of Memberdatabase;[/red]
    [/code]
  • Here's the second error. Now the compiler does not know what [b]DatabasefileTYPE[/b] is. You've gotten into a circular definition, which is not allowed (except with pointers, but that's an advanced subject I don't think you're ready for yet.)
    [code]
    Program schoolSBA;
    {This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}

    uses crt, dos;

    Type

    Memberdatabase = record
    DDCFILE,
    DPIfile,
    DSGOfile: [red]DatabasefileTYPE;[/red]
    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;

    Databasefiletype = file of Memberdatabase;
    [/code]
    But this is not the correct definition for [b]Memberdatabase[/b]. The innards of [b]Memberdatabase[/b] should be identical to [b]MemberdatabaseDDC[/b].
    [code]
    Program schoolSBA;
    {This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}

    uses crt, dos;

    Type

    [red]Memberdatabase = record
    Member_ID : string[10];
    Member_Name : String[30];
    Member_TicketPayment : integer;
    Advert : string;
    end;[/red]

    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;

    Databasefiletype = file of Memberdatabase;
    [/code]
  • The next three errors are caused by trying to define a variable more than once. The solution is simple: delete the offending lines.

    [code]
    Program schoolSBA;
    {This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}

    uses crt, dos;

    Type

    Memberdatabase = record
    Member_ID : string[10];
    Member_Name : String[30];
    Member_TicketPayment : integer;
    Advert : string;
    end;

    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;

    Databasefiletype = file of Memberdatabase;

    var

    DDCFILE,
    DPIfile,
    DSGOfile : Databasefiletype;
    [red]DDCfile : file of MemberDatabaseDDC;[/red]
    RecDDC: MemberDatabaseDDC; {variable for DDC record}

    [red]DPIfile: file of MemberDatabaseDPI;[/red]
    RecDPI: MemberDatabaseDPI;{variable for DPI record}

    [red]DSGOfile : file of MemberDatabaseDSGO;[/red]
    RecDSGO :MemberDatabaseDSGO; {variable for DSGO record}

    Choice, count,i: integer;
    [/code]
  • The next error is in the procedure [b]View_RecordsDDC[/b]. The problem here is that the file [b]DDCfile[/b] is of type [b]Databasefiletype[/b], and [b]Databasefiletype[/b] is defined as [b]file of Memberdatabase[/b]. But [b]RecDDC[/b] is of type [b]MemberDatabaseDDC[/b]. It doesn't matter that the innards of the two types, [B]MemberDatabaseDDC[/b] and [b]MemberDatabase[/b], are identical. As far as the compiler is concerned, it's not a match.
    [code]
    Procedure View_RecordsDDC;

    {***************************************************
    * This Procedure is used to view the information *
    * about the members in the DDC Database. *
    ***************************************************}
    CONST
    SIZE = 1 ; { max number or records to be displayed }
    Var
    Ans : INTEGER;
    count, { loop counter }
    n, { index of last record in database file }
    curr : longint ; { index of current record in database file }

    Begin
    Assign(DDCfile,'DDCDatabase.dat');
    {$I-}
    Reset(DDCfile);
    {$I+}
    n := filesize(DDCfile) - 1 ;
    curr := 1 ; { default value }

    repeat
    clrscr ;
    Info;
    For count := curr - (SIZE - 1) to curr do Begin
    if (count < 0) or (count > n) then
    continue ; { no record has index < 0 or > n }

    Seek(DDCfile,count);
    [red]Read(DDCfile,RecDDC);[/red]
    writeln;
    Textcolor(Black);
    Textbackground(White);

    With RECDDC do begin
    Writeln;
    writeln('Member Identification#:', Member_ID);
    writeln;
    writeln('name of Member: ', Member_Name);
    Writeln;
    Writeln;
    Writeln('Ticket Payment of member:$', Member_TicketPayment);
    Textcolor(Black);
    GotoXY(30,16);
    Writeln('....GO UP.');
    GotoXY(30,18);
    Writeln('....GO DOWN.');
    Gotoxy(30,20);
    Writeln('END....EXIT VIEW MODE.');

    end
    end;
    curr := nextrec(curr, n)
    until curr < -99 ;
    close(DDCfile);
    end;
    [/code]
    The solution is to go back to the declarations of [b]RecDDC, RecDPI[/b] and [b]RedDSGO[/b] and redefine them as [b]MemberDatabase[/b].
    [code]
    Program schoolSBA;
    {This program was written by Michael Jarvis, a student of the Saint Mary's Academy.}

    uses crt, dos;

    Type

    Memberdatabase = record
    Member_ID : string[10];
    Member_Name : String[30];
    Member_TicketPayment : integer;
    Advert : string;
    end;

    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;

    Databasefiletype = file of Memberdatabase;

    var

    DDCFILE,
    DPIfile,
    DSGOfile : Databasefiletype;
    [red]RecDDC : MemberDatabase;[/red] {variable for DDC record}

    [red]RecDPI : MemberDatabase;[/red]{variable for DPI record}

    [red]RecDSGO : MemberDatabase;[/red] {variable for DSGO record}

    Choice, count,i : integer;
    [/code]
  • Actor you're a mad genius in turbo pascal...thanks alot!!!! gosh you are a big help in making my program work amazing.

    Yes the teacher has to watch the codes plus the program(i have to give it to her on a cd). well if it is possible to put the [b]viewing members[/b][b] procedure in one procedure[/b] then ok but if not it's ok.

    is it possible to edit their info..plus i tried getting simple animations for my advert procedure but when i put the codes it told me i have some error. do you know of any good simple animations i can use. like fireworks or some moving objects and for me to still be able to see the info on the page.

    im using "Information Technology for CSEC" i live in the caribbean plus the teacher said the lower grades aren't going to use the book again.
    we never used that text book for programming because it doesn't have turbo pascal in it but "basic" and she said that turbo pascal is easier to use than basic so yeah.

    And again thanks..
    and do you know of any great "free" software to make flowcharts
    i used smart draw but my free version expired and finding a crack for it is not easy..



    Thanks for the help!!
  • The next error is in the procedure [b]getcost[/b].
    [code]
    [red]function getcost (databasefile : databasefiletype) :[/red] integer ;
    {
    get total of payments from a database
    }
    [/code]
    This has to do with the way variables are passed to procedures/functions. There are two ways: by [italic]value[/italic] and by [italic]reference[/italic].

    Consider the following function, which returns the cube of a number.
    [code]
    function cube (x : real) : real ;
    begin
    cube := x * x * x
    end ;
    [/code]
    and a code fragment that calls the function.
    [code]
    z := cube(x) ;
    [/code]
    This is an example of "pass by value." When the function is called it makes a copy of the passed variable. I.e., the [b]x[/b] in the function is a copy of the [b]x[/b] in the calling statement. The two exist at different places in memory. The fact they both have the same identifier does not matter. Both the child function and the parent know which [b]x[/b] to work with.

    Now suppose that [b]cube[/b] were a procedure instead of a function.
    [code]
    procedure cube (x : real) ;
    begin
    x := x * x * x
    end ;
    [/code]
    This turns out to be a do-nothing procedure because there is no way to get the modified value of [b]x[/b] back to the calling procedure. To do that we need to "pass by reference." This is done using the reserved word [b]var[/b].
    [code]
    procedure cube (var x : real) ;
    begin
    x := x * x * x
    end ;
    [/code]
    When a variable is passed by reference the called procedure/function does not make a copy of the variable. Instead it uses the actual variable passed to it. Consider
    [code]
    cube(z) ;
    [/code]
    This turns [b]z[/b] into its cube. It does not matter that the parent passes [b]z[/b] to the procedure and the procedure uses [b]x[/b] because [b]z[/b] and [b]x[/b] are the same thing. [b]x[/b] becomes a kind of nickname for [b]z[/b].
    [code]
    a := 2.0 ;
    b := 3.0 ;
    c := 4.0 ;
    cube(a) ;
    cube(b) ;
    cube(c) ;
    writeln (a:3:1, b:5:1, c:5:1) ;
    [/code]

    this will write out

    8.0 27.0 64.0

    Each time [b]cube[/b] is called [b]x[/b] becomes the same as [b]a, b[/b] and [b]c[/b] in turn.

    The thing is that you cannot make copies of file variables. The reason is technical and I won't go into that now. File variables must be passed by reference. Thus the correct version of [b]getcost[/b] is
    [code]
    function getcost ([red]var[/red] databasefile : databasefiletype) : integer ;
    {
    get total of payments from a database
    }
    [/code]

  • Another duplicate identifier. [b]databasefile[/b] is already defined 8 lines above. Same solution. Get rid of the offending line.
    [code]
    function getcost (var databasefile : databasefiletype) : integer ;
    {
    get total of payments from a database
    }
    var
    cost : integer ;
    i, { loop index }
    n : longint ; { index of last record }
    [red]databasefile : databasefiletype ;[/red]
    databaserec : memberdatabase ;

    [/code]
  • [blue]: Actor you're a mad genius in turbo pascal...[/blue]

    Thanks for the complement.

    [blue]: well if it is possible to put the
    : [b]viewing members[/b][b] procedure in one procedure[/b] then ok but
    : if not it's ok.[/blue]

    No problem.

    [blue]: is it possible to edit their info..[/blue]

    Editing info is possible. There are two strategies. One is to edit the info inside the [b]viewing[/b] procedure. The other is to have a separate procedure. For the user it's better to edit inside [b]viewing[/b] but for the programmer it's simpler to have a separate procedure. Your call.

    [blue]: plus i tried getting simple
    : animations for my advert procedure but when i put the codes it told
    : me i have some error. do you know of any good simple animations i
    : can use. like fireworks or some moving objects and for me to still
    : be able to see the info on the page.[/blue]

    Sorry, but my career was in databases and robotics. No experience with animation. Afraid I can't help there.

    [blue]: im using "Information Technology for CSEC"[/blue]

    I was hoping you were using a book that I already have. Checking at Amazon.com I find that that one's expensive.

    [blue]: and do you know of any great "free" software to make flowcharts[/blue]

    Afraid not.

    [blue]: Thanks for the help!![/blue]

    You're welcome.

  • [blue]: i live in the Caribbean[/blue]

    How's the weather down there. This afternoon I went to the store for supplies. Rode my scooter and darn near froze.
  • From what you've posted I'm assuming March 1 or shortly after.

  • The last error, "unknown identifier", occurs in the procedure [b]grandtotals[/b].
    [code]
    begin
    {
    first do the work
    }
    costddc := getcost([red]DDCdatabasefile[/red]) ;
    costdpi := getcost([red]DPIdatabasefile[/red]) ;
    costdsgo := getcost([red]DSGOdatabasefile[/red]) ;
    total := costddc + costdpi + costdsgo ;
    [/code]
    We need to change this to our new file names.
    [code]
    begin
    {
    first do the work
    }
    costddc := getcost([red]DDCfile[/red]) ;
    costdpi := getcost([red]DPIfile[/red]) ;
    costdsgo := getcost([red]DSGOfile[/red]) ;
    total := costddc + costdpi + costdsgo ;
    [/code]
    I think this is our last error and the program should compile.

  • Well i would rather have the user edit the info while viewing but i doubt the screen will have enough space so i guess you can make a separate procedure to edit their stuff...that's alright for the animation..the weather is getting hot ..it was cold for the beginning of the year as Christmas just passed. that book isn't really great.. the final project is due for march 17.

    thanks for the help as always!


  • Two more changes I would like to make to your code before I test it. The first is to change the file names in the assign statements in the main program to the ones you chose. As I've explained before Turbo Pascal will truncate these to 'DDCDatab.dat', 'DPIdatab.dat' and 'DSGOData.dat', but it's ok to keep the longer names in your code. It has good mnemonic value. I'm thinking that you know what the word "mnemonic" means. If you don't then google it or look it up in a dictionary. It's a word that should be in every programmer's vocabulary.
    [code]
    Begin{Main program}
    assign(DDCfile, '[red]DDCDatabase.dat[/red]');
    Assign(DPIFile, '[red]DPIDatabase.dat[/red]');
    assign(DSGOFILE, '[red]DSGODatabase.dat[/red]');

    clrscr;
    Viewmenu;
    Mainmenu;
    end.{End of program}
    [/code]
    [b]Assign[/b] appears at four other places in your code. One is in the procedure [b]file_exist[/b] which we won't worry about since it's dead code. I'll have more to say about dead code later. The other three are in [b]View_RecordsDDC, View_RecordsDPI[/b] and [b]View_RecordsDSGO[/b]. These are unnecessary since the three [b]assign[/b] statements in the main program associates each file variable with it's respective file, globally, throughout the program.

    I've commented these out rather than deleting them. This will make them easier to recover should their deletion have unexpected effects when we test, but I don't think it will.

    By the way, I use (* *) type comments for "deleting out" code and { } for all other comments. This is because you cannot nest { } comments inside other { } type comments. But you can nest { } comments inside (* *) comments (and vice versa). By following this practice I don't have to worry about an unexpected } ending my comment out.
    [code]
    Procedure View_RecordsDDC;

    {***************************************************
    * This Procedure is used to view the information *
    * about the members in the DDC Database. *
    ***************************************************}
    CONST
    SIZE = 1 ; { max number or records to be displayed }
    Var
    Ans : INTEGER;
    count, { loop counter }
    n, { index of last record in database file }
    curr : longint ; { index of current record in database file }

    Begin
    (*[red]
    Assign(DDCfile,'DDCDatabase.dat');
    [/red]*)
    {$I-}
    Reset(DDCfile);
    {$I+}
    [/code]
    [code]
    Procedure View_RecordsDPI;

    {***************************************************
    * This Procedure is used to view the information *
    * about the members in the DDC Database. *
    ***************************************************}
    CONST
    SIZE = 1; { max number or records to be displayed }
    Var
    Ans : INTEGER;
    count, { loop counter }
    n, { index of last record in database file }
    curr : longint ; { index of current record in database file }

    Begin
    (*[red]
    Assign(DPIFILE,'DPIDatabase.dat');
    [/red]*)
    {$I-}
    Reset(DPIfile);
    {$I+}
    [/code]
    [code]
    Procedure View_RecordsDSGO;

    {***************************************************
    * This Procedure is used to view the information *
    * about the members in the DDC Database. *
    ***************************************************}
    CONST
    SIZE = 1; { max number or records to be displayed }
    Var
    Ans : INTEGER;
    count, { loop counter }
    n, { index of last record in database file }
    curr : longint ; { index of current record in database file }

    Begin
    (*[red]
    Assign(DSGOfile,'DSGODATABASE.dat');
    [/red]*)
    {$I-}
    Reset(DSGOfile);
    {$I+}
    [/code]

  • I've been testing your code with the errors removed and the two changes I suggested. There are two small issues that are not exactly errors but I think they should be corrected. The first is in the procedure [b]grandtotals[/b]. As is it "falls off the end" and when it does the program terminates. This isn't exactly wrong but it's annoying to the user. To avoid it, if you are going to be using recursion, you need to add a call to [b]mainmenu[/b] as I show below in red.
    [code]
    procedure grandtotals ;
    {
    ******************************************************
    * This Procedure is used to identify the totals that *
    * each group pays and the total of all three groups. *
    ******************************************************
    }

    function getcost (var databasefile : databasefiletype) : integer ;
    {
    get total of payments from a database
    }
    var
    cost : integer ;
    i, { loop index }
    n : longint ; { index of last record }
    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(DDCfile) ;
    costdpi := getcost(DPIfile) ;
    costdsgo := getcost(DSGOfile) ;
    total := costddc + costdpi + costdsgo ;
    {
    then display results
    }
    clrscr ;
    gotoxy(12,2) ; write('

  • Pampaz: Check your messages.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories