concept project pascal part 1
concept project pascal part 1
Table of Contents
1. Introduction
2. Part 1: Procedural Programming (Pascal)
o Pascal Grammar vs. C Grammar
o General Program Skeleton in Pascal
o Control Statements in Pascal
o Example Programs with Explanations and Outputs
3. Part 2: Functional Programming (Scheme)
o Conversion of Pascal Programs to Scheme
o Explanation of Outputs
4. Part 3: Logic Programming (Prolog)
o Conversion of Pascal Programs to Prolog
o Explanation of Outputs
5. Comparisons and Conclusions
6. References
Introduction
Programming languages fall into different paradigms, each designed to solve problems in
unique ways. This report examines three different paradigms: procedural (Pascal),
functional (Scheme), and logic programming (Prolog). Through a series of programs, we
compare their syntax, structure, and efficiency.
Pascal and C have different grammar structures. Pascal is strongly typed and more
structured, while C allows more flexibility and direct memory manipulation. The main
differences include:
Control statements in Pascal are used to control the flow of execution within a program.
The main types include:
if x > 0 then
writeln('Positive')
else
writeln('Negative');
for i := 1 to 10 do
writeln(i);
while x < 10 do
begin
writeln(x);
x := x + 1;
end;
repeat...until: Similar to while, but ensures the loop runs at least once.
repeat
writeln(x);
x := x + 1;
until x > 10;
program PerimeterSquare;
var
side, perimeter: integer;
begin
write('Enter the side length of the square: ');
readln(side);
perimeter := 4 * side;
writeln('The perimeter of the square is: ', perimeter);
end.
program EvenOrOdd;
var
num: integer;
begin
write('Enter a number: ');
readln(num);
if num mod 2 = 0 then
writeln('The number is even.')
else
writeln('The number is odd.');
end.
program CoffeeOrTea;
var
choice: char;
begin
writeln('Do you want Coffee or Tea? (c/t)');
readln(choice);
case choice of
'c', 'C': writeln('Here is your Coffee!');
't', 'T': writeln('Here is your Tea!');
else
writeln('Invalid choice!');
end;
end.