Professional Documents
Culture Documents
SVKM’s NMIMS
Experiment: 1
PART A
TASK: Read two numbers from the user and add these 2 numbers and store the result for
future use
Inputs /outputs/operations
Step 1: accept first number from user into variable A
Step 2: accept second number from user into variable B
Step 3: accept third number in X
Step 4: accept fourth number in Y
STEP 5: accept fifth number in V
Step 6 : accept sixth number
Step 3: Perform C = A+B
Step 4: store the addition/result into C
Step 5: stop
Iterations:
A.3 Theory:
Algorithm:
Defined as: “A sequence of activities to be processed for getting desired output from a given input.”
+ Addition
- Subtraction
* Multiplication
/ Division
Flowchart:
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
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.
A.4 Task 1:
For the following Problem Statements write Algorithm and Draw a Flowchart.
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
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.
Algorithm:
Step 1: Total 0, i 1;
8
Algorithm and Flow Chart Spet2: Read amount purchased and unit price of item i
Step3: Total Total + amount of itemi* price per unit of itemi
Step4: i i+1
Step5: Repeat Step 2 to 4 for each purchased item
Step6: Read Total amount given to the shopkeeper as GivenAmount
Step7: RefundAmount GivenAmount-Total
Step8: Print amount to be refund is Rs.: RefundAmount
Step9: Print total item purchased are: i
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.
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
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 Fahrenheit from the user. If the temperature is 60 degrees
or more display the message "Go play Cricket" otherwise, if the temperature is between
65 to 70 degrees display the message "Go for indoor games", otherwise display the
message "It is chilling".
PART B
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
PPS_batch_rollno_experimentno Example: PPS_A1_A001_P1
B.1 complete all tasks given in PART A of this lab manual and write your answer
(Algorithm and flowchart here)
1.
Step 1: Start
Step 2: Store the total as 0.
Step 3: Store i as 1.
Step 4: Print “Do you wish to add an item?”.
Step 5: Accept value, if Yes x=1 and if No x=0.
Step 6: Repeat steps 7 to 10 for each given item if x=1.
Step 7: Accept the amount of item i purchased as A.
Step 8: Accept the unit price of item i as P.
Step 9: Store Total =Total + A*P
Step 10: Store i=i+1
Step 11: Else x=0, Read Total amount given to the shopkeeper as Given Amount
Step 12: Store Refund Amount = Given Amount - Total
Step 13: Print amount to be refund is Rs: Refund Amount
Step 14: Print total item purchased are: i
Step 15: Stop.
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
2.
3.
Step 1: Start
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
Step 2: Print “Do you wish to find the area a shape?” Accept x;
Step 3: If x = yes, repeat
Step 4: Print “What shape do you wish to find the area of?” Accept s;
Step 5: If s= rectangle; accept l and b;
Step 6: Store area r = l*b;
Step 7: Print r; Repeat Step 2;
Step 8: If s= circle; accept r1;
Step 9: Store area c= pi*(r1) ^2;
Step 10: Print c; Repeat Step 2;
Step 11: If s= triangle; accept h and b1;
Step 12: Store area t = (b1*h)/2;
Step 13: Print t; Repeat Step 2
Step 14: Stop
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
4.
Step 1: Start
Step 2: Read temperature in degrees Fahrenheit in “Temp”
Step 3: if Temp >= 60 and Temp<65
Then display “Go play cricket”
Step 4: Else if Temp >=65 and Temp <= 70
Then display “ Go for indoor games”
Step 5: Otherwise display “it is chilling”
Step 6: Stop
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
1. I learnt how to create algorithms and flowcharts which helped me build programming logic.
2. Algorithms and Flowcharts are basic building blocks for programming and is not dependent on
any syntax. Hence, once Algorithms and flowcharts are built, programming in any language is
possible.
3. Flowcharts help covers all scenarios and possible outcomes to the given problem.
B.3 Conclusion (Learning Outcomes): Reflect on the questions answered by you jot down your
learnings about the Topic: Algorithm and Flowchart. You must list your personalized conclusive
remarks in line with the learning outcomes listed in PART A.
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.
Step 1: Start
Step 2: Read l and w
Step 3: Store area r = l*w
Step 4: Store perimeter p= 2(l + w)
Step 5: Display r and p
Step 6: Stop
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving
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
Step 1: Start
Step 2: Read marks ‘m’;
Step 3: if m >= 90
Then display “The student is awarded grade A.”
Step 4: Else if m <90 and m>=80
Then display “The student is awarded grade B.”
Step 5: Else if m <80 and m>=65
Then display “The student is awarded grade C.”
Step 6: Otherwise display “The student is awarded grade D.”
Step 7: Stop.
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving