Two popular approaches to programing design are the structured approach and the objectoriented approach:
Structured design: Dividing a problem into small subproblem. This process of
implementing a structured design is
Elements of a Computer System
A Computer: It is an electronic device capable of performing commands.
1. Input (getting data)
2. Output (Display results)
4. Performance of arithmetic and logical operations
Input (Read) Statement
In most cases the standard input device is the keyboard
When the computer gets the data from the keyboard, the user is said to be acting
cin is used with > to gather input
The stream extraction operator i
It happens when the user tries to put a value that does not match the data type of the
int a, b, c;
The user entered 32.65.
In a the computer will store 32 but then the computer will try to put the . in b which
Data must be loaded into main memory before it can be manipulated
Storing data in memory is a two-step process:
1. Instruct computer to allocate memory
2. Include statements to put data into memory
Allocating Memory with constants and v
I/O Streams and Standard I/O Devices
Three basic operations of a program:
1. It gets data
2. It manipulates the data
3. It outputs the result
I/O: sequence of bytes called stream from source to destination.
Bytes are usually characters, unl
Left and right Manipulator
left: left-justifies the output
Disable left by using unsetf
right: right-justifies the output
Types of Manipulators
Two types of manipulators:
Parameterized: require iomanip header
Notes from the class
Scalable code: A code that can be reused and fixed. We can perform it. We can add to it,
The only language that computers understand is machine language (binary code)
Debugging: Fix the lines that have problems in t
Order of Precedence
When there is more than one operator, the order of precedence fallows the same rules than the
order of precedence in arithmetic.
First *, /, %
Second +, Because *, /, % have the same level of precedence, the operations are
Processing a C+ Program
Source Code or source program: A program written in high language. In the first step the
program that is written in the text editor. It has to have the extension .cpp. If the name that you
gave to it is FirstProgram th
1. The indirection operator causes the value entered by the user to be stored,
not in input , but in the variable pointed to by input .
2. The value 7 will be displayed if the expression *iptr is sent to cout. If the
expression iptr is sent to cout, the a
Review Questions and Exercises
1. Describe the difference between the if/else if statement and a series of if statements.
In an if/else if statement, the conditions are tested until one is found to be true. In a series of if statements, all o
Declaring and initializing variables
If we declare a variable and do not assign any value to it, the value of the variable is
going to be whatever was saved in that space before.
Variables can be initialized when declared:
int first = 13, sec
A computer can proceed:
Selectively (branch): making a choice
Repetitively (iteratively): looping
Some statements are executed only if certain conditions are met
A condition is met if it evaluates to true
Then + C where x
Then where a and a
Algebra Rules for finite Sums
where c is a constant that does not depend on k
Programing with the problem Analysis-Coding-Execution Cycle
Programing is a process of problem solving.
Algorithm: A step by step problem solving process in which a solution is arrived at in a
finite amount of time.
Steps in programing to sol
Saving and Using the Value of an Expression
To save the value of an expression:
Declare a variable of the appropriate data type
Assign the value of the expression to the variable that was declared
Use the assignment statement
The clear function
When an input stream enters the fail state, the system ignores all further I/O using that
stream. We can use the stream function clear to restore the input stream to a working
Once in a fail state, all further I/O statements usin
The Evolution of Programing Languages
The only consistence in computers is that all data is storage and manipulated in binary
Assembly language: in assembly language, an instruction is an easy to remember form
The Language of Computer
Because computers are electronic devices they use electronic signals to process information.
Two Types of electrical signals:
1. Analog signals: are continuous wave forms used to represent such things as sounds.
Using Predefined Functions in a program
Predefined functions: Functions that are already written. They are organized as a
collection of libraries called header files.
Header file may contain several functions
To use a predefined function, you need
There are two ways to initialize a variable:
By using the assignment statement
feet = 35;
By using a read statement
cin > feet;
Increment and Decrement Operators
Increment operator: increment variable by 1
Basic Elements of C+ (Chapter 2)
Computer program: It is a sequence of statements whose objective is to accomplish a task.
Programing: It is a process of planning and crating programs.
Sample Run: When you compile and execute a program.
Taking in account
Function definition syntax:
Formal parameter list syntax:
We do not need to put return at the end of the function, if we put it is to finish the
Function call syntax:
Actual parameter list syntax:
A new simple data type can be defined by specifying its name and the values, but
not the operations
The values must be identifiers
value1, value2, are identifiers called enumerators
value1 < value2 < value3 <.
Array: a collection of a fixed number of components wherein all of the
components have the same data type
In a one-dimensional array, the components are arranged in a list form
Syntax for declaring a one-dimensional array:
the int expression has
Cin and the get function
The get function
Inputs next character (including whitespace)
Stores in memory location indicated by its argument
The syntax of cin and the get function:
Is a char variable
Is the argument or parameter of the f