answersLogoWhite

0


Best Answer

Normally we would represent the days of the week using a low-level enumeration:

type

DayOfWeek (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday);

In other words, Sunday is represented by the integer 0, Monday by 1, Tuesday by 2, etc. This provides with a compact method of representing the high-level concept of a day of the week and the symbolic names are sufficiently abstract to make them easy to work with. However, it would be useful to convert these low-level symbolic constants to their higher-level equivalents (the actual strings, 'Sunday', 'Monday', 'Tuesday', etc) which can then be presented to the user. It would also be useful to be able to perform the reverse conversion, from high-level string to low-level enumeration. We achieve this with conversion functions implemented as lookup tables using case statements:

function ToDayOfWeekStr (Dow : DayOfWeek) : string;

begin

case Dow of

Sunday: ToDayOfWeekStr := 'Sunday';

Monday: ToDayOfWeekStr := 'Monday';

Tuesday: ToDayOfWeekStr := 'Tuesday';

Wednesday: ToDayOfWeekStr := 'Wednesday';

Thursday: ToDayOfWeekStr := 'Thursday';

Friday: ToDayOfWeekStr := 'Friday';

Saturday: ToDayOfWeekStr := 'Saturday';

end

end

function ToDayOfWeekEnum (Dow : string) : DayOfWeek;

begin

case Dow of

'Sunday': ToDayOfWeekEnum := Sunday;

'Monday': ToDayOfWeekEnum := Monday;

'Tuesday': ToDayOfWeekEnum := Tuesday;

'Wednesday': ToDayOfWeekEnum := Wednesday;

'Thursday': ToDayOfWeekEnum := Thursday;

'Friday': ToDayOfWeekEnum := Friday;

'Saturday': ToDayOfWeekEnum := Saturday;

else {handle input errors here};

end

end

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a pascal program using the case statement to display the days of the week?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a program using the gotoxy statement and print function to display letters of the alphabet on the computer screen?

There is no gotoxy statement in C.


What has the author Michael Yester written?

Michael Yester has written: 'Using Turbo Pascal 6' -- subject(s): Pascal (Computer program language), Turbo Pascal (Computer file)


What has the author Thomas M Boger written?

Thomas M. Boger has written: 'Programming fundamentals using Turbo Pascal' -- subject(s): Pascal (Computer program language), Turbo Pascal (Computer file)


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


What has the author Kenneth L Bowles written?

Kenneth L. Bowles has written: 'Problem solving using UCSD Pascal' -- subject(s): UCSD Pascal (Computer program language)


What has the author Arthur M Keller written?

Arthur M. Keller has written: 'A first course in computer programming using PASCAL' -- subject(s): Pascal (Computer program language)


Write a program By using if else statement to read a number and check whether it is positive or negative?

write a c++program by using if statement to read a number and check whether it is positive or negative


Write a program that accepts as inputs the edges of a graph and then draws the graph using a computer graphics display?

hey i m going to give a program that accepts edges a input and then it draws the graph using a computer graphics display...


What has the author Susan Finger written?

Susan Finger has written: 'Pascal Programming for Engineers Using VPS' 'Advanced applications for Introduction to Pascal with applications in science and engineering' -- subject(s): Data processing, Engineering, Pascal (Computer program language), Science


What has the author Guy J Hale written?

Guy J. Hale has written: 'Applied data structures using Pascal' -- subject(s): Data structures (Computer science), Pascal (Computer program language)


Write a program in java to display a string message using Servlets?

i dont no string for servlate