To Computing and Engineering Problem Solving

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 29

Copyright 2012 Pearson Education, Inc.

Chapter 1
INTRODUCTION
TO COMPUTING
AND ENGINEERING
PROBLEM SOLVING

Outline
1. Objectives
2. Computing Systems
3. An Engineering Problem-Solving
Methodology

Copyright 2012 Pearson Education, Inc.

Objectives
Introduce computing and engineering
problem solving, including:
A discussion of hardware and software
A five-step problem-solving methodology?
Copyright 2012 Pearson Education, Inc.

Computing Systems
A computing system is a complete working
system that includes:
Hardware(h\w)
Software (s\w)
Copyright 2012 Pearson Education, Inc.

Hardware
Hardware(h\w) (i.e. they can actually be
touched):
Physical parts of the computing system
that have mass

Computer
Display
Mouse
Printer

Copyright 2012 Pearson Education, Inc.

Hardware
Jon von Neumann computing model
1.
2.
3.
4.

Input device(s)
Output device(s)
Memory Unit
CPU (Central Processing
Unit) consisting of:

C
P
U

Control Unit
ALU (Arithmetic Logic Unit)

Copyright 2012 Pearson Education, Inc.

Hardware
Jon von Neumann computing model
1. Input device(s)

2. Output device(s)

Copyright 2012 Pearson Education, Inc.

Hardware
Jon von Neumann computing model
3. Memory Unit
Stores data
4. CPU(Central Processing Unit)
Controls the transfer and the process of the
data
Control Unit
ALU (Arithmetic Logic Unit)
Copyright 2012 Pearson Education, Inc.

Software
Computer software refers to programs
that reside and execute electronically
on the hardware.
Operating systems: e.g. Windows, Unix, Linux,..
Provide the HCI (Human Computer Interface)

Application programs
Provide problem solutions e.g. M.S. Word, Excel,
Matlab

Copyright 2012 Pearson Education, Inc.

Computer Languages
Computer Languages: three levels
Machine Language: written using the digits 0s and 1s
(binary).
Assembly Language: written in symbolic statements
High-Level Language: C++, Java, Basic, (Englishlike commands.)
Copyright 2012 Pearson Education, Inc.

10

Computer Languages

Copyright 2012 Pearson Education, Inc.

11

Software Interface to
Computer Hardware

Copyright 2012 Pearson Education, Inc.

12

Building a Program
Computers only understand machine
language. High-level languages like C++
must be translated to machine language
for execution.

Copyright 2012 Pearson Education, Inc.

13

Building a Program
program written in a high-level language such as C++
must be translated into machine language

Compiler
Converts source program to object program

Linker
Converts object program to executable program

Copyright 2012 Pearson Education, Inc.

14

Key Terms
Source Program
printable/Readable Program file
Object Program
nonprintable machine readable file
Executable Program
nonprintable executable code
Copyright 2012 Pearson Education, Inc.

15

Errors in Programs
Syntax/Parse Errors
Mistakes with the language.
Always reported by the compiler

Linking Errors
Missing pieces prevent the final assembly of an
executable program.

Run-time Errors
Occur when program is executing.
May or may not be reported.
Copyright 2012 Pearson Education, Inc.

16

Logic Errors
Can be difficult to find.
Debugging can be time consuming.
Better tools for find bugs

It is important to carefully check the output


of your programs for errors.
Even programs that appear to work correctly
may have bugs!

Copyright 2012 Pearson Education, Inc.

17

Debugging
Process of eliminating logic errors
(i.e. bugs) from programs.
User-friendly programming environments
such as Microsoft Visual C++ integrate the
compiler with

text processors and code editors


special tools to help find bugs in programs (debugger)
testing tools
and much more

Copyright 2012 Pearson Education, Inc.

18

Engineering
Problem-Solving
Methodology

19

Five Step
Problem-Solving Methodology
1. State the problem clearly.
2. Describe the input and output information.
3. Work the problem by hand, give example.
4. Develop a solution (Algorithm development) and
convert it to a computer program (C++ program).
5. Test your solution with a variety of data.

20

Example 1
Write a computer program to calculate the
volume of a box based on its length, width
and height. The program should allow the
user to enter the length, width and height
of the box and it should calculate the
corresponding volume and display the
result.

21

Example 1
1. Problem Statement: Write a program to compute the volume of box.
2. Input: length, width, height
Output: volume
3. Hand Example:
volume = 20.75*11.5*9.5
9.5
20.75

11.5

4. Algorithm:
1- input length, width and height
2- compute volume
3- output volume
and Implement algorithm in C++ (See next slide)
5 test.
22

/************************************************************/
/* Example 1
/* This program computes the volume of a box
/************************************************************/
#include <iostream>
using namespace std;

*/
*/

int main()
{
// Declare and initialize objects
double length;
double width;
double height;
double volume;
// get the user input
cout << Enter the length of the box: ;
cin >> length;
cout << Enter the width of the box: ;
cin >> width;
cout << Enter the height of the box: ;
cin >> height;
// Calculate volume.
volume = length * width * height;
// Print the volume.
cout << The volume is << volume << endl;

// Exit program.
return 0;

23

Example 2
(x1,y1
)

1.Problem statement

(x2,
y2)

Compute the straight line


distance between two points in a plane

2.Input/output description
Point 1 (x1, y1)
Point 2 (x2,
y2)

Distance between two


points (distance)

24

Example 2

(contd)

3. Hand example
distance side12 side2 2

side1 = 4 - 1 = 3
side2 = 7 - 5 = 2
distance side12 side2 2

distance 3 2
2

distance 13 3.61
25

Example 2 (contd)
4. Algorithm development and coding
a)

Generalize the hand solution and list/outline the necessary


operations step-by-step
1) Give specific values for point1 (x1, y1) and point2 (x2, y2)
2) Compute side1=x2-x1 and side2=y2-y1
3) Compute
4) Print distance
distance

b)

side12 side2 2

Convert the above outlined solution to a program

5. Testing
26

Example 3: Compute the area of a


triangle
1. State problem
x=3
cm

2. I/O
3. Hand example
area = * 3 *4 = 6 cm2

x
y

y=4 cm
area

4. Develop solution and Coding

5. Testing

1.

Get values of x and y

2.

Compute area = *x*y

3.

Print area

27

Example 4: Given two complex numbers


z1=a1+b1*i and z2=a2+b2*i, find z3= z1+z2
1. State problem

a1
b1
a2
b2

2. I/O
3. Hand example

a3
b3

4. Develop solution and Coding

5. Testing

1.

Get a1 b1 a2 b2

2.

Compute a3 = a1 + a2

3.

Compute b3 = b1 + b2

4.

Print z3 = a3 + b3 * i

28

Example 5: Given the number of seconds,


find number of hours, minutes and seconds
1. State problem

total_sec

2. I/O
3. Hand example
4. Develop solution
and Coding

5. Testing

H
M
S

3675 seconds can be written as


1 hour 1 min 15 sec
1.

Get total_sec

2.

H = total_sec / 3600 (integer


division)

3.

M = (total_sec (H*3600)) / 60
M = (total_sec mod 3600) / 60

4.

S = total_sec (H*3600) (M*60)

5.

Print H hour, M min, S sec

29

You might also like