Help with Pascal

Status
Not open for further replies.

Slax

Seniorius Lurkius
7
Can someone help me with some coding? I am trying to process a data file. The data file is a text file containing some ssn's, gpa's, and some other fields. outout should look like this:

ssn lastname firstname mi sexcode major
string[9] string[12] string[10] char (male,female) string3


cit gpa totalhours qpoints
boolean real:3 real:1 real:1

At the bottom left of the page there is to be a total student count
and at the bottom right there is to be average gpa. the above 10 headers are suppose to be all the way across, i just ran out of room.There is also a record status field(char type) and the first thing the program should do is check to see if rec_stat = a, if not then read next record, but that field does not show up on the output. Any help with this would greatly be appreciated. I have already tried to write this program, but I get so many errors, please help!
 

Slax

Seniorius Lurkius
7
ok, I dont have my disk with my code, but I will post what I know from memory:

Program XYZ;
uses crt;

TYPE
begin
student_record : record
rec_stat : char;
ssn : string[9];
last_name: string[12];
first_name: string[10];
middle_i : char;
sex_code : (male,female);
major : string[3];
citizen : boolean;
gpa : real:3;
tothours : real:1;
qpoints : real:1;
sum : integer;
count : integer;
totstudents : integer;
gpaaverage : real:3;
end;

VAR
student_file : student_record;
student_file : file of student_record;

and that's my declaration section.
 

Slax

Seniorius Lurkius
7
Procedure startup;

assign(student_file,student.dat);
{$I-} reset(student_file); {$I+}
clrscr;
Student_file OK := (IOResult = 0);
write('ssn last_name first_name mi sex major cit gpa tothours gpa');
if student_file OK then begin
read (student_file, 'student.dat')
else
Writeln ('No file read');
halt;
end;

If rec_stat = 'a' then
read (student_file, 'student.dat')
else
end;

totstudents = 1
begin
while not eof(student_file)do begin
read (student_file, ssn,last_name,first_name,middle_i,sex_code,major,citizen,gpa,tothours,qpoints);
totstudents = totstudents + 1
end;

to be continued...
 

hanser

Ars Legatus Legionis
43,847
Subscriptor++
code:<HR>
Code:
{ I forget just about everything about Pascal, but I'll give this a whirl anyway }

assign(student_file,student.dat);
{$I-} reset(student_file); {$I+}
clrscr;			{ You have the appropriate includes included in your uses section, correct? I think you need crt to use clrscr}
Student_file OK := (IOResult = 0);
write('ssn last_name first_name mi sex major cit gpa tothours gpa');
if student_file OK then
	read (student_file, 'student.dat')
else
begin
	Writeln ('No file read');
	halt; 
end;

If rec_stat = 'a' then
	read (student_file, 'student.dat')
else
	end;

totstudents := 1;
begin			{ why is this here? }
	while not eof(student_file)do
	begin
		read (student_file, ssn,last_name,first_name,middle_i,sex_code,major,citizen,gpa,tothours,qpoints);
		totstudents := totstudents + 1;
	end;
end;			{ see above }

No idea if you're reading everything properly. It's been three years since I last looked at Pascal. Have your tried googling for online resources?
 

Slax

Seniorius Lurkius
7
that totstudents part is there to total the number of students. Basically, a counter. I included crt in the declaration section. I'm lost after this. i checked for errors, set end flag, and set up the counter, but I don't understand the process block. How do you actually make the data go into the correct fields? how do you right justify the input fields so that everything lines up? How do you set up the code to average all the gpa's? Did I define my variables correctly? I was hoping someone could guide me through the program to help me through the whole thing. I don't just want the answer, I want to understand the codes.Thanks for your help. :confused:
 
Status
Not open for further replies.