Download presentation
Presentation is loading. Please wait.
Published byScot Ellis Modified over 6 years ago
1
The CONST definition CONST Pi = 3.14159, City = ‘New York’;
Constant identifiers are used when you do not want the value of an identifier to change why not just put the value in the program? Note: The compiler automatically defines the type to the constant identifier by looking at the value assigned to it.
2
Reserved words Certain words have special meaning to the compiler. Therefore these words cannot be used as constant or variable identifiers. We have seen some examples: DIV, MOD VAR, CONST PROGRAM, BEGIN, END
3
String Variables Note: This is not part of the Pascal standard. It was added to Turbo Pascal (and some other Pascal compilers) To declare a string variable we could write: VAR Country: string[13]; To assign a value to a string variable we could write: Country := ‘United States’;
4
More about integers What if you need an integer larger than 32767?
Using integer type would be incorrect another type called LongInt is used > other integer types are: byte (0->255) shortint (-128->127) word (0->65535)
5
More about reals Reals also have other types
real 6 bytes 11 to 12 digits single 4 bytes 7 to 8 digits double 8 bytes 15 to 16 digits extended 10 bytes 19 to 20 digits
6
Chapter 3 topics write / writeln readln VAR declaration
CONST definition assignment statement (including arithmetic)
7
Homework #3 Problem #1 Write a program that asks the user for his or her age and place of birth. Then write both pieces of information back to the screen in a single WriteLn statement (using a CONST string). Hint: What kind of data type would you want to use for someone's age? What kind of data type would you want to use for a geographic location?
8
Homework # 3 (con’t) Problem #2
Problem #14 on Page 99 of your text: Write a program to calculate the product of any five real numbers read. What difficulty would the program encounter if it calculated the product of five integers?
9
Instructions for handing in homework
Mail to grader at: each program should be included as an attachment The answer to #14, part 2 should be contained in the message body.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.