0% found this document useful (0 votes)
2 views

PASCAL PROGRAMMING ASSIGNMENT 2

The document is an assignment for a computer programming module at Midlands State University, focusing on Pascal programming. It includes explanations of programming concepts such as write/writeln, read/readln, procedures, functions, variables, data types, and arithmetic operations like DIV and MOD. Additionally, it provides example programs for currency conversion and finding the largest and smallest numbers among user inputs.

Uploaded by

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

PASCAL PROGRAMMING ASSIGNMENT 2

The document is an assignment for a computer programming module at Midlands State University, focusing on Pascal programming. It includes explanations of programming concepts such as write/writeln, read/readln, procedures, functions, variables, data types, and arithmetic operations like DIV and MOD. Additionally, it provides example programs for currency conversion and finding the largest and smallest numbers among user inputs.

Uploaded by

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

MIDLANDS STATE UNIVERSITY

DEPARTMENT OF EDUCATIONAL FOUNDATIONS, MANAGEMENT


AND CURRICULLUM STUDIES

PART A: STUDENT AND ASSIGNMENT DETAILS

STUDENT NAME: LILIAN NYONI REG NUMBER: R1913823E

PROGRAMME: BED PRIMARY LEVEL: 1.2


MODULE TITLE & CODE - COMPUTER PROGRAMMING BPC 102
ASSIGNMENT NUMBER: 2
LECTURER: MRS S. MOYO
QUESTION: PASCAL PROGRAMMING
PART B: MARKER’S COMMENTS

…...
………………………………………..............................................................................................................
...................................................................................................................................................................

MARKER’S NAME: …………...………………....………. SIGNATURE: ……………………….

DATE: ……………………………………............................ MARK: ................


QUESTION 1

a) Write and writeln both print text on the screen. The difference is that write just prints
while writeln prints and then shifts the cursor to the first place of the next row on the
screen. For example write(‘Good morning’); writeln(‘Good morning’); After
displaying the text Good morning in writeln instruction the cursor will move to the next
row but in the write instruction it will not.
b) Read and readln- the user gets information from the keyboard. Both instructions can read
values and characters from the keyboard and directly store them into specified variables.
For example :
Program Example;
var num1, num2: integer;
begin
writeln(‘Please enter two numbers separated by a space’);
read(num1);
read(num2);
writeln(‘num1=’,num1,’num2=’, num2);
end.

When run the program will display the message Please enter two numbers separated by a
space. The user is expected to type two numbers eg 100 50 After which the program
shows num1=100 num2=50 if we replace the read instruction with the readln instruction
the program will assign 100 to num1 then discard the rest of the text that was typed and
then wait for more input to assign num2.

c) Procedure and function can be viewed as small programs, they have a set of parameters,
values or variables. A procedure is a set of instructions which takes input and performs a
certain task, it does not return a value. Function on the other hand is a set of instructions
which takes some input and performs certain tasks and it returns a value meaning it
calculates an answer which is made available. Therefore a procedure just executes
commands while function returns a value.
d) Variable and data type – variables are containers that hold value, they can also be viewed
as locations where data is stored during programming. Variables are declared before the
keyword ‘begin’ just after the program head. When variables are declared the name of
the variable is stated. Eg Program Example;
Var num 1, num 2: integer;
Begin

Data types on the other hand are digital variables that are manipulated by the
programmer. They are used together with the variables when they are declared. A
variable cannot be declared without a data type. Data types can be categorized as scalar,
pointer and structured data types.

e) DIV and MOD- div is division in which the fractional part is discarded. For example a
div b returns the integer part of the result after dividing two integers. 19 div 5 will return
a result of 3, the remainder is discarded. Mod stands for modulus and returns the
remainder when one integer is divided by another. For example 19 mod 5 will return a
value of 4.

QUESTION 2

a) Program Convert(input,output);
uses crt;
var a, b, ZWL, US$, rate:real;
begin
clrscr;
writeln(‘Please enter amount to be converted in ZWL’);
readln(amount in ZWL);
writeln(‘Please enter amount in US$’);
readln(US$);
writeln(‘Please enter today’s rate’);
readln(today’s rate);
end;
procedure calculate_currency;
begin
currency:= ZWL/today’s rate;
end;
Procedure display _answer;
begin
writeln(‘ The converted currency is’,a ZWL is equivalent to bUS$’);
readln
end.
b) Program largesmall(input,output);
uses crt;
var a, b, c, d, e, largest, smallest: integer;
begin
clrscr;
writeln(‘Enter first number’);
readln(a);
writeln(‘Enter second number’);
readln(b);
writeln(‘Enter third number’);
readln( c);
writeln(‘Enter fourth number’);
readln(d);
writeln(‘Enter fifth number’);
readln(e);
large:=a;
If b>large then begin
large:=b;
end;
If c>large then begin
large:=c;
end;
If d>large then begin
large:=d;
end;
If e>large then begin
large:=e;
end;
writeln(‘ the largest is large’);
readln;
end;
small:=a;
If b<small then begin
small:=b;
end;
If c<small then begin
small:=c;
end;
If d<small then begin
small:=d;
end;
If e<small then begin
small:=e;
end;
writeln(‘ the smallest is small’);
readln
end.

You might also like