Pascal Chapter 10 homework

Discussion in 'Mac Programming' started by larswik, Apr 17, 2011.

  1. macrumors 68000

    Joined:
    Sep 8, 2006
    #1
    I have my new Pascal assignment due Wednesday.

    Assignment : I have to READ in 2 data files. File 1 has 30 'Y' or 'N' and is the customer requests for the apartment. The second file has 5 line and each line has 30 'Y' or 'N' followed by an address. The goal is to read in the files and match up the customer with the best apartment by how many Yes's match and print out the address with it.

    For this assignment I must use an Array. The problem that I have is not a programing issue (yet), but this is the first project that I need to READ in 2 data files. when I run the program I don't know how to have it ask me for the second file?

    Code:
    program test(infile, outfile);
    
    type
    	ary = array[1..30] of char;
    
    var
    	custwants : array[1..30]of char;
    	infile, outfile : text;
    	i : integer;
    
    begin
    reset(infile);
    rewrite(outfile);
    (****  Read in Customers Wants*)
    for i := 1 to 30 do
    	read(infile, custwants[i]);
    	
    reset(infile);
    	
    for i := 1 to 30 do (* testing the read in*)
    	writeln(outfile, custwants[i]);
    end.
    I tried to use the RESET(INFILE) again hoping it would ask for another file, but it did not.

    -Lars
     
  2. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    Can you put more the 2 files in program statement?

    Code:
    program test(infile1, infile2, outfile);
    (* snip *)
    reset(infile1);
    reset(infile2);
    rewrite(outfile);
    
     
  3. thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #3
    Yes, that worked. I never thought about it that way. I thought I could just call infile again and it would ask me for another file.

    Thanks!

    -Lars
     
  4. macrumors 6502

    Joined:
    Apr 29, 2010
    #4
    Lars, you could associate the name "infile" with another external file instead of the current one. But the computer doesn't know what "infile" means. You could have replaced "infile" with "Donald_Duck," and your program would still have made the computer do what it did when you input file's internal name was "infile." The computer usually doesn't care what you call your variables, your files, your procedures, and so forth. But sometimes it'll complain when you try to use a programming language's keywords as, say, variable names. It'll complain when, for example, you try to declare a variable named "writeln."

    Years ago, when I learned Cobol, my professor proved my point when he wrote a whole program where the variable names didn't tell you what they stood for. He wrote something like, "Add Donald-Duck to Woody-Woodpecker giving two-birds." Or how about, "Perform Mac-N-Cheese 20 times."?
     
  5. thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #5
    Is what you are talking about 'reserved' words? I named it infile because I knew that was the best item for me to describe the process. When the program launches it asks for all the files up front to process. After jiminaus wrote that answer it clicked that what I write in the 'PROGRAM TEST (test1, test2, test 3);' Those are just 3 variables, or I think of them kind of like gate ways of passing the information from the outside to inside the program. I can make all the tests inputs or outputs.

    Thanks for the extra help.

    -Lars
     
  6. macrumors 6502

    Joined:
    Apr 29, 2010
    #6
    Yes, I'm talking about reserved words.

    Oops. Maybe I misinterpreted something Lars told us. I thought he thought the computer would automatically make "infile" stand for another input file any time the computer needed to use another one.

    I like the gateway analogy.

    My pleasure.
     
  7. macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #7
    Lars was under the mistaken impression that it was the reset/rewrite procedures which cause the file prompts, not the program parameters (the gateways, as from now on they'll be called here).
     
  8. macrumors 6502

    Joined:
    Apr 29, 2010
    #8
    Hmm, I wonder what gave him that impression. I don't see any connection between those procedures and those prompts.
     
  9. macrumors regular

    Joined:
    Jan 27, 2011
    #9
    Out of curiosity and admittedly OT, why is your prof teaching Pascal? :)
     
  10. macrumors 6502

    Joined:
    Apr 29, 2010
    #10
    Everybody knows that Pascal is better than C. ;)
     
  11. thread starter macrumors 68000

    Joined:
    Sep 8, 2006
    #11
    Wow lots of replies. Sorry, what I meant was the reset and rewrite. If I declared 3 variables of type Text I can make them all reset for input or rewrite for output. Before the problem was solved I tried to use 2 resets both named infile. I thought once it finished with 1 file it would then ask for the next, this was not the case.

    As for why the teacher is using Pascal he said the next version of smart phones will go back to an easier language, like Pascal :) No, JK, he said it was a straight forward language to learn and most everything we learn will be applied to other languages in the future.

    Although I had my midterm Monday and he only gave 1 hour 15 minutes to do it. my 40 year old brain is not as fast as these kids half my age. I only got 2/3's finished. The most I can get is a C if I got everything right on the test that I had time to do.

    -Lars
     

Share This Page