Chapter 1
Chapter 1
Office hours:
Mon: 11:30 am -1:30 pm, Wed; 10:00 am-12:00 pm; Fri: 10:am – 12:00 pm
Office Place: Light Engineering Building Room 208
English mathematician.
Designed the Analytical Engine in the early
Charles Babbage
1800s.
Analytical Engine
Augusta Ada Byron Published “Of the Analytical Engine” in
Digital Computers 1864.
HISTORICAL PERSPECTIVE
9/1/2010 Engineering Problem Solving with 7 9/1/2010 Engineering Problem Solving with 8
C++ second edition, J. ingber C++ second edition, J. ingber
Analytical Engine Analytical Engine
Luigi F. Menabrea, French engineer and
Designed to process base ten numbers. mathematician, described Babbage’s vision
Consisted of four parts: of a machine capable of solving any
– Storage unit problem using:
– Processing unit – Inputs
– Input device – Outputs
– Output device – Programs written on punch cards
9/1/2010 Engineering Problem Solving with 9 9/1/2010 Engineering Problem Solving with 10
C++ second edition, J. ingber C++ second edition, J. ingber
9/1/2010 Engineering Problem Solving with 11 9/1/2010 Engineering Problem Solving with 12
C++ second edition, J. ingber C++ second edition, J. ingber
Digital Computers Digital Computers
ENIAC(Electronic Numerical Integrator Intel Pentium 4 Processor.
And Calculator) • Weighs < 16 ounces.
• Developed by research team lead by John Mauchly • Executes trillions of instructions per second.
and J. Presper Eckert during the early 1940s.
• Weighed 30 tons.
• Executed hundreds of instructions every second.
9/1/2010 Engineering Problem Solving with 13 9/1/2010 Engineering Problem Solving with 14
C++ second edition, J. ingber C++ second edition, J. ingber
COMPUTING SYSTEMS
9/1/2010 Engineering Problem Solving with 17 9/1/2010 Engineering Problem Solving with 18
C++ second edition, J. ingber C++ second edition, J. ingber
9/1/2010 Engineering Problem Solving with 21 9/1/2010 Engineering Problem Solving with 22
C++ second edition, J. ingber C++ second edition, J. ingber
9/1/2010 Engineering Problem Solving with 27 9/1/2010 Engineering Problem Solving with 28
C++ second edition, J. ingber C++ second edition, J. ingber
Number Systems Number Systems
Base ten number system Base two (binary) number system
• Ten decimal digits (0,1,2,3,4,5,6,7,8,9) • Two binary digits (0,1)
• Each digit multiplies a power of ten • Each digit multiplies a power of two
– Example: – Example:
24510 = 2*102 + 4*101 + 5*100 101102 = 1*24 + 0*23 + 1*22 + 1*21 + 0*20
= 1*16 + 0*8 + 1*4 + 1*2 + 0*1
= 16 + 0 + 4 + 2 + 0
= 2210
9/1/2010 Engineering Problem Solving with 29 9/1/2010 Engineering Problem Solving with 30
C++ second edition, J. ingber C++ second edition, J. ingber
9/1/2010 Engineering Problem Solving with 33 9/1/2010 Engineering Problem Solving with 34
C++ second edition, J. ingber C++ second edition, J. ingber
9/1/2010 Engineering Problem Solving with 35 9/1/2010 Engineering Problem Solving with 36
C++ second edition, J. ingber C++ second edition, J. ingber
Example: 2’s Complement Example: 2’s Complement
Form the 2’s complement representation for Add 127 to -127
the value -12710 assuming a word size of 8 01111111
for simplicity. +
12710 = 011111112 10000001
Negate bits: 10000000 = _______
Add 1: 10000001 00000000
2’s complement is 10000001
9/1/2010 Engineering Problem Solving with 37 9/1/2010 Engineering Problem Solving with 38
C++ second edition, J. ingber C++ second edition, J. ingber
Example
First Program – volume of a box
1. Write a program to compute the volume of box.
2. Input: length, width, height /************************************************************/
/* Program chapter1 */
Output: volume /* */
/* This program computes the volume of a box */
3. Hand Example: /************************************************************/
#include <iostream>
volume = 20.75*11.5*9.5 using namespace std;
9.5 int main()
{
11.5 // Declare and initialize objects
20.75
double length( 20.75), width(11.5),height(9.5), volume;
// Calculate volume.
volume = length * width * height;
4. Solution: input length, width and height // Print the volume.
compute volume cout << “The volume is “ << volume << endl;
output volume // Exit program.
return 0;
5. Implement algorithm in C++ and test. }
/************************************************************/