0% found this document useful (0 votes)
271 views10 pages

Grade 11 - CP 4 Introduction To Problem Solving

Uploaded by

kumar sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
271 views10 pages

Grade 11 - CP 4 Introduction To Problem Solving

Uploaded by

kumar sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CHAPTER – 4

INTRODUCTION TO PROBLEM SOLVING


BBE:
1. Write pseudocode that reads two numbers and divides one by another and displays
the quotient.
input num1, num2
quotient  num1 / num2
print quotient
2. Two friends decide who gets the last slice of a cake by flipping a coin five times. The
first person to win three flips wins the cake. An input of 1 means player 1 wins a flip,
and a 2 means player 2 wins a flip. Design an algorithm to determine who takes the
cake?
input num
if num = 1 then
Print “Player 1 has won”
else if num = 2 then
Print “Player 2 has won”
else
Print “Enter 1 or 2 only”
3. Write the pseudocode to print all multiples of 5 between 10 and 25 (including both
10 and 25).
For i in sequence 10..25
If i modulus 5 = 0 then
Print i
4. Give an example of a loop that is to be executed a certain number of times.
The FOR loop, can be executed a certain number of times. E.g.,
For i in sequence 1..5 OUTPUT:
Print i 1 2 3 4 5
5. Suppose you are collecting money for something you need Rs. 200 in all. You ask
your parents, uncles and aunts as well as grandparents. Different people may give
either Rs. 10, Rs. 20 or even Rs. 50. You will collect till the total becomes 200.
Write the algorithm.
Total = 0
While total < 200
Input money
Total = total + money
6. Write the pseudocode to print the bill depending upon the price and quantity of an
item. Also print Bill GST, which is the bill after adding 5% of tax in the total bill.
Input itemname, price, qty
billamount = price * qty
gstamount = billamount * 0.05
print itemname, price, billamount
print “GST =”, gstamount
print “Total amount = “, billamount + gstamount
7. Write a pseudocode that will perform the following :
a. Read the marks of three subjects : Computer Science, Mathematics and Physics
out of 100.
b. Calculate the aggregate marks.
c. Calculate the percentage of marks.
input cmarks, mmarks, pmarks
total = cmaks + mmarks + pmarks
perc = (total / 300) * 100
print cmarks, mmarks, pmarks
print “Aggregate=”, total
print “Percentage=”, perc
8. Write an algorithm that performs the following : Ask a user to enter a number. If
the number is between 5 and 15, write the word GREEN . If the number is between
15 and 25, write the word BLUE. If the number is between 25 and 35 , write the
word ORANGE. If it is any other number write that ALL COLOURS ARE
BEAUTIFUL.
Ans.:
input num
if num >=5 and num <= 15 then
print “GREEN”
else if num >=15 and num<=25 then
print “BLUE”
else if num >=25 and num<=35 then
print “ORANGE”
else
print “ALL COLOURS ARE BEAUTIFUL”
9. Write an algorithm that accepts four numbers as input and find the largest and
smallest of them
Ans.:
input n1, n2, n3, n4
if n1> n2 and n1>n3 and n1>n4 then
print n1 “ is greatest”
else if n2 > n1 and n2>n3 and n2>n4 then
print n2 “is greatest”
else if n3 > n1 and n3 > n2 and n3 > n4 then
print n3 “is greatest”
else if n4 > n1 and n4 > n2 and n4 > n3 then
print n4 “is greatest”
if n1<n2 and n1 < n3 and n1 < n4 then
print n1 “is smallest”
else if n2 < n1 and n2 < n3 and n2 < n4 then
print n2 “is smallest”
else if n3 < n1 and n3 < n2 and n3 < n4 then
print n3 “ is smallest”
else if n4 < n1 and n4 < n2 and n4 < n3 then
print n4 “is smallest”
10. Write an algorithm to display the total water bill charges of the month depending
upon the number of units consumed by the customer as per the following criteria :
i. for the first 100 units @ 5 per unit.
ii. For next 150 units @ 10 per unit.
iii. More than 250 @ 20 per unit.
Ans. :
input units
if units > 250 then
bill = (units – 250) * 75 + 150 * 10 + 100 * 5
else if units > 100 then
bill = (units – 100) * 10 + 100 * 5
else
bill = units * 5
print units, bill
11. What are conditionals? When they are required in a program?
Conditionals are the statements that test a condition.
Conditionals are required in a program where the control has to take different
flow – of – action depending upon a condition’s result.
12. Match the pairs.
Flowchart Symbols Functions

- Start / Stop of the Process

- Data

- Process Step

- Decision Making

- Flow of Control
13. Following is an algorithm for going to school or college. Can you suggest
improvements in this to include other options? Reach_School_Algorithm
a. Wake up b. Get ready c. Take lunch box
d. Take bus e. Get off the bus f. Reach school or college
Ans.:
It can be modified to incorporate situations where a different course of action is
required. E.g., if bus is missed.
Wake up
Get ready
Take lunch box
If taken bus then
Ride the bus
Get off the bus
Else
Take other means of transport
Get down at school
Reach school or college.
14. Write a pseudocode to calculate the factorial of a number
(Hint. Factorial of 5 , written as 5! = 5x4x3x2x1)
Input num
F=1
While num > 1
F = F * num
num = num – 1
print F
15. Draw a flowchart to check whether a given number is an Armstrong number. An
Armstrong number of three digits is an integer such that the sum of the cubes of its
digits is equal to the number itself. For example, 371 is an Armstrong number since
3**3 + 7**3 + 1**3 = 371.
Ans. : mod gives remainder - dev gives quotient - a**b means ab
Start

Input num

d1 = num mod 10
q1 = num div 10
d2 = q1 mod 10
q2 = q1 div 10
d3 = q2 mod 10

n1 = d3 **3 + d2 ** 3 + d1 ** 3

is
num = n1

print
“Not an Armstrong number”

Print “Armstrong number”

Stop

16. Following is an algorithm to classify numbers as “Single Digit”, “Double Digit” or


“Big”.
Classify_Number_Algo
input number
if number <= 9
“Single Digit”
else if number < =99
“Double Digit”
else
“Big”
Verify for (5, 9, 47, 99, 100, 200) and correct the algorithm if required.
Ans.:
1. Input number
2. If number < 9
3. “Single Digit”
4. Else if number < 99
5. “Double Digit”
6. Else
7. “Big”

Number Lines Executed OUTPUT


5 1, 2, 3 Single Digit 
9 1, 2, 4, 5 Double Digit 

47 1, 2, 4, 5 Double Digit 
99 1, 2, 4, 6, 7 Big 

100 1, 2, 4, 6, 7 Big 
200 1, 2, 4, 6, 7 Big 

The error in given algorithm is that it should also test for equality i.e., as :
Input number
If number <= 9
“Single Digit”
Else if number <= 99
“Double Digit”
Else
“Big”
17. For some calculations, we want an algorithm that accepts only positive integers
upto 100.
Accept_1to100_Algo
Input number
If(0<=number) and (number <=100)
ACCEPT
Else
REJECT
(a) On what values will this algorithm fail?
(b) Can you improve the algorithm?

Ans.:
a) The given algorithm will fail at input number as zero(0).
b) Corrected algorithm :
Input number
If(0 <= number) and (number <= 100)
ACCEPT
Else
REJECT

II. ANSWER THE FOLLOWING :


1. Mention the steps you would follow while writing a program.
The steps to creating a working program are :
o Understand the problem well.
o Analyse the problem to
 Identify minimum number of inputs required for output.
 Identify processing components.
o Design the program by
 Deciding step by step solution.
 Breaking down solution into simple steps
o Code the program by
 Identifying arithmetic and logical operations required for solutions.
 Using appropriate control structures such as conditional or looping
control structures.

2. Write pseudocode to print Even numbers between 1 to 50.


Start
I=1
While i < = 50
Repeat steps 4 through 5
If((i%2)=0) then
Display i
I= i + 1
Stop

3. What is dry run?


A dry run is the process of a programmer manually working through their code
to trace the value of variables. There is no software involved in this process.

4. Name some useful tools for program development.


Programming tools like assemblers, compilers and linkers translate a program
from a human write-able and readable source language into the bits and bytes that can
be executed by a computer.

5. What is an algorithm?
A Step by step representation of the program is called algorithm.

6. What is a flow chart?


A graphical or pictorial representation of the program is called flow – chart.
7. What is pseudocode?
The written format of a program or program coding is called as pseudocode. ..

8. What is the difference between an algorithm and pseudocode?


Algorithm Psudocode
An algorithm is a step-by-step A pseudocode is a technique of
procedure developed to solve a developing an algorithm
problem,
9. What is the use of trace table?

MCQ’s :
1. The value of radix in binary number system is ______ .
a. 2 b. 8 c. 10 d. 16
2. The value of radix in octal number system is _____ .
a. 2 b. 8 c. 10 d. 16
3. The value of radix in decimal number system is _____ .
a. 2 b. 8 c. 10 d. 16
4. The value of radix in hexadecimal number system is _____ .
a. 2 b. 8 c. 10 d. 16
5. Which of the following are not valid symbols in octal number system?
a. 2 b. 8 c. 9 d. 7

6. Which of the following are not valid symbols in hexadecimal number system?
a. 2 b. 8 c. 9 d. G e. F
7. Which of the following are not valid symbols in decimal number system?
a. 2 b. 8 c. 9 d. G e. F
8. The hexadecimal digits are 1 to 0 and A to ______ .
a. E b. F c. G d. D
9. The binary equivalent of the decimal number to is ___ .
a. 0010 b. 10 c. 1010 d. 010
10. ASCII code is a 7 bit code for .......
a. letters b. numbers c. Other symbols d. All of these
11. How many bytes are there in 1011 1001 0110 1110 numbers?
a. 1 b. 2 c. 4 d. 8
12. The binary equivalent of the octal Numbers 13.54 is ......
a. 1011.1011 b. 1001.110 c. 1101.110 d. None of these
13. The octal equivalent of 111 010 is ......
a. 81 b. 72 c. 71 d. 82
c.

14. The input hexadecimal representation of 1110 is _____.


a. 0111 b. E c. 15 d. 14
15. Which of the following is not a binary number?
a. 1111 b. 101 c. 11E d. 000
16. Convert the hexadecimal number 2C to decimal :
a. 3A b. 34 c. 44 d. 43
c.

17. UTF8 is a type of ______ encoding.


a. ASCII b. Extended ASCII c. Unicode d. ISCII
18. UTF32 is a type of ______ encoding.
a. primary b. RAM c. Unicode d. ISCII
19. Which of the following is not a valid UTF8 representation?
a. 2 octal (16 bits) b. 3 octal (24 bits)
c. 4 octal (32 bits) d. 8 octal (64 bits)
c.

20. Which of the following is not a valid encoding scheme for characters?
a. ASCII b. ISCII c. Unicode d. ESCII

II. FILL IN THE BLANKS :


1. The Decimal number system is composed of 10 unique symbols.
2. The Binary number system is composed of 2 unique symbols.
3. The Octal number system is composed of 8 unique symbols.
4. The Hexadecimal number system is composed of 16 unique symbols.
5. The illegal digits of octal number system are 8 and 9 .
6. Hexadecimal number system recognizes symbols 0 to 9 and A to F.
7. Each octal number is replaced with 3 bits in octal to binary conversions.
8. Each Hexadecimal number is replaced with 4 bits in Hex to binary conversion.
9. ASCII is a 7 bit code while extended ASCII is a 8 bit code.
10. The ISCII encoding scheme represents Indian Languages characters on
computers.
11. The Unicode encoding scheme can represent all symbols / characters of most
language.
12. UTF8 can take upto 4 bytes to represent a symbol.
13. UTF32 takes exactly 4 bytes to represent a symbol.
14. Unicode value of a symbol is called code point.

III. TRUE / FALSE QUESTIONS :


1. A computer can work with Decimal Number system - False
2. A computer can work with Binary number system - True
3. The number of unique symbols in Hexadecimal number system is 15 - False
4. Number systems can also represent characters. - False
5. ISCII is an encoding scheme created for Indian language characters- True
6. Unicode is able to represent nearly all languages characters - True
7. UTT8 is a fixed-length encoding scheme - False
8. UTF32 is a fixed-length encoding scheme - True
9. UTF8 is a variable – length encoding scheme and can represent
Characters in 1 through 4 bytes - True
10. UTF8 and UTF32 are the only encoding schemes supported by
Unicode - False

You might also like