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

Fundamentals of Algorithms CS - 201: Lab Manual 2

The document is a lab manual that provides examples of pseudocode solutions to various problems. It contains 5 problem statements with the pseudocode algorithms to solve each problem. The problems include calculating student exam percentages, calculating percentages for multiple students, identifying students over age 20, finding the oldest and youngest student, and reading the first 20 records of a data set. It also contains review questions that define pseudocode, compare it to flowcharts, and list advantages and disadvantages.

Uploaded by

irfan_chand_mian
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views

Fundamentals of Algorithms CS - 201: Lab Manual 2

The document is a lab manual that provides examples of pseudocode solutions to various problems. It contains 5 problem statements with the pseudocode algorithms to solve each problem. The problems include calculating student exam percentages, calculating percentages for multiple students, identifying students over age 20, finding the oldest and youngest student, and reading the first 20 records of a data set. It also contains review questions that define pseudocode, compare it to flowcharts, and list advantages and disadvantages.

Uploaded by

irfan_chand_mian
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Lab Manual 2

Fundamentals of Algorithms
CS – 201

Instructor
Ms. Saher Naqi

Topic: Pseudo code

Submitted By
Mr. Muhammad. Irfan Arshad
Roll Number: 1387
BS – CS (3rd Semester)

College of Computer Sciences and Information Studies


Government College University, Faisalabad.
Page 2 of 8 cs-102

BS (cs) - Lab Manual Lab 1:


pseudocode

Problem’s Solution via pseudo code


Problem Statement 1:
A student appears in an examination that consists of total
10 subjects, each subject having maximum marks of 100. The roll number of the
student, his name, and the marks obtained by him in various subjects is supplied as
input data. Such a collection of related data items that is treated as a unit is known
as a record. Write a pseudocode for the algorithm to calculate the percentage marks
obtained by the student in this examination and then to print it along with his roll
number and name.

ALGORITHM 1 Calculate percentage marks of student

Procedure: student_record (name: char, roll#: integer marks: float)


{The marks of student in diff subjects are (m1, m2… m10), respectively}

length 10
total 0
for i 1 to length
do
total total + marks[i]
► end for loop
percentage (total/100) x 100

{The Percentage of student in 10 subjects along with his roll# & name}

12/8/2021 BY M.IRFAN ARSHAD


Page 3 of 8 cs-102

BS (cs) - Lab Manual Lab 1:


pseudocode

Problem Statement 2:
50 students of a class appear in the problem 1. Write a
pseudocode for the algorithm to calculate and print the percentage marks obtained
by each student along with his roll number.

ALGORITHM 2 Calculate percentage of students mark

Procedure: student_record (name: char, roll#: integer marks: float)


{The name, (n1, n2…n50), roll# (r1, r2….r50) & marks (m1, m2… m50) of diff students respectively}

length 50
total 0
for i 1 to length
do
percentage[i] (marks[i]/total marks) x 100
► end for loop

{Name, Roll# & Percentage of 50 students along with his roll# & name}

12/8/2021 BY M.IRFAN ARSHAD


Page 4 of 8 cs-102

BS (cs) - Lab Manual Lab 1:


pseudocode

Problem Statement 3:
Write a pseudocode chart of the logical steps needed to
produce a printed listing of all students over the age of 20 in a class. The input
records contain the name and age of the students. Assume an initial value of 99 for
the age field.

ALGORITHM 3 Age of student

Procedure: age (name: char, age: integer)


{The name & age of student are (a1, a2, a3....an), respectively}

age 99
for i 1 to length
do
if (age>20)
then
{The name & age of student}
► end if
► end for loop

12/8/2021 BY M.IRFAN ARSHAD


Page 5 of 8 cs-102

BS (cs) - Lab Manual Lab 1:


pseudocode

Problem Statement 4:
Write a pseudocode of the logical steps needed to print the name and age of
the oldest and the youngest student in a class. The input records contain the
name and age of the students. Assume a sentinel value of 99 for the age field
of the trailer record.

ALGORITHM 4 Age of youngest & oldest student

Procedure: Student_age( name: char, age: integer)


{The name & age of student are (a1, a2, a3....an), respectively}

while (age! =99)


do
if (age>=18 && age<=25)
then
{name & age of youngest student}
► end if
if(age>=26)
then
{name & age of oldest student}
► end if
► end while loop

12/8/2021 BY M.IRFAN ARSHAD


Page 6 of 8 cs-102

BS (cs) - Lab Manual Lab 1:


pseudocode

Problem Statement 5:
The first 20 records in a data set are to be read and
printed. Write a pseudocode for the algorithm to do this job. Make sure that the
processing stops after the twentieth record.

ALGORITHM 5 records of data (array, length)


Set count1 to one
Set length to twenty
While count1 is less then equal to length
Prompt the user to enter the record
Input the record
Add one to the count1
► end while loop
Set count2 to one
While count2 is less then equal to length
Print the record of data set
► end while loop

12/8/2021 BY M.IRFAN ARSHAD


Page 7 of 8 cs-102

BS (cs) - Lab Manual Lab 1:


pseudocode

Solution of Review Questions:


1. What is a pseudocode?
Pseudocode is a compact and informal high-level description of a computer
programming algorithm that uses the structural conventions of aprogramming language,
but is intended for human reading rather than machine reading. Pseudocode typically
omits details that are not essential for human understanding of the algorithm, such
as variable declarations, system-specific code and subroutines

2. What is the difference between flowchart and pseudocode?

A flowchart is a symbolic Pseudocode (derived from pseudo and


representation of code, using box shapes code) is a compact and informal high-
and arrows. Flowcharts can be thought of level description of a computer
as a graphical form of pseudocode. programming algorithm that uses the
The layout of flowcharts for a program structural conventions of programming
provides a graphical structure that allows languages, but omits detailed
programmers to follow the logical subroutines, variable declarations or
structure of the code. The graphical nature language-specific syntax.
of the flowchart provides another way to The layout of pseudocode follows more
look at the sequence of the program, closely the structure for the code of the
which can be especially beneficial for program. Pseudocode uses words as
nonprogramming members of the team opposed to a pictorial representation to
who need to understand how the code will illustrate the logic of the algorithm.
work. Pseudocode provides a beneficial bridge
Flowcharts are especially beneficial for to the project code because it closely
smaller concepts and problems, while follows the logic that the code will.
pseudocode is more efficient for larger Pseudocode also helps programmers
programming problems. Flowcharts share ideas without spending too much
provide an easy method of time creating code, and it provides a
communication about the logic and offer a structure that is not dependent on any one
good starting point for the project because programming language.
they are easier to create than pseudocode The structure of pseudocode uses a
in the beginning stages. linear text-based structure to organize the
The structure of flowcharts uses symbols logic of the programming problem. It
and shapes to create a diagram of only the does not need so much detail as to
essential parts of the algorithm or include variables and function names but
problem. While it is sometime not enough should include enough detail so that code
to begin coding from, especially for larger can be created to follow the same logic. 
systems, it can provide a broad idea of
how the system will function.

12/8/2021 BY M.IRFAN ARSHAD


Page 8 of 8 cs-102

BS (cs) - Lab Manual Lab 1:


pseudocode
3. List out advantages and disadvantages of pseudocode.

Pseudocode Advantages 

1. Can be done easily on a word processor


2. Easily modified
3. Implements structured concepts well

Pseudocode Disadvantages 

1. It's not visual


2. There is no accepted standard, so it varies widely from company to company

12/8/2021 BY M.IRFAN ARSHAD

You might also like