Solved Need help using Records in Pascal (Delphi 200

November 18, 2011 at 13:47:40
Specs: Windows 7, 2.2GHz / 3GB
I need help using records and enumerated data types such as ordinal and symbolic in pascal.
the question is... declare the type TDay and the array hoursworked from the previous page. using these write a program to collect the hours worked by an employee in a week and the hourly pay rate. the program should calc and display the total hours worked and the gross pay for the week.
This is what i have so far :

Tday = (Sun, Mon, Tue, Wed, Thu, Fri, Sat);

var hoursworked : array [Mon..Fri] of integer ;
day : Tday ;

procedure userin ;
var payrate, pay : real ;

payrate := 5.50 ;

for Day := Mon to Sun do

readln (Hoursworked[day]);

case Day of
Mon..Fri : Pay := hoursworked[day] * Payrate;
Sat : Pay := hoursworked[day] * Payrate * 1.5 ;
Sun : Pay := hoursworked[day] * payrate * 2 ;

end; // end of procedure


This is basically what was on the previous page into code format, i am extremely unsure of where to go from here? can someone please help?? Thanks in advance and much appreciation.

See More: Need help using Records in Pascal (Delphi 200

Report •

November 18, 2011 at 14:58:06
Maybe tomorrow you 'll get a tip.

Report •

November 19, 2011 at 09:59:38
✔ Best Answer
Here your assignment, perfectly working under Windows XP SP3.
I hope you spend the time you saved getting the homework done to understand the code.


type Tday= (Mon, Tue, Wed, Thu, Fri, Sat, Sun);

  day: Tday;
  hoursworked: array [Mon..Sun] of integer;
  tothours: integer;
  grosspay: real;

const dayofweek: array [Mon..Sun] of string[3]=
  ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun');

procedure UserIn; {Accept and Validate Input Data}
WriteLn ('Enter the hours worked on');
tothours:= 0;
for day:= Mon to Sun do begin
    Write ('  ', dayofweek[day], ': '); ReadLn (hoursworked[day]);
    if (hoursworked[day] < 0) or (hoursworked[day] > 24) then
      WriteLn ('    Invalid Value! Please reenter...')
  until (hoursworked[day] >= 0) and (hoursworked[day] <= 24);
  tothours:= tothours + hoursworked[day]
end; {End Of Procedure UserIn}

procedure ComPay; {Compute Gross Pay}
const payrate: real= 5.50;
grosspay:= 0;
for day:= Mon to Sun do
  case day of
    Mon..Fri: grosspay:= grosspay + hoursworked[day] * payrate;
    Sat: grosspay:= grosspay + hoursworked[day] * payrate * 1.50;
    Sun: grosspay:= grosspay + hoursworked[day] * payrate * 2.00
end; {End Of Procedure ComPay}

  WriteLn ('Total Hours Worked:', tothours:4, ' - Gross Pay:', grosspay:8:2);


Report •

November 19, 2011 at 14:29:10
thanks very much really helped me as i honestly hit the wall.. much appreciated and thanks for teaching me how to use the "const" variable control as i have never used it before.. once again thanks :D

Report •

Related Solutions

November 20, 2011 at 05:49:52
Thanks...with what you said i was able to proceed with the chapter i was then able to write:

program Letters;


SysUtils, Strutils;


TLetters = 'a' .. 'z' ;

Letter : TLetters;
LetterFrequency : array [1..26] of integer;
sentence, LSentence : string ;

procedure userin;
var move: string;
count,count2,same, Slength, add : integer;
writeln ('Type in a sentence');
readln (sentence);
Lsentence := lowercase (sentence); //lower case of input
SLength := Length (sentence); //length of string

for count := 1 to Slength do begin // overall
move := sentence ;
move := Midstr (move,count, 1);

for count2 := 1 to 26 do begin // letter check
case count2 of
1 : Letter := 'a';
2 : Letter := 'b';
3 : Letter := 'c';
4 : Letter := 'd';
5 : Letter := 'e';
6 : Letter := 'f';
7 : Letter := 'g';
8 : Letter := 'h';
9 : Letter := 'i';
10 : Letter := 'j';
11 : Letter := 'k';
12 : Letter := 'l';
13 : Letter := 'm';
14 : Letter := 'n';
15 : Letter := 'o';
16 : Letter := 'p';
17 : Letter := 'q';
18 : Letter := 'r';
19 : Letter := 's';
20 : Letter := 't';
21 : Letter := 'u';
22 : Letter := 'v';
23 : Letter := 'w';
24 : Letter := 'x';
25 : Letter := 'y';
26 : Letter := 'z';

if move = Letter
then begin
if same <> count2 then add := 0 ;
add := add + 1 ;
LetterFrequency[count2] := add ;
same := count2
end; //of the submission loop
end; // of letter check loop
end; // of overall loop

end; //*********of procedure***********

procedure display ;
var count : integer;
writeln ('The number of occurences of the letters are');
for count := 1 to 26 do begin
if letterfrequency[count] <> 0 then
writeln (LetterFrequency[count]);
end; // of loop
end; // of procedure

// main program begin ********************




//*********************Try it******************************

although i wasnt sure how i could of avoided the case statement i couldnt think of a way around it..

Report •

November 20, 2011 at 07:23:14
About the code you posted above, yes, there are better and more cool ways to compute characters' occurencies inside a string. Your code is far away to be nice and readable, but almost it works and that is the most important thing (excluding other points of view sometime very important too as efficency and module size).

Rarely there is one way to write a (working) program, but there is just one to get the optimized version. To avoid the cumbersome case ... of requires to deeply restructure the code. Be aware Pascal is not an absolute standard, so e.g. I don't have on my compiler the Midstr function as I run Turbo Pascal 7 for DOS, a legacy Borland version ancestor of Delphi (that I can't manage),

By the way, just curious, why are you interested to a today almost dead language? Where are you posting from?

Report •

November 20, 2011 at 07:49:59
since i copied and pasted the code the indents where lost immediately..i would never even consider writing code without indents..i study Computing at college and it is required by the board that i use this language...pascal is the only language i know at the moment and i understand that it is used to introduce aspects of programming to a beginner.
..i made some minor changes to the code to do with the display (displays the letter and the frequencies of that letter next to it).

No problem i just wanted you to see what i was then able to do. i post from the UK
may I ask what about you?

Report •

November 20, 2011 at 08:35:18
I live in Milan, Italy, now a retired manager after 35 years in the IT industry mainly spent when mainframes ruled the world and personal computers, servers and Microsoft were at their dawn. I hold a doctorate degree in electrical engineering so while in charge of budgets and planning I always loved (and love) systems and programming.

While Pascal is now displaced by C/C++ and tools more suited to Internet and database applications, it is still an elegant way to introduce the fundamental principles of programming as structured code and object oriented technology (via Turbo Vision then Delphi). It is not a waste of time to learn about Pascal since it actually translates the math rules of programming into the real world. Theory is the difference between a geek and a college student.

Let me end giving a tip: to retain indentation, posting on this forum, paste your code, format and then prefix and postfix typing [pre] ...your code...[/pre] (where [ actually must be < and ] >). So the result will be a fancy readable code.

Report •

Ask Question