Upload
irfanchandmian
View
567
Download
1
Embed Size (px)
Citation preview
Lab Manual
Fundamentals of AlgorithmsCS – 201
Instructor Ms. Saher Naqi
Submitted ByMr. Muhammad. Irfan Arshad
Roll Number: 1387BS – CS (3rd Semester)
College of Computer Sciences and Information StudiesGovernment College University, Faisalabad.
Page 1 of 8 cs-102
BS (cs) - Lab Manual Lab 1: Flowcharts
Problem’s Solution Via Flowchart
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. Draw a flow chart 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.
Loop 10 times
Loop 10 times
10/28/2010 7:47 PM BY M.IRFAN ARSHAD
START
Enter Roll # & Name
Add Ten Subject Marks Of Each Student
& loop 10 times
Calculate a Percentages Of Each Student Percentages =(Obtain
marks/Total marks)*100
Display a Percentages Along
With Roll# & Name
STOP
Enter a Subject Obtained Marks
Page 2 of 8 cs-102
BS (cs) - Lab Manual Lab 1: FlowchartsProblem Statement 2:
50 students of a class appear in the problem 1. Draw a flowchart for the algorithm to calculate and print the percentage marks obtained by each student along with his roll number.
Loop 50 times
Loop 50 times
10/28/2010 7:47 PM BY M.IRFAN ARSHAD
Enter a Roll#, Name &marks
Calculate a Percentages of Each StudentLoop 50 time
Display a Percentages Along
With Roll# & Name
STOP
START
Page 3 of 8 cs-102
BS (cs) - Lab Manual Lab 1: FlowchartsProblem Statement 3: Draw a flow 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.
Yes
10/28/2010 7:47 PM BY M.IRFAN ARSHAD
START
Enter a Name & age
Process on data
Display name &age
STOP
Ifage >20
Page 4 of 8 cs-102
BS (cs) - Lab Manual Lab 1: Flowcharts
Problem Statement 4:Draw a flowchart 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.
Youngest Oldest
10/28/2010 7:47 PM BY M.IRFAN ARSHAD
START
Enter a Name & age
Process on data& loop
Display Young name &age
STOP
Check which student is
young which is old
Process on data& loop
Display Young name &age
Page 5 of 8 cs-102
BS (cs) - Lab Manual Lab 1: Flowcharts
Problem Statement 5: A set of examination papers which have been graded with scores from 0 to 100 is to be searched to find how many of them are above 90. The total is to be printed.
Yes Loop
No
10/28/2010 7:47 PM BY M.IRFAN ARSHAD
Enter scores (0-100)
Add total marks
Display total marks
STOP
If scores
>90
START
Page 6 of 8 cs-102
BS (cs) - Lab Manual Lab 1: Flowcharts
Solution of Review Questions:What is a flowchart?
A flowchart is a type of diagram that represents an algorithm or process, showing the steps as boxes of various kinds, and their order by connecting these with arrows. This diagrammatic representation can give a step-by-step solution to a given problem. Data is represented in these boxes, and arrows connecting them represent flow / direction of flow of data. Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields.How does a flowchart help a programmer in program development?
The flowchart is a means of visually presenting the flow of data through an information processing systems, the operations performed within the system and the sequence in which they are performed. In this lesson, we shall concern ourselves with the program flowchart, which describes what operations (and in what sequence) are required to solve a given problem. The program flowchart can be likened to the blueprint of a building. As we know a designer draws a blueprint before starting construction on a building. Similarly, a programmer prefers to draw a flowchart prior to writing a computer program . Flow chart is pictorial representation of the flow of the program, algorithm is step by step procedure to solve a given problem.What are the characteristics necessary for a sequence of instructions to qualify as an algorithm?
Algorithms are essential to the way computers process information, because a computer program is essentially an algorithm that tells the computer what specific steps to perform (in what specific order) in order to carry out a specified task, such as calculating employees' paychecks or printing students' report cards. Thus, an algorithm can be considered to be any sequence of operations which can be performed by a Turing-complete system. Therefore, while designing an algorithm care should be taken to provide a proper termination for algorithm. Thus, every algorithm should have the following five characteristic features
1.Input 2.Output 3.Definiteness 4.Effectiveness 5.Termination
Therefore, an algorithm can be defined as a sequence of definite and effective instructions, which terminates with the production of correct output from the given input.
In other words, viewed little more formally, an algorithm is a step by step formalization of a mapping function to map input set onto an output set.
10/28/2010 7:47 PM BY M.IRFAN ARSHAD
Page 7 of 8 cs-102
BS (cs) - Lab Manual Lab 1: Flowcharts
Describe the function of the various flowcharting symbols?
Symbol Symbol Name(alias)
Symbol Description
Process Show a Process or action step. This is the most common symbol in both process flowcharts and business process maps.
Predefined Process(Subroutine)
A Predefined Process symbol is a marker for another process step or series of process flow steps that are formally defined elsewhere. This shape commonly depicts sub-processes (or subroutines in programming flowcharts). If the sub-process is considered "known" but not actually defined in a process procedure, work instruction, or some other process flowchart or documentation, then it is best not to use this symbol since it implies a formally defined process.
Flow Line (Arrow, Connector)
Flow line connectors show the direction that the process flows.
Decision Indicates a question or branch in the process flow. Typically, a Decision flowchart shape is used when there are 2 options (Yes/No, No/No-Go, etc.)
Connector (Inspection)
Flowchart: In flowcharts, this symbol is typically small and is used as a Connector to show a jump from one point in the process flow to another. Connectors are usually labeled with capital letters (A, B, AA) to show matching jump points. They are handy for avoiding flow lines that cross other shapes and flow lines. They are also handy for jumping to and from sub-processes defined in a separate area than the main flowchart.Process Mapping: In process maps, this symbol is full sized and shows an Inspection point in the process flow.
[Just to confuse things further, some people will use
10/28/2010 7:47 PM BY M.IRFAN ARSHAD
Page 8 of 8 cs-102
BS (cs) - Lab Manual Lab 1: Flowcharts
a circle to indicate an operation and a square to indicate an inspection. That's why it's important to include a symbol key in the flowchart.]
Data(I/O)
The Data flowchart shape indicates inputs to and outputs from a process. As such, the shape is more often referred to as an I/O shape than a Data shape.
What is a record?
In computer data processing, a record is a collection of data items arranged for processing by a program. Multiple records are contained in afield or data set. The organization of data in the record is usually prescribed by the programming language that defines the record's organization and/or by the application that processes it. Typically, records can be of fixed-length or be of variable length with the length information contained within the record.
10/28/2010 7:47 PM BY M.IRFAN ARSHAD