fucntion construction
Author |
Message |
Sehroz
|
Posted: Thu Jan 10, 2008 5:14 pm Post subject: fucntion construction |
|
|
Hey i need some help constructing a function for a program im making. Basicaly this is what i have so face code wise.
type StudentMarks :
record
FirstName : array 1 .. 10 of string (20)
LastName : array 1 .. 10 of string (20)
PhoneNumber : array 1 .. 10 of string (12)
Marks : array 1 .. 10 of int
end record
procedure fillarray
var info: StudentMarks
for i:1 .. 10
var count : int :=0
count:=count+1
put "Enter first name",(i)
get info.FirstName(i)
put "Enter last name"," ", (i)
get info.LastName(i)
put "Enter phone number"," ", (i)
get info.PhoneNumber(i)
put "Enter marks "," ", (i)
get info.Marks(i)
end for
end fillarray
once the data has been inputed the program should call a highestMark which will search for the highest mark. Like starting from the second record compare the mark of that record to the current highest mark which is initally set to the first record. but if the mark of the second record is higher then first one then replace it. after the last record has been checked return the highestmark as the result and call a procedure to printArray
yea.. so if someone could help make a function highestMark it will be apreciated |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
cwlvc
|
Posted: Thu Jan 10, 2008 6:20 pm Post subject: Re: fucntion construction |
|
|
good luck
i really don't know these stuff
sorry |
|
|
|
|
![](images/spacer.gif) |
StealthArcher
![](http://compsci.ca/v3/uploads/user_avatars/18949255664b176c4f1481b.jpg)
|
Posted: Thu Jan 10, 2008 7:07 pm Post subject: Re: fucntion construction |
|
|
Turing: | record
FirstName : array 1 .. 10 of string (20)
LastName : array 1 .. 10 of string (20)
PhoneNumber : array 1 .. 10 of string (12)
Marks : array 1 .. 10 of int
end record
procedure fillarray
var info: StudentMarks
for i:1 .. 10
var count : int :=0
count:=count+1
put "Enter first name",(i)
get info.FirstName(i)
put "Enter last name"," ", (i)
get info.LastName(i)
put "Enter phone number"," ", (i)
get info.PhoneNumber(i)
put "Enter marks "," ", (i)
get info.Marks(i)
end for
end fillarray |
Code tags are wondrous inventions.
And sorting will help with this, look up some of the sorting tutorials |
|
|
|
|
![](images/spacer.gif) |
Zampano
![](http://compsci.ca/v3/uploads/user_avatars/123384421747e86c6cddac1.gif)
|
Posted: Thu Jan 10, 2008 7:44 pm Post subject: Re: fucntion construction |
|
|
Okay, you asked for help. Basically some of the buts of the function would be going through a for loop checking whether one value is greater than another. Basically, it should have a have a forloop which each time asks if info.Marks(c) is his higher than highest mark. If the if returns true, then highest mark must be given the value of the element of marks being compared to. After the for loop, put:
and it's done. That easy. Just wrap it in the function declaration and the rest is very basic sorting. If choosing the greatest value of several variables is a task with a solution that doesn't come obviously to you, one wonders what exactly you are doing learning records.
If it's the syntax that confuses you, look in Turing F10 for examples given their to help you learn.[/code] |
|
|
|
|
![](images/spacer.gif) |
|
|