Problem Solving and Programming Concepts
Problem Solving and Programming Concepts
Programming Concepts
Problem Solving in Everyday Life
People make decisions every day to solve problems that affect their lives.
In this step, you need to identify and evaluate the pros and cons of each possible
solution before selecting the best one.
List instructions that enable you to solve the
problem using the selected
solution.
No instruction can be used unless the individual or the machine can understand it.
To evaluate or test a solution means to check its result to see if it is correct, and
to see if it satisfies the needs of the person(s).
For Example, When a person needs a piece of furniture to sleep on, buying her a
cot may be a correct solution, but it may not be very satisfactory.
If the result is either incorrect or unsatisfactory, then the problem solver must
review the list of instructions to see that they are correct or start the process all
over again.
If any of these six steps are not
completed well,
the results may be less than desired.
Is there Anybody who do not Suffer from
any Problem in Daily Life???????
NO………….
People solve problems daily at home, or work, or wherever they go. Problems
at home include such things as what to cook for dinner, which movie to see
this evening, which car to buy, or how to sell the house.
At work, the problems might involve dealing with fellow employees, work
policies, management, or customers. The better the decisions an employee
can make, the more valuable that person will be to the company.
Example: Take the problem of what to do this evening.
1. Identify the problem. How do the individuals wish to spend the evening?
2. Understand the problem. With this simple problem, also, the knowledge base
of the participants must be considered. The only solutions that should be
selected are ones that everyone involved would know how to do. You probably
would not select as a possible solution playing a game of chess if the
participants did not know how to play.
Example: Take the problem of what to do this evening.
3. Identify alternatives.
a. Watch television.
b. Invite friends over.
c. Play video games.
d. Go to the movies.
e. Play miniature golf.
f. Go to the amusement park.
g. Go to a friend’s party.
The list is complete only when you can think of no more alternatives.
Example: Take the problem of what to do this evening.
Program: means the set of instructions that make up the solution after they have
Computers are built to deal with algorithmic solutions, which are often difficult
or very time consuming for humans.
People are better than computers at developing heuristic solutions.
Example, Solving a Calculus Problem or alphabetizing 10,000 names are very
easy task for computer.
But the problem of how to throw a ball or how to speak English is not. The only
difficulties lies in programming.
Problem Solving With Computers
The field of computers that deals with heuristic types of problems is called
artificial intelligence.
Artificial intelligence enables a computer to do things like the human can do.
As a result, the computer’s problem-solving abilities are similar to those of a
human being.
Constants and Variables
The computer uses constants and variables to solve problems.
A constant is a value never changes during the processing of all the instructions
in a solution.
Constants can be any type of data—numeric, alphabetical, or special symbols.
During the execution of the program, this constant is given a value and then is
referred to by its name.
For example, the value of PI does not change, it would be a constant and defined
within the program.
Constants and Variables
The only way to change the value of the constant is to change the program.
Many name conventions says that constants can be given names containing all
capital letters in order to easily distinguish them from variables.
The value of a variable may change during processing.
It is also called as Identifiers.
Variables can be of any data type, just as constants can.
A programmer must give a name to each variable value used in a solution.
Naming Conventions for Constants and Variables
1) Name a variable according to what it represents, that is, Hours for hours
worked, PayRate for rate of pay, and so on.
2) Do not use spaces in a variable name.
3) Start a variable name with a letter.
4) Do not use a dash (or any other symbol that is used as a mathematical operator)
in a variable name.
5) Be consistent when using upper- and lower-case characters. In some languages
HOURS is a different variable name than Hours.
Data Types and Their Data Sets
How the Computer Stores Data?
The computer stores data internally in memory locations.
These data are found by the variable names used by a program.
Each memory location can hold one and only one value at a time.
When a user enters a new value into the variable location, the previous value is
destroyed.
These memory locations are temporary.
When a program completes its instructions, and/or when the computer is
turned off, the values stored in the internal memory are destroyed.
How the Computer Stores Data?
• When data, information, or programs have to be kept for future, they are stored
externally on an external storage medium such as a hard disk drive in storage
areas called files.
• There are basically two types of files: program files and data files.
• Program files contain the instructions to tell the computer what to do.
• Data files contain the data required to execute the program files.
Functions
• Functions are small sets of instructions that perform specific tasks and return
values.
• They are usually built into a computer language.
• Functions are repeatedly used in the problem solving process in order to
shorten the problem-solving time and improve the readability of the solution.
• Each language has a set of functions within it.
• Most languages allow programmers to write their own functions.
Functions
• A function is a block of code that has a name and it has a property that it is reusable.
• The form of a function is the name of the function followed by an open parenthesis,
followed by the data needed to perform the function and concluded by a closed
parenthesis:
Function_Name(data)
• The value of the result of the function is returned in the name of the function.
• Functions use data. The data is listed as part of the function and are called parameters.
• Sqrt(N) function will calculate the square root of N.
• Max(N1, N2, N3), will find which of three numbers is the largest.
Functions
• These functions have been divided into classes.
• Mathematical functions (square root, absolute value, or a random
number).
• String functions(copy part of the string into another variable, find the
length or the number of characters in the string).
• Conversion functions(convert a string value to a numeric value).
• Statistical functions(maximum values, minimum values).
• Utility functions(date and time functions).
Operators
• The computer has to be told how to process data.
• Operators are the data connectors within expressions and equations.
• They tell the computer how to process the data.
• They also tell the computer what type of processing (mathematical, logical, or
whatever) needs to be done.
• Mathematical, relational, and logical operators.
• The operand and the resultant are two concepts related to the operator.
• Operands can be constants or variables.
Operators
• Mathematical operators include addition, subtraction, multiplication,
division, integer division, modulo division, powers, and functions.
• Relational operators include the following: equal to, less than, greater than,
less than or equal to, greater than or equal to, and not equal to. A programmer
uses relational operators to program decisions. The resultant of a relational
operation is logical data type True or False.
The problem analysis chart is an aid to clear thinking because it helps the problem solver
to identify the essential data and information in a problem and to disregard the
nonessentials.
Developing the Interactivity Chart
Procedural Object-Oriented
Top-Down Approach
Within each module the execution is procedural.
• The top-down method simply means that as you divide the problem into
subtasks.
• When using the top-down method, the module that encompasses the complete
solution becomes what is called the Control module because it controls the
processing of all the data.
• Dividing a solution into modules is not an easy job. When you approach a
solution to a problem, you need to think about the basic things you want to
accomplish, during the processing, in general terms.
• Some of these might be input of data, initialization of data, types of processing
such as calculations or putting data in order, and completing the solution.
Developing the IPO Chart
• The IPO (input-processing-output) chart extends and organizes the information in
the problem analysis chart.
• It shows in more detail what data items are input, what processing takes place on
that data, and what information will be the end result, the output.
• The output is the first to be completed in an IPO chart. The next is the input,
and the last is the processing.
• An analogy to completing an IPO chart would be planning a trip. The first
thing you need to know is the destination—San Francisco, Paris, New York.
This information is the output. Then you can plan what to pack, your means
of transportation, and all the other essentials for starting out—the input.
• Finally, you plan the route—the processing. How can you know what to pack
or what route to follow if you don’t know where you’re going?
Writing the Algorithms
After using the structure chart and the IPO chart, the next step in organizing a
solution is for the programmer to develop sets of instructions for the computer,
called algorithms.