CMP 131 Introduction to Computer Programming. Violetta CavalliSforza Week 5, Lecture 1 (Monday). THIS WEEK. Homework #2: Turn in the nonprogramming part today (in class or by email after class).
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Have names associated with them. They are defined (constants) or declared (variables) in the program declaration section.
Appear directly as values of constants or in program without being defined or declared.
3 div 15 = 0 3 div 15 = 0
15 div 3 = 5 15 div 3 = 5
16 div 3 = 5 16 div 3 = 5
17 div 3 = 5 17 div 3 = 5
18 div 3 = 6 18 div 3 = 6
3 mod 5 = 3 5 mod 3 = 2 5 mod 3 = 2
4 mod 5 = 4 5 mod 4 = 1 5 mod 4 = 1
5 mod 5 = 0 15 mod 5 = 0 15 mod 5 = 0
6 mod 5 = 1 15 mod 6 = 3 15 mod 6 = 3
7 mod 5 = 2 15 mod 7 = 1 15 mod 7 = 1
8 mod 5 = 3 15 mod 8 = 7 15 mod 0 = ??
PROGRAM intdiv;
VAR a, b: integer;
BEGIN
REPEAT
write('Input a and b: '); readln(a,b);
IF b <> 0 THEN
writeln('DIV = ', a DIV b, ' MOD = ', a MOD b);
writeln;
UNTIL b = 0;
END.
PROGRAM CharComp;
VAR firstchar, secondchar: char;
BEGIN
write('Enter a character, without quotes > ');
readln(firstchar);
write('Enter another character, without quotes > ');
readln(secondchar);
IF firstchar = secondchar
THEN writeln(firstchar,' is equal to ', secondchar)
ELSE
IF firstchar < secondchar
THEN writeln(firstchar,' is less than ', secondchar)
ELSE writeln(firstchar,' is greater than ', secondchar);
readln;
END.
PROGRAM CharOrd;
VAR ch: char;
BEGIN
write('Enter a character, without quotes > ');
readln(ch);
writeln('The successor of ',ch,' is ',succ(ch));
writeln('The predecessor of ',ch,' is ',pred(ch));
readln;
END.
PROGRAM BoolOrd;
BEGIN
writeln('The successor of ',false,' is ',succ(false));
writeln('The predecessor of ',false,' is ',pred(false));
writeln('The successor of ',true,' is ',succ(true));
writeln('The predecessor of ',true,' is ',pred(true));
readln;
END.
PROGRAM CharOrd;
VAR ch: char;
BEGIN
write('Enter a character, without quotes > ');
readln(ch);
writeln('The successor of ',ch,' is ',succ(ch));
writeln('The predecessor of ',ch,' is ',pred(ch));
readln;
END.
/
*
*
+

Rules for Expression EvaluationX * Y * Z + A / B  C * D ==>
((((X * Y) * Z) + (A / B))  (C * D))
X * Y * Z + A / B  C * D
22 div 7 7 div 22 22 mod 7 7 mod 22
const PI = 3.14159;
MaxI = 1000;
var X, Y : Real;
A, B, I : Integer;
. . .
I := A mod B; I := A mod Y;
X := A / B; I := A / B; X := A / Y;
I := B div 0; I := A mod 0; X := PI div Y;
X := A mod (A / B);
I := (MaxI  990) div A;
I := A mod (MaxI  990);
SEE TURBO PASCAL COMPILATION ERRORS
CONST PI = 3.14159;
MaxI = 1000;
VAR X, Y : Real;
A, B, I : Integer;
BEGIN
I := A mod B;
{ I := A mod Y; }
X := A / B;
{ I := A / B; }
X := A / Y;
{ I := B div 0; }
I := A mod 0;
{ X := PI div Y; }
{ X := A mod (A / B); }
I := (MaxI  990) div A;
I := A mod (MaxI  990);
END.
X := Y + Z + 2.0;
Sum := Sum + Item;
NewX :=  X;
SqYards := MetersToYards * SqMeters;
Ch := 5; { Ch is of char type }
Ch := Name; { Name is of string type }
Name := True; { True is a Boolean literal }
BoolVar := ‘False’; {‘ False’ is a string literal }