I PUC Unit B

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

UNIT B PROBLEM SOLVING METHODOLOGY 11 MARKS

ONE MARK QUESTION.


1. What is meant by debugging?
The process of finding and correcting
errors in a program is called debugging.

2. What is meant by coding?


It is the process of translating
the algorithm or flowchart into the
syntax of a given programming
language such as C, C++.
3. Define testing.
To check properly the working of a program
by supplying sample of data as input.
4. Define flow-chart.
Pictorial/Graphical representation of an
algorithm
5. Define an algorithm
An algorithm is a step-by-step
finite sequence of instructions,
to solve a well-defined problem.
6. Define stepwise refinement.
It is the process of breaking down
the problem at each stage to
obtain a computer solution is
called stepwise refinement.
7. Define coding.
The process of translating the algorithm or
flowchart into the syntax of a given
programming language.
8. Define Pseudo code
This is an abstract representation of
program in English statement.

TWO MARK QUESTION.


1. What are syntax and semantic error?
Syntax errors: An error which occurs
due to the wrong use of syntax is
referred to as syntax error. (OR)
Errors which occur at the time of
compilation are called syntax errors
Semantic errors: An error which
occurs due to the wrong use of logic
is referred to as semantic error.

2. What is a flowchart? Mention any one


advantage.
The diagrammatic representation of an
algorithm is called flowchart.
Advantages:
1. Communication: Flowcharts are better way
of communication of the logic of a program.
2. Effective Analysis: With the help of
flowchart, problem can be analyzed in more
effective way.
3. Proper documentation: Program flowcharts
serve as a good program documentation, which
is needed for various programs.
4. Proper Debugging: The flow chart helps in
debugging process.
3. Write any two advantages of top-down
approach
 Program can be developed
easily.
 Error free code generation
 Efficiency code generation
Easy to understand the problem.

4. Write any two advantages of an


algorithm
 Very easy to write.
 Easy technique to understand logic
 Easy identification of the mistake by
non computer person.
5. Write any two dis- advantages of an
algorithm.
 Time consuming
 Difficult to show branching and looping.
 Big task are difficult to put in
algorithm.
6. Give any two characteristics/features of
algorithm (Any two)
 Input: The algorithm must accept one or
more data to be processed.
 Definite: Each operational step or
operation must be definite. i.e.,
each and every instruction must
clearly specify that what should
be done.
 Effective: Each operational step can
at least carry out by a person in a
minimum number of times.
 Terminate: After some minimum number
of operations algorithm must come to
an end.
 Output: It must produce one or more
computed result.
7. Write any two advantages of structured
programming
 Structured program is easy to
write as the programming logic is
well organized. Structured programs
are easy to test and debug.
 Structured programs are easy to maintain.
 Structured programs can be functionally
decomposed into logical working units.

8. Write an algorithm to find simple


interest.
Step 1: start
Step 2: Input p,t,r
Step 3: si=(p*t*r)/100
Step 4: output si
Step 5: stop
9. Draw the flowchart symbol for
input/output and decision making.
Input/output

Decision

10. Classify the types of flowchart.


Flowcharts are classified into two
categories:
1. Program Flowcharts
2. System Flowcharts
 Program flowcharts present a diagrammatic
representation of a sequence of
instructions for solving a program.
 System flowcharts indicate the flow of
data throughout a data processing system,
as well as the flow into and out of the
system. Such flowcharts are widely used
by designers, to explain a data
processing system
11. Write the characteristics of a good
program.
 The best program to solve a given problem
is one that requires less space in
memory, takes less execution time, easy
to modify and portable.
 Modification: A good program is the one
which allows any modifications easily
whenever needed.
 Portability: A good program is the one
which can be run on different type of
machine with a minimum or no change.
12. Explain Top-down design
Top-down design involves dividing a
problem into sub-problems and further
dividing the sub- problems into smaller
sub-problems until it leads to sub-
problems that can be implemented as
program statements.

B C

D E F
THREE MARK QUESTION.
1. What is nested if statement? Write its
syntax.
A statement in which one if statement
included within another if statement is
called nested-if- statement. OR
One if statement within another if is
called nested-if statement.

2. Mention three types of basic


constructs used. Explain any one.
A programming constructs is a statement in a
program.
There are 3 basic programming constructs.
 Sequential Constructs
 Selection Constructs
 Iteration Constructs
sequential construct : The
programming statements are executed one
after another in a sequence. There will
be no backward or forward reference.

a) Input statement : is used to input value


into the variable from the input device.
Example:
input a,b,c
b) Assignment statement: used to store a
value in a variable. Example: a=5;
c) Output statement: is used to
display the values of variables on the
standard output device. The word
OUTPUT, DISPLAY, WRITE and PRINT are
used for this purpose. Example: output
a,b,c

3. What is Flow-chart? Mention any one


advantage and any one disadvantage.
Flowchart: The diagrammatic representation
of an algorithm is called flowchart.
Advantage: Flowcharts are better way of
communication of the logic of a program.
Disadvantages: Difficult to modify, Time
consuming
4. Design a flow chart to find the average of
four numbers.
5. Write an algorithm to find sum of digits
of a number.
Step 1: start
Step 2: input n
Step 3: sum =0
Step 4 repeat
step 5 while(n<>0)
Step 5: rem=n%10
sum=sum+rem
n=n/10
end of while
step 6: output sum
step 7:stop

6. What is modularity? Give any two advantages


of modularity
The process of splitting the lengthier
and complex programs into number of
smaller units called modularity.
Advantages of modular programming:
1. Reusability: Rewriting the same
statements every time can be avoided as
the program is represented in the form
of modules.
2. Debugging is easier: Since each
module is smaller and clearer, the user
can easily find and correct the errors.
3. Building Library: User can build his
own library of functions. This reduces
the time and space requirements of the
programs.
4. Portability: Since the functions and
libraries common across different
operating systems, it is easier for us
to port and execute them.

7. Discuss different types of errors.


a. Syntax errors: The grammatical
mistakes in the statements of the
program are called syntax errors.
Example: c=a+b this statement is missing
semicolon(c=a+b;)
b. Semantic error: The wrong use of
logic in the program is termed as
semantic error.
c. Logical error : If the correct
translation of algorithm causes the
program to produce wrong results, the
error is called as logical error.
Example: the condition should be
written while(i<=10) if you print
while(i>=10) in that case you will get
an error called logical error
d. Run-time error: Errors that are
detected during the execution of the
program is called as runtime error.
Example: Division by zero (5/0), infinite
loop,
improper input
8. Write an algorithm to find compound
interest.
Step 1: start
Step 2: input P,T,R
Step 3: CI=P*(1+R/100)T
Step 4: output CI
Step 5: Stop

9. Write an algorithm to find the largest


of 3 numbers using simple if
Step 1: start
Step 2: input a,b,c
Step 3:
large=a;
if (b>large)
large=b
end of if
if (c>large)
large=c
end of if
step 4: output large
Step 5: Stop
FIVE MARK QUESTION
1. With syntax and example, explain the
working of for statement.
For statement is also called as the “fixed
execution” looping statement.
It is normally used when we know exactly
how many times a particular set of
statements is to be repeated again.

Example:
for(int i=1; i<=10; i++)
cout<<i<<setw(4);
2. Explain in brief the various stages of
problem solving.

The steps to follow in the problem solving


process are:

Problem Definition :In this step we define


the problem. The objective of this step is to
eliminate unimportant aspect and focus on the
root problem.
Problem Analysis:
Problem analysis involves identifying the
following:
Inputs – The data we have to work with,
Output – The desired result
Any additional requirements or constraints
on the solution.
Design of solution: The solution to the
problem can be designed by using tools such as
algorithm and flowchart.
Algorithm:An algorithm is a step-by-step
finite sequence of instructions, to solve a
well-defined problem.
Flowchart: The diagrammatic representation
of an algorithm is called flowchart.
Coding :It is the process of translating the
algorithm or flowchart into the syntax of a
given programming language such as C, C++.
a)Testing :Testing is the process of
executing program with a set of sample data
and check the output for correctness.
b)Debugging: It is the process of identifying
and correcting or removing the bugs(errors).
The compiler is used to test and debug the
program.
Documentation: Documentation is reference
material which explains the use and
maintenance of the program (application) for
which it has been written.
Maintenance: Program maintenance means
periodic review of the programs and
modifications based on user’s requirements.
Documentation helps speedy and efficient
maintenance.

3. Write an algorithm to check if the given


number is Armstrong number

Step 1: Start
Step 2: Input N
Step 3: m=n,sum=0
Step 4: Repeat step 5,6,7 while (n!=0)
Step 5: rem=n%10
Step 6: sum=sum+rem*rem*rem
Step 7: n=n/10
End of while loop
Step 8: if (sum==m) then
Output “It is an Armstrong number”
else
Output “It is not an Armstrong number”
endof if
Step 9: Stop

4. Explain the working of the switch statement


with an example.
If we have to choose from one of the many
alternatives.
It is also known as multiple-branch
selection statement.
Syntax:
switch (expression)

case label -1: statement 1;

break;

case label -2: statement 2;


break;

…..

case label -n: statement n;

break;

default : default statement;

Example:

switch(dayno)
{ case 1: cout<<”Monday”;
break;
case 2: cout<<”Tuesday”;
break;
case 3: cout<<”Wednesday”;
break;
case 4: cout<<”Thursday”;
break;
case 5: cout<<”Friday”;

break;
case 6: cout<<”Saturday”;
break;
case 7 : cout<<”Sunday”
break;
default :cout<<”Invalid day number”;

}
5. Write an algorithm and draw a flowchart to
find area and circumference of a circle.
Step 1 : start
Step 2: Read rad
Step 3: area= 3.142* rad*rad
circum = 2 * 3.14 * rad
Step 4: Display area , circum
Step 5: Stop
6. What is flow chart? Explain various
symbols used in it.
Flowchart: The diagrammatic
representation of an algorithm is called
flowchart.

Name Symbol meanings


Oval Beginning or End

Parallelogram Input or Output

Rectangle Process or
Calculation or
Assignment
Rhombus Decision or branching

Preparation For loop(repeated


set of instruction)
Pre-defined process Subprogram

Connector Connection(An entry from,


or an exit to, another part of
flow chart)
Arrows Control flow

7. Write an algorithm to swap two numbers


using third variable.
Step 1: Start
Step 2: Input a,b
Step 3: t=a
a=b
b=t
Step 4: output a,b
Step 5: Stop
RUNNING NOTES...............

ALGORITHM EXAMPLE:
FLOWCHART SYMBOLS AND EXAMPLES:
SELECTION STATEMENTS:
SIMPLE IF
SYNTAX: FLOWCHART

IF- ELSE
SYNTAX: FLOWCHART

IF –ELSE-IF
SYNTAX: FLOWCHART
NESTED IF.....
SYNTAX FLOWCHART

SWITCH CASE
SYNTAX
FLOWCHART

ITERATIVE STATEMENTS

WHILE
SYNTAX FLOWCHART

DO-WHILE
SYNATX FLOWCHART
FOR LOOP
SYNTAX

FLOWCHART

DIFFERENCE BETWEEN WHILE AND D0-WHILE

You might also like