Lab 1 - Algorithms Pseudo code and Flowcharts v PDF

Title Lab 1 - Algorithms Pseudo code and Flowcharts v
Author Ramish Saeed
Course Fundamentals of Programming
Institution National University of Sciences and Technology
Pages 7
File Size 370 KB
File Type PDF
Total Downloads 40
Total Views 133

Summary

Download Lab 1 - Algorithms Pseudo code and Flowcharts v PDF


Description

Department of Software Engineering

CS-114: Fundamentals of Programming Class: BESE-11B

Lab 01: Algorithms, Pseudo code, and Flowcharts CLO: Define basic algorithms for identifying and solving real-world problems

Date: October 20, 2020 Time: 14:00-16:50 Instructor: Dr. Hashir Kiani Lab Engineer: Ms. Sara Mehmood

Lab 01: Algorithms, Pseudo code, and Flowcharts Introduction This lab will introduce you to the concepts of algorithms, pseudo code, and flowcharts.

Objectives The purpose of this lab is to enable students to understand the basics of problem solving in programmatic context. Students will be representing solutions to different problems as flowcharts and pseudo code.

Tools/Software Requirement Microsoft Word

Description What is an Algorithm? An algorithm is procedure consisting of a finite set of instructions that provides a solution to a problem. In other word, an algorithm is a step-by-step procedure to solve a given problem. Algorithms can be translated into many programming languages. There are two main methods of representing algorithms. 1. Pseudo code 2. Flowchart

What is a Pseudocode? Pseudocode is a tool that can be used to write a preliminary plan for the development of a computer program. It is a generic way of describing an algorithm without the use of any specific programming language syntax. In fact, it serves as an English like way to state an algorithm.

Example: Write a pseudo code for converting temperature entered by the user in centigrade to Fahrenheit. Solution: BEGIN DISPLAY “Enter Centigrade: " INPUT centigrade_value CALCULATE Fahrenheit = (1.8 * centigrade_value) + 32 DISPLAY Fahrenheit END

What is a Flowchart? A flowchart provides a detailed picture of the algorithm using special symbols to represent various program statements. A flowchart will usually be drawn from top to bottom showing the exact order of the steps. Arrows are used to depict the “flow” of a program.

Figure 1: Representing a Flowchart

Basic Flowchart Symbols There are different types of symbols representing different operations in this flowchart:

Rounded rectangles It represents the terminals of a program (e.g. Start, End) Parallelograms It represents the Input and out operation. (e.g. Display a Message, Read Hours) A rectangle It represents process e.g. A mathematical calculation. A diamond It represents decision making process e.g. A condition is analyzed, where answer is usually either True or False.

Flow Lines Arrow shows the direction of flow of instructions. Connectors They are used to join one part of the flowchart with another part of the flowchart. Flow Chart Guidelines: 1. Think of a logical plan to solve a problem 2. Identify the tasks in chronological order 3. Organize them by type and corresponding shape 4. Draw your chart 5. Flowchart can have only one start and one stop symbol 6. Try to keep it neat i.e. Arrows should not cross each other 7. Confirm your flowchart

Example: Draw a flowchart for calculating average of two numbers. Solution:

Example: Flowchart for going to the market to purchase a pen. Solution:

The connectors connecting two parts of the same flowchart are referenced using a number (number 1 in the circle in this case).

Lab Tasks: Write pseudo codes and draw flowcharts for the following problems: 1. Retrieve three numbers from the user. Determine the largest of these three numbers and display that value to the user with an appropriate message. For simplification assume that the numbers entered by the user are not the same. To confirm your solution trace through your flowchart and pseudocode with the following test values to check their accuracy:   

7, 5, 6 5, 6, 7 6, 7, 5

2. Obtain from the user an hourly pay rate and the number of hours worked for the current week. Calculate and output their weekly pay according to the following criteria: a. Regular pay is the pay up to 40 hours. No overtime is paid! b. Overtime pay is pay for the hours over 40. Overtime is paid at a rate of 1.5 times the hourly pay rate. c. Gross pay is the sum of the regular pay and the overtime pay. To confirm your solution trace through your flowchart and pseudocode with the following test values to check their accuracy:  

hourly pay rate = 20, number of hours worked = 52 hourly pay rate = 35, number of hours worked = 22

3. Obtain 5 exam scores from the user and determine whether the scores are passing (a score of 60 or above) score or failing score. Your solution should count the number of passing and failing scores. Additionally, you will be calculating the average of the scores. Display average of the scores, the number of failing scores, and the number of passing scores. To confirm your solution trace through your flowchart and pseudocode with the following test score values to check their accuracy: 

75, 89, 32, 55, 12

Bonus Lab Tasks (Ungraded):

Write pseudo codes and draw flowcharts for the following problems: 1. Retrieve a number from the user. Calculate its factorial and display it to the user. 2. Retrieve a number from the user. Generate and display the multiplication table for the given number Hint: You must use the concept of repetition to run the same step multiple times based on some condition...


Similar Free PDFs