Algorithims Labmanual 2 Solve

Embed Size (px)

Citation preview

  • 8/7/2019 Algorithims Labmanual 2 Solve

    1/8

    Lab Manual

    Fundamentals of Algorithms

    CS 201

    Instructor

    Ms. Saher Naqi

    Submitted By

    Mr. Muhammad. Irfan Arshad

    Roll Number: 1387

    BS CS (3rd Semester)

    College of Computer Sciences and Information StudiesGovernment College University, Faisalabad.

  • 8/7/2019 Algorithims Labmanual 2 Solve

    2/8

    Page 1 of 8 cs-102

    BS (cs) - Lab Manual Lab 1: Flowcharts

    10/28/2010 7:47 PM BY M.IRFAN ARSHAD

    Problems Solution via pseudo codeProblem 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 thestudent, 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.

    ALGORITHM 1 student_marks (Array, length)Input: Enter a (name, roll#, marks{m1,m2,m10})Output: Display a percentage along with his roll# & name

    total 0for i 0 to Array[length]

    do

    total total Array[marks]

    end

    percentage (total/10)*100

    return percentage

    Problem 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 byeach student along with his roll number.

  • 8/7/2019 Algorithims Labmanual 2 Solve

    3/8

    Page 2 of 8 cs-102

    BS (cs) - Lab Manual Lab 1: Flowcharts

    10/28/2010 7:47 PM BY M.IRFAN ARSHAD

    Problem 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

    START

    Enter a Name

    & age

    Process on data

    Display name

    &age

    STOP

    If

    age >20

  • 8/7/2019 Algorithims Labmanual 2 Solve

    4/8

    Page 3 of 8 cs-102

    BS (cs) - Lab Manual Lab 1: Flowcharts

    10/28/2010 7:47 PM BY M.IRFAN ARSHAD

    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

    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

  • 8/7/2019 Algorithims Labmanual 2 Solve

    5/8

    Page 4 of 8 cs-102

    BS (cs) - Lab Manual Lab 1: Flowcharts

    10/28/2010 7:47 PM BY M.IRFAN ARSHAD

    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

    Enter scores

    (0-100)

    Add total marks

    Display total

    marks

    STOP

    If

    scores >90

    START

  • 8/7/2019 Algorithims Labmanual 2 Solve

    6/8

    Page 5 of 8 cs-102

    BS (cs) - Lab Manual Lab 1: Flowcharts

    10/28/2010 7:47 PM BY M.IRFAN ARSHAD

    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 isrepresented in these boxes, and arrows connecting them represent flow / direction of flowof 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 programflowchart, 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 adesigner 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 pictorialrepresentation of the flow of the program, algorithm is step by step procedure to solve a givenproblem.

    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 tobe 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.Output3.Definiteness

    4.Effectiveness5.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 amapping function to map input set onto an output set.

  • 8/7/2019 Algorithims Labmanual 2 Solve

    7/8

    Page 6 of 8 cs-102

    BS (cs) - Lab Manual Lab 1: Flowcharts

    10/28/2010 7:47 PM BY M.IRFAN ARSHAD

    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 andbusiness process maps.

    PredefinedProcess

    (Subroutine)

    A Predefined Process symbol is a marker for anotherprocess step or series of process flow steps that are

    formally defined elsewhere. This shape commonlydepicts 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 ordocumentation, then it is best not to use this symbolsince it implies a formally defined process.

    Flow Line(Arrow,

    Connector)

    Flow line connectors show the direction that theprocess flows.

    Decision Indicates a question or branch in the process flow.

    Typically, a Decision flowchart shape is used whenthere 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 fromone point in the process flow to another. Connectorsare usually labeled with capital letters (A, B, AA) to

    show matching jump points. They are handy foravoiding flow lines that cross other shapes and flow

    lines. They are also handy for jumping to and fromsub-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 processflow.

    [Just to confuse things further, some people will use a

    circle to indicate an operation and a square to indicatean 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 moreoften referred to as an I/O shape than a Data shape.

  • 8/7/2019 Algorithims Labmanual 2 Solve

    8/8

    Page 7 of 8 cs-102

    BS (cs) - Lab Manual Lab 1: Flowcharts

    10/28/2010 7:47 PM BY M.IRFAN ARSHAD

    What is a record?

    In computer data processing, a record is a collection of data items arrangedfor 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 offixed-length or be of variable length with the length information contained within the record.