You are on page 1of 8

Lesson 1: Problem Solving and Errors

Slide 1: Lesson Outline


This document is designed to help you take notes while watching the videos for this
lesson. Print these slides before going to the Video Lectures.
Note: Reviewing this material is not sufficient to fully understand the topic; you should
also complete the readings and exercises.
Review these slides

Definitions (slides 2-4)


Problem Solving (slides 5-14)
Programming Errors (slide 15)

Slide 2: Definitions
Vocabulary
What is a Computer?

Data:

Information:

Computer:

Lesson 1

Slide 3: Definitions (cont'd)


Program vs. Algorithm
Computer Program:
A set of instructions written in a specific programming language that causes a computer
to perform a specific task.
Algorithm:
A step-by-step list of instructions that, when carried out, produces a solution to a
problem.

Slide 4: Definitions (cont'd)


What is a Programming Language?
It is a language with strict grammar rules, symbols and special words used to construct
a computer program.

Slide 5: Problem Solving


Steps in Problem Solving
1. Problem Specification
- Understand problem
- Identify input/output
2. Solution Design
- Work problem out by hand for specific case
- Design general algorithm
3. Implementation, Coding and Documentation
- Write program in programming language
4. Testing and Debugging
- Test program for specific example used in step 2
- Test with other values

Lesson 1

6: Problem
m Solving
g (cont'd
d)
pting Sho
ortcut?

7: Problem
m Solving
g (cont'd
d)
ple of Alg
gorithm Developm
D
ment
m:
st of 100 so
ocial insurance numbe
ers. Each nu
umber is on
n an index ccard.

8: Problem
m Solving
g (cont'd
d)
ple of Alg
gorithm Developm
D
ment (con
nt'd)
m:
st of 100 so
ocial insurance numbe
ers. Each nu
umber is on
n an index ccard.
ossible Solution:
hrough deck
k a first tim
me, find sma
allest numb
ber, place ca
ard at the ttop of the d
deck;
hrough remaining 99 cards
c
and find smallestt and place it second ffrom the to
op;
hrough in th
his fashion until all carrds have beeen ordered
d.

Slide 9: Problem Solving (cont'd)


Example of Steps in Problem Solving
Problem:
Write a program that converts from miles (m) to kilometers (km).
1. Problem Specification

Need to know that 1 mile is equivalent to 1.6093 kilometers

x miles is equivalent to ( x* 1.6093) km

Input miles * output kilometers

Slide 10: Problem Solving (cont'd)


Example of Steps in Problem Solving (cont'd)
2. Solution Design

Display message: Please enter distance in miles:__"

Read the miles (m)

Compute the number of kilometers (km)

Display message: "Equivalent distance in kilometers is:__ ."

Lesson 1

11: Proble
em Solving (cont''d)
ple of Ste
eps in Pro
oblem Solving (co
ont'd)
lementatio
on
es2km.cp
pp
nvert mil
les to ki
ilometers
s.
ude <iost
tream>
namespac
ce std;
ain()
m
km
m;
double miles,
cout << "Please enter di
istance i
in miles:
:";
cin >> miles;
m
km = mil
les * 1.6
6093;
cout<"Eq
quivalent
t distanc
ce in km is :" <<
< km << e
endl;
return 0;
0

12: Proble
em Solving (cont''d)
ple of Ste
eps in Pro
oblem Solving (co
ont'd)
lementatio
on (cont'd
d)
es2km.cp
pp
nvert mil
les to ki
ilometers
s.
ude <iost
tream>
namespac
ce std;
ain()
m
km
m;
double miles,
cout << "Please enter di
istance i
in miles:
:";
cin >> miles;
m
km = mil
les * 1.6
6093;
cout<<"E
Equivalen
nt distan
nce in km
m is :" <
<< km << endl;
return 0;
0

13: Proble
em Solving (cont''d)
ple of Ste
eps in Pro
oblem Solving (co
ont'd)
lementatio
on (cont'd
d)
es2km.cp
pp
nvert mil
les to ki
ilometers
s.
ude <iost
tream>
namespac
ce std;
ain()
m
km
m;
double miles,
cout << "Please enter di
istance i
in miles:
:";
cin >> miles;
m
km = mil
les * 1.6
6093;
cout<<E
Equivalen
nt distan
nce in km
m is : <
<< km << endl;
return 0;
0

14: Proble
em Solving (cont''d)
C++ Program Sta
ages

15: Progr
ramming Errors
re three general categ
gories of errrors:
tax Errors
ons of the C++
C
gramm
mar rules
t by the com
mpiler
-Time Erro
ors
alled an exe
ecution erro
or
t during the
e running of
o the progrram
cal Errors
in design of
o program
t produce an error message
ce incorrectt output

You might also like