[go: up one dir, main page]

0% found this document useful (0 votes)
1 views4 pages

concept project pascal part 1

This project report explores three programming paradigms: procedural (Pascal), functional (Scheme), and logic programming (Prolog), comparing their syntax, structure, and efficiency. It includes detailed sections on Pascal programming, including grammar differences with C, control statements, and example programs. The report also discusses converting Pascal programs to Scheme and Prolog, culminating in comparisons and conclusions about the paradigms.

Uploaded by

naif alhrbi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views4 pages

concept project pascal part 1

This project report explores three programming paradigms: procedural (Pascal), functional (Scheme), and logic programming (Prolog), comparing their syntax, structure, and efficiency. It includes detailed sections on Pascal programming, including grammar differences with C, control statements, and example programs. The report also discusses converting Pascal programs to Scheme and Prolog, culminating in comparisons and conclusions about the paradigms.

Uploaded by

naif alhrbi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Project Report: Concepts of Programming Languages (CS213)

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.

Part 1: Procedural Programming (Pascal)


Pascal Grammar vs. C Grammar

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:

 Variable Declaration: Pascal requires explicit declaration (var x: integer;),


whereas C combines declaration and initialization (int x;).
 Control Structures: Pascal uses begin...end;, while C uses {}.
 Functions: Pascal functions must be declared before use.

General Program Skeleton in Pascal


program Example;
begin
writeln('Hello, Pascal!');
end.

Control Statements in Pascal

Control statements in Pascal are used to control the flow of execution within a program.
The main types include:

 if...then...else: Used for decision-making.

if x > 0 then
writeln('Positive')
else
writeln('Negative');

 for...do: Used for loops with a known number of iterations.

for i := 1 to 10 do
writeln(i);

 while...do: Used when the number of iterations is not known in advance.

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;

 case...of: Used as an alternative to multiple if statements.


 case choice of
 1: writeln('Option 1');
 2: writeln('Option 2');
 else
 writeln('Invalid choice');
end;

Example Programs in Pascal

1. Calculate the Perimeter of a Square

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.

‘’’’’’’’’’’ the outpot is :

2. Check if a Number is Even or Odd

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.

‘’’’’’’’’’’ the outpot is :

3. Choose Coffee or Tea

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.

‘’’’’’’’’’’ the outpot is :

You might also like