Notes-C++ language


The objective of problem solving

The goal of problem solving is to develop a program to solve a problem.The objective is to develop the program with better quality,i.e.,least number of defects,within the time schedule and budget.It may be difficult to solve a complex problem as a whole at one strike.Dividing a problem into a number of small problems makes it easy to solve complex problems.However,such a division of the problem is possible only when the problem is already defined completely and correctly.The problem has to be determined manually for a set of input data,in order to test the correctness of the program.Therefore,problem definition has two parts-input data and output.

The problem solving aspect of programming with examples

Problem solving is making efforts to find a solution to a problem.The complexity of a problem is determined by the time taken to solve it.There are problems that have no readymade solution.Such problems are called Open Problems.
The computer is best suited for its repetitive ability and correctness of solutions to problems.Even an ordinary user can use it and get the results,once the program is written for solving a problem.Quite often,problems are not understood correctly.It may be due to the complexity of the problems.Therefore,if a problem could be explained with the help of examples,it would make it easier to understand.

Example 1:-
To find the some of the digits in a number,we can divide the problem into 3 parts:
(1) finding the modulus of 10
(2) adding the number to a sum whose initial value is zero
(3) dividing the number by 10 and then repeating the process from (1)again till the quotient is zero

The top-down design approach to develop a program

The top design approach works by decomposing a system from a high level of abstraction into a more detailed level (lower level) of abstraction.It allows us to build solutions to a problem in a stepwise manner.It consists of 3 steps which are as follows:-

1. Breaking a problem into sub problems:- Each general statement or set of statements about the solution are taken one at a time, and broken down into a more precisely defined subtasks.These subtasks should more accurately describe how the final goal is to be reached.
2. Choosing data structures:- It is an important decision while devising a computer solution to a problem.Various data structures are available.The choice depends on it’s simplicity and effectiveness in processing data.
3. Construction of loops:- The implementation of subtasks in top-down design may involve the loops or iterative constructs.Loops with i/o statements, expressions and assignments are the core of program implementation.

Modular Programming

A method in which long programs are divided into smaller program or modules that can be designed,coded and debugged separately with a minimum amount of interaction.It’s characteristics/features are as follows-

*Each module should do only one thing

*Communication between modules is allowed only by a calling module

*Module can be called by one higher module only

*No communication can take place directly between modules that do not have calling called relationship

*All modules are designed as single entry,single exit systems using control structures