You are on page 1of 14

SVKM’s NMIMS University

Mukesh Patel School of Technology Management & Engineering


COURSE: Programming for Problem Solving

SVKM’s NMIMS

Mukesh Patel School of Technology Management and


Engineering, Vile Parle, Mumbai- 400056

Department of Electronics & Telecommunication

Manual of Programming for


Problem Solving
SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving

Experiment: 1
PART A

(PART A: TO BE REFFERED BY STUDENTS)

A.1 Aim: To study Algorithm and Flow charts

A.2 Learning Outcomes: Learner would be able to

1. Interpret the steps of algorithm into a flowchart.


2. Explain the features of each symbol of the flowchart.
3. Analysis the scenario to write algorithm and flowchart (breaking the problem into steps of
selection, sequence).

TASK: Read two numbers from the user and add these 2 numbers and store the result for
future use

TASK: perform addition of 10 numbers

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

ITERATION: REPETATION OF STEPS {EXTRA KNOWLEDGE: How many times to be


repeated?, how will I keep track of number of repetition? What to repeat ?

Step 1: start algorithm


SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving

Step 2: set Counter =1 and SUM =0 { initialization }


Step 3: Repeat steps 4 to 6 till Counter is not equal to 10
Step 4: read NEXT number into X
Step 5: SUM = SUM+X
STEP 6: Counter = Counter +1
Step 6: 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

 Assignment. For example B  Y*7 means B will


have the value of Y*7

Read For taking input

Print For displaying output

Start For beginning the algorithm steps

End For stopping the algorithm steps to make it a finite


algorithm

if <condition> then <statement> else For conditional statement


<statement>

Go to step n For moving to step n

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.

Sr.No Shape Description

1 Terminal: To represent the start and end of algorithms

2 Input/Output: To represent the input and output or the


read and write operations of algorithms.

3 Processing: To represent the processing of instructions


like arithmetic operation and data manipulators.

4 Decision: To represent branching of the statements. To


take decisions. There will be one entry point and more
than one exit point.

5 Flow Line: To represent flow of data or the sequence of


statements.

6 On-page Connector: Used to join different flowline

7 Off-page Connector: Used to connect flowchart portion


on different page.

8 Predefined Process/Function: Used to represent a


group of statements performing one processing task.

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".

Inputs : temperature in degrees Fahrenheit


Outputs : display of messages in 3 categories
Processing :
1. If the temperature is 60 degrees or more display the message "Go play Cricket"
2. 65 to 70 degrees display the message "Go for indoor games",
3. otherwise display the message "It is chilling".

Step 1: Read temperature in degrees Fahrenheit in “Temp”


Step 2: if Temp >= 60
Then display “Go play cricket”
Step 3: Else if Temp >=65 and Temp <= 70
Then display “ Go for indoor games”
Step 4: Otherwise display “it is chilling”
Step 5: Stop

PART B

(PART B: TO BE COMPLETED BY STUDENTS)


SVKM’s NMIMS University
Mukesh Patel School of Technology Management & Engineering
COURSE: Programming for Problem Solving

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

Roll No.: L032 Name: Samyuktha Jagesh Mandampully

Prog/Yr/Sem: CSDS 311/1/1 Batch: L2

Date of Experiment: 15/9/21 Date of Submission: 18/09/21

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

B.2: Observations and Learning:

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. I can interpret the steps of algorithm into a flowchart confidently.


2. I can explain the features of each symbol of the flowchart precisely.
3. I can conduct the analysis of the scenario to write algorithm and flowchart (breaking the
problem into steps of selection, sequence).

B.4 Question of Curiosity / 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.

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

2. Draw a flowchart to match the following pseudocode:


Step1: Assign variable n1 a starting value of 6
Step2: Assign variable n2 a starting value of 8
Step3: Add 9 to n2
Step4: Store the value n1 times n2 in variable n3
Step5: Store the value n2 minus n1 in n2
Step6: Display n1, n2 and n3
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

You might also like