1experiment: 1: Aim: To Study Algorithm and Flow Charts Learning Outcomes: Learner Would Be Able To
1experiment: 1: Aim: To Study Algorithm and Flow Charts Learning Outcomes: Learner Would Be Able To
1Experiment: 1
PART A
Task 1:
For the following Problem Statements write Algorithm and Draw a Flowchart.
1. Krishna goes to market for buying milk and vegetables. He is having a currency of Rs.500
with him. From a shop he purchases 2.0 liters Milk priced Rs.50.0 per liter, 1.5 kg Carrots
priced Rs.35.0 per kg, 2.5 kg Tomatoes priced Rs.10.0 per kg. He gives the currency of
Rs.500 to the shopkeeper. Find out the amount shopkeeper will return to Krishna.
Inputs to the algorithm are:
1. amount of different items purchase, for example 2.0 kg Apple etc.
2. price of the items, for example Mango is Rs. 35.0 per kg
3. total amount given to the shopkeeper
Expected output:
Amount to be returned by shopkeeper after deducting total price of the purchased
vegetables and fruits, and total items purchased.
2. The below given flowchart is used to find whether a number X is even or odd. What will be
content in the decision box? Write an algorithm for the same.
1
Mukesh Patel School of Technology Management & Engineering, SVKM’s NMIMS University
COURSE: Programming for Problem Solving
3. Obtain the user’s choice to find area of given shape (Rectangle, Circle and Triangle).
Calculate and output the area of the shape chosen. List the variables required and draw the
flowchart (using the same names as your variable list). Also perform a dry run using input of
6 for the circle.
4. Obtain a temperature in degrees celsius from the user. If the temperature is 35 degrees or less
display the message "Go play Cricket" otherwise, if the temperature is between 36 to 55
degrees display the message "Go for indoor games", display the message "It is chilling" if the
temperature is less than 5 degrees and “It is very hot” if the temperature is above 55 degrees.
2
Mukesh Patel School of Technology Management & Engineering, SVKM’s NMIMS University
COURSE: Programming for Problem Solving
Theory:
Algorithm:
Defined as: “A sequence of activities to be processed for getting desired output from a given input.”
+ Addition
- Subtraction
* Multiplication
/ Division
Example:
Algorithm to add two numbers entered by the user.
Step 1: Start
Step 2: Declare the variables Num1, Num2 and Sum
Step 3: Read values Num1 and Num2
Step 4: Add Num1 and Num2 and assign the result to Sum
Sum = Num1+ Num2
Step 5: Display Sum
Step 6: Stop
3
Mukesh Patel School of Technology Management & Engineering, SVKM’s NMIMS University
COURSE: Programming for Problem Solving
Flowchart:
Defined as a diagram which visually presents the flow of data through processing systems. Flowchart
can be used for representing an algorithm. It describes the operations (and in what sequence) are
required to solve a given problem.
4
Mukesh Patel School of Technology Management & Engineering, SVKM’s NMIMS University
COURSE: Programming for Problem Solving
Experiment: 1
(PART B: TO BE COMPLETED BY STUDENTS)
Students must submit the soft copy as per following segments within two hours of the practical. The
soft copy must be uploaded on the portal at the end of the practical. The filename should be
RollNo_Batch_ExperimentNo_OOP Example: B001_B1_Exp1_OOP
1. ALGORITHM:
Step 1: Start
Step 2: Initialize Variable amount to 500, milk_rate to 50, carrot_rate to 35, tom_rate
amount = 500
milk_rate = 50
carrot_rate = 35
tom_rate = 10
milk_qty = 2
carrot_qty = 1.5
tom_qty = 2.5
Step 3: Calculate amount to be returned by the shopkeeper and assign it to variable amount
(tom_qty*tom_rate)]
Step 5: Stop.
2.
5
Mukesh Patel School of Technology Management & Engineering, SVKM’s NMIMS University
COURSE: Programming for Problem Solving
Conclusion (Learning Outcomes): Reflect on the questions answered by you jot down your
learnings about the Topic: Algorithm and Flowchart.
Homework Questions:
1. Write an algorithm and draw a flowchart that will obtain from the user a length and width for
a rectangle. Calculate and output the area and perimeter of the rectangle. Perform a dry run
using inputs of 6 and 12 for the rectangle.
3. Write an algorithm and draw flow chart to read the marks of students and classify them into
different grades. If the marks secured are greater than or equal to 90, the student is awarded
grade A; but if they are greater than or equal to 80 but less than 90, Grade B is awarded; if
they are greater than or equal to 65 but less than 80, Grade C is awarded; otherwise Grade D
is awarded.