Results 1 to 6 of 6

Thread: Schoolwork Help

  1. #1
    Join Date
    Nov 2004
    Posts
    5,192
    Rep Power
    25

    Default Schoolwork Help

    Hi all. Have a school thing that I'd like a little assistance with for a friend. Last time I touched programming was probably in 94. Plan to get back into it and use Python still, but see if you can help me out on this.

    Needs to accept/store input to a file and be able to print the stored data basically. So like name and payment, then print and total the number of names and the sum of the payment.

    On a side note - I'd question why Pascal is still in use in schools. Is there some new version that doesn't run on DOS? I've seen -> http://www.freepascal.org/ <- but again I'm a bit confused as to why schools haven't moved on to C or VB.

    Thanks in advance for any assistance provided.

    *EDIT*

    So far I have what's below. If I can find out how to add the numbers that are searched for in a created file then that would be nice. Unless someone wants to help with the cleanup of the syntax if it needs be done?

    ADDING NUMBERS
    http://borlandpascal.wikia.com/wiki/...ng_two_numbers
    __________________________________________________ ___________________________________________
    var a,b,s:integer;
    begin
    write ('Type a: '); readln (a);
    write ('Type b: '); readln (b);
    s:=a+b;
    writeln ('The sum of a+b is ', s);
    readln;
    end.
    __________________________________________________ ___________________________________________


    CREATING A FILE AND WRITING DATA
    http://pascal-programming.info/lesson9.php
    __________________________________________________ ___________________________________________
    Program Lesson9_Program2;
    Var FName, Txt : String[10];
    UserFile : Text;

    Begin
    FName := 'Textfile';
    Assign(UserFile,'C:\'+FName+'.txt'); {assign a text file}
    Rewrite(UserFile); {open the file 'fname' for writing}
    Writeln(UserFile,'PASCAL PROGRAMMING');
    Writeln(UserFile,'if you did not understand something,');
    Writeln(UserFile,'please send me an email to:');
    Writeln(UserFile,'victorsaliba@hotmail.com');
    Writeln('Write some text to the file:');
    Readln(Txt);
    Writeln(UserFile,'');
    Writeln(UserFile,'The user entered this text:');
    Writeln(UserFile,Txt);
    Close(UserFile);
    End.
    __________________________________________________ ___________________________________________


    SEARCHING FOR STRING WITHIN FILE
    http://www.daniweb.com/software-deve.../threads/52166
    __________________________________________________ ___________________________________________
    procedure SearchingInFile(Filename, SearchStr :string);
    var
    SearchPos,
    FoundCount :integer;
    FileLine :string;
    SearchFile :Text;
    begin
    Assign(SearchFile, Filename);
    Reset(SearchFile);
    FoundCount := 0;
    while not EOF(SearchFile) do
    begin
    // the <strong class="highlight">search</strong> will be no case sensitive (using UpCase)
    FileLine := UpCase(Readln(SearchFile));
    SearchPos := Pos(UpCase(SearchStr), FileLine);
    if SearchPos > 0 then
    begin
    // looking for more SearchStr into FileLine
    while SearchPos > 0 do
    begin
    // add 1 to founded word count
    Inc(FoundCount);
    // Advance SearchPos
    SearchPos := SearchPos +Length(SearchStr).
    // remove substring before last word founded, including the word
    FileLine := Copy(FileLine, SearchPos, Length(FileLine));
    // check for a new occurence of searched word on line readed
    SearchPos := Pos(UpCase(SearchStr), FileLine);
    end;
    end;
    end;
    Close(SearchFile);
    end;
    __________________________________________________ ___________________________________________
    Last edited by khat17; Feb 5, 2012 at 08:54 PM.
    Knowing the solution doesn't mean knowing the method. Yet answering correctly and regurgitation are considered "learning" and "knowledge".

  2. #2
    Join Date
    May 2003
    Posts
    229
    Rep Power
    0

    Default

    Hi, I don't really understand what assistance you are asking for. You say "If I can find out how to add the numbers that are searched for in a created file then that would be nice.", but the first code snippet you give "Adding Numbers" shows you how to add numbers, so I am confused.

  3. #3
    Join Date
    Nov 2004
    Posts
    5,192
    Rep Power
    25

    Default

    So then how do I use the first code to add numbers pulled from the file? Bear in mind that I don't do this anymore so I have no idea what to use. Also what needs to be done is - total the number of names in the file - total the numbers in the file. Could you give some idea on how to do that?
    Knowing the solution doesn't mean knowing the method. Yet answering correctly and regurgitation are considered "learning" and "knowledge".

  4. #4
    Join Date
    May 2003
    Posts
    229
    Rep Power
    0

    Default

    Oh, you don't understand the code that you have so far (I'm not trying to insult you, I just didn't realize that before).

    I'm sorry but I can't teach you Pascal from scratch.

  5. #5
    Join Date
    Jan 2009
    Posts
    2,404
    Rep Power
    0

    Default

    Kinda rusty on programming myself too and I don't do/like Pascal, but my pseudocode skill sticks with me. So basically get input, write to file, read from file and print.

    0. Initialize variables.
    Code:
    declare variables: name, payment, etc (if required)
    set counter and sum to 0
    1. Loop to get input and write to file.
    Code:
    open file for writing
    loop
    check for sentinel (to exit loop)
    get user input to variable
    write variable to file
    ... (repeat for each variable: name, payment, etc)
    loop end
    2. Loop to read from file and print.
    Code:
    open file for reading
    loop
    read line from file
    check for EOF (to exit loop)
    make any data type conversions and put to variable
    increment counter
    update sum
    loop end
    print counter, sum
    That's what came off the top of my head. Just need to make it into code, eradicate the bugs, and you're done.
    Rooted OnePlus 2 64GB Ed, Android 5.1.1 OxygenOS ; on teifin' AT&T's network; Rooted ASUS Transformer TF101 w/ dock, Android 5.1 KatKiss; Laptop: ASUS X550C, 2.0GHzx2, 8GB, 512GB SSD, Kubuntu 15.10;
    Facebook page: Skeleville Technology Solutions

  6. #6
    Join Date
    Nov 2004
    Posts
    5,192
    Rep Power
    25

    Default

    Quote Originally Posted by sking View Post
    Oh, you don't understand the code that you have so far (I'm not trying to insult you, I just didn't realize that before).

    I'm sorry but I can't teach you Pascal from scratch.
    Thanks anyways. Doesn't mean that I don't understand the code - I can read and have an idea of what happens - it means that unlike when I was doing programming back in 94 I can't see what each variable does and how to tie them together. Having read through the codes that I pasted I can guess out what it does. I'd have loved to find my old programs because I remarked each section or line to ensure that going back to it I would know exactly what to do. But I'm not looking for a tutor as you suggest - currently trying to teach myself Python. No insult taken still - I'm completely dumb to programming now.

    Quote Originally Posted by Skele Drew View Post
    Kinda rusty on programming myself too and I don't do/like Pascal, but my pseudocode skill sticks with me. So basically get input, write to file, read from file and print.

    0. Initialize variables.
    Code:
    declare variables: name, payment, etc (if required)
    set counter and sum to 0
    1. Loop to get input and write to file.
    Code:
    open file for writing
    loop
    check for sentinel (to exit loop)
    get user input to variable
    write variable to file
    ... (repeat for each variable: name, payment, etc)
    loop end
    2. Loop to read from file and print.
    Code:
    open file for reading
    loop
    read line from file
    check for EOF (to exit loop)
    make any data type conversions and put to variable
    increment counter
    update sum
    loop end
    print counter, sum
    That's what came off the top of my head. Just need to make it into code, eradicate the bugs, and you're done.
    Thanks Drew. Think I had some of that in the first codes I pasted - what I need to do now is sum the results of searched values in the file.

    Looking at it all I recall some stuff - define the variables at the beginning of the program - set the different parts of the program - use if/else/then to go to the different parts of the program as needed - ensure that results are zeroed to clear values from additional calculations.

    So again what I need to do - the values can be searched for in the file using the info above - how do I then sum all values searched for? So let's say 10 persons with payments of 2 dollars. How do I get it to total that it was 10 persons with a total of 20 dollars?
    Last edited by khat17; Feb 7, 2012 at 08:20 AM.
    Knowing the solution doesn't mean knowing the method. Yet answering correctly and regurgitation are considered "learning" and "knowledge".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •