Chapter 01
Chapter 01
• Mainframe computers
• Midsize computers
• CU (Control Unit):
− Fetches and decodes instructions
− 128 characters
− 3 is encoded as 0110011
• EBCDIC
− Used by IBM
− 256 characters
• Unicode
− 65536 characters
− Two bytes are needed to store a character
Sample Run:
My first C++ program.
The sum of 2 and 3 = 5
7 + 8 = 15
− Linker:
Combines object program with other programs
provided by the SDK to create executable code
− Loader:
• Algorithm:
− Get length of the rectangle
− Get width of the rectangle
− Find the perimeter using the following
equation:
perimeter = 2 * (length + width)
• Find the area using the following equation:
area = length * width
• Get baseSalary
• Get noOfServiceYears
• Calculate bonus using the following formula:
if (noOfServiceYears is less than or equal to
five)
bonus = 10 * noOfServiceYears
otherwise
bonus = 20 * noOfServiceYears
• Get totalSale
• 10 students in a class
• Each student has taken five tests and each
test is worth 100 points.
• Design an algorithm to calculate the grade for
each student as well as the class average.
− Design an algorithm to find the average test score.
− Design an algorithm to determine the grade.
• Data consists of students’ names and their
test scores.
1. totalAverage = 0;
2. Repeat the following steps for each student in the
class.
a. Get student’s name.
b. Use the algorithm as discussed above to find the
average test score.
c. Use the algorithm as discussed above to find the grade
d. Update totalAverage by adding current student’s
average test score.
3. Determine the class average as follows:
classAverage = totalAverage / 10
C++ Programming: From Problem Analysis to Program Design, Third Edition 43
Structured Programming
• Structured design:
− Dividing a problem into smaller subproblems
• Structured programming
− Implementing a structured design
• The structured design approach is also called
− Top-down design
− Stepwise refinement
− Modular programming
• Structured design:
− Problem is divided into small subproblems
− Each subproblem is solved
− Combine solutions to all subproblems