visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: Pascal :: Paramaters


By: VB guy Canada  Date: 26/02/2003 00:00:00  English  Points: 50 Status: Answered
Quality : Excellent
Hey,
This program is suppose to take 5 names, alphabetize them, and print them out. It uses records parameters and procedures. I don't relly understand how paramaters work, can someone please explain? Whenever I compile I get an type mismatch error. Heres the program:

program presidents (input, output);
uses
wincrt;
type
name=record
fname,mname,lname:string;
end;
arraytype=array [1..5] of name;
var
card:arraytype;
i,j:integer;
temp:name;
procedure ask (var ccard:arraytype;ii:integer);
begin
for ii:=1 to 5 do
begin
writeln('Type in the first name',ii);
readln(ccard[ii].fname);
writeln('Type in the middle name');
readln(ccard[ii].mname);
writeln('type in the last name');
readln(ccard[ii].lname);
clrscr;
end;
end;
procedure sort (var ttemp:name;ccard:arraytype;ii,jj:integer);
begin
for ii:= 1 to 5-1 do
begin
for jj:=1 to 5-1 do
begin
if (ccard[jj].lname) > (ccard[jj+1].lname) then
begin
ttemp:=ccard[jj];
ccard[jj]:=ccard[jj+1];
ccard[jj+1]:=ttemp;
end;
end;
end;
end;
procedure print (var ccard:arraytype;ii:integer);
begin
for ii:=1 to 5 do
begin
writeln(ii,'. ',ccard.fname,' ',ccard.mname,' ',ccard.lname); {do I define .lname as a paramater?}
end;
writeln('Brian Abbott');
end;
begin
ask (card,i);
sort (card,temp); {Error message is here}
print(card,i);
end.


By: VGR Date: 26/02/2003 02:34:00 English  Type : Comment
well, given the way it's written, no surprise you don't understand it quickly :D

ok, the main program : last three lines.
Call ask(card,i), then sort(), then print().
i is an integer, temp is a record of type "name", and card is an array[1..5] of that "name" type (hence records)

ok until now ?

ask() is pretty straithforward, as is print()

Apparently you'll end up with a compilation error on the line calling Sort(card,temp) BECAUSE sort() is defined this way (signature, prototype, whatever) :
procedure sort (var ttemp:name;ccard:arraytype;ii,jj:integer);

so it REQUIRES two extra parameters of type integer.

Given the body of the sort() procedure, you mistyped the declaration of the procedure sort().
It should read :
procedure sort (var ttemp:name;ccard:arraytype);
Var ii,jj:integer;

A part from this (your program will work seamlessly after this correction), I suggest you use the text editor to replace all "5" by "cMax" and define cMax after the "uses WinCrt;" line as :
Const cMax=5; // now easily modifiable for program's expansion.

PS : there are no procedure parameters in this program.

regards,
By: VGR Date: 26/02/2003 02:37:00 English  Type : Comment
and if ever this tells you something, Pascal records are just C "structs" (variant types included)

By: VB guy Date: 27/02/2003 06:10:00 English  Type : Comment
I still get the type mismatch error. I'm not sure if I did exactly what you said. I also doubled up the three i's at the print line. heres the new program.


program presidents (input, output);
uses
wincrt;
type
name=record
fname,mname,lname:string;
end;
arraytype=array [1..5] of name;
var
card:arraytype;
i,j:integer;
temp:name;
procedure ask (var ccard:arraytype;ii:integer);
begin
for ii:=1 to 5 do
begin
writeln('Type in the first name',ii);
readln(ccard[ii].fname);
writeln('Type in the middle name');
readln(ccard[ii].mname);
writeln('type in the last name');
readln(ccard[ii].lname);
clrscr;
end;
end;
procedure sort (var ttemp:name;ccard:arraytype);
VAR ii,jj:integer;
begin
for ii:= 1 to 5-1 do
begin
for jj:=1 to 5-1 do
begin
if (ccard[jj].lname) > (ccard[jj+1].lname) then
begin
ttemp:=ccard[jj];
ccard[jj]:=ccard[jj+1];
ccard[jj+1]:=ttemp;
end;
end;
end;
end;
procedure print (var ccard:arraytype;ii:integer);
begin
for ii:=1 to 5 do
begin
writeln(ii,'. ',ccard[ii].fname,' ',ccard[ii].mname,' ',ccard[ii].lname);
end;
writeln('Brian Abbott');
end;
begin
ask (card,i);
sort (card,temp);{type mismatch error}
print(card,i);
end.




By: VGR Date: 27/02/2003 06:18:00 English  Type : Comment
of course
the call is sort(temp,card), not card,temp

look at the definition
By: VB guy Date: 28/02/2003 01:15:00 English  Type : Comment
Hey, I still getthe same error at the call.
program presidents (input, output);
uses
wincrt;
type
name=record
fname,mname,lname:string;
end;
arraytype=array [1..5] of name;
var
card:arraytype;
i,j:integer;
temp:name;
procedure ask (var ccard:arraytype;ii:integer);
begin
for ii:=1 to 5 do
begin
writeln('Type in the first name',ii);
readln(ccard[ii].fname);
writeln('Type in the middle name');
readln(ccard[ii].mname);
writeln('type in the last name');
readln(ccard[ii].lname);
clrscr;
end;
end;
procedure sort (var ttemp:name;ccard:arraytype);
Var ii,jj:integer;

begin
for ii:= 1 to 5-1 do
begin
for jj:=1 to 5-1 do
begin
if (ccard[jj].lname) > (ccard[jj+1].lname) then
begin
ttemp:=ccard[jj];
ccard[jj]:=ccard[jj+1];
ccard[jj+1]:=ttemp;
end;
end;
end;
end;
procedure print (var ccard:arraytype;ii:integer);
begin
for ii:=1 to 5 do
begin
writeln(ii,'. ',ccard[ii].fname,' ',ccard[ii].mname,' ',ccard[ii].lname);
end;
writeln('Brian Abbott');
end;
begin
ask (card,i);
sort (card,temp);
print(card,i);
end.


By: VGR Date: 28/02/2003 02:20:00 English  Type : Answer
begin
ask (card,i);
sort (TEMP, CARD);
print(card,i);
end

read me !!! TEMP, CARD, not CARD, TEMP

Do register to be able to answer

EContact
browser fav
page generated in 255.224940 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page