Module 1 - Processing A C++ Languange Program PDF
Module 1 - Processing A C++ Languange Program PDF
Module 1 - Processing A C++ Languange Program PDF
CS 2 - Fundamentals of Programming
1
North Luzon Philippines State College
CS 2 - Fundamentals of Programming
Module 1: An overview of
computers and programming
languages
2
North Luzon Philippines State College
CS 2 - Fundamentals of Programming
Computers have evolved from their introduction in the 1950s, when there were few computers,
through the 1960s, when
manufacturers produced
very large, expensive
computers, to the 1970s
when people began to use
cheaper, smaller
computers. Today,
computers are even more
affordable and faster.
Regardless of the type,
mainframe, midsize and
micro (personal) computers
share some basic elements,
including input, output,
storage and performance of
arithmetic and logical
operations.
A mainframe
computer was once on of
the largest, fastest and most powerful computers available. However, to put this in perspective, a
mainframe in 1960 was less powerful than today’s personal computer. During the next decade, the
midsize computer was introduced as a less expensive, less powerful, smaller and more affordable
alternative to mainframe. The introduction of micro computers or personal computers (PC), brought
all of these efficiencies to a level that made computers a household commodity. PCs are usually sold
with descriptions of their features to help consumers (who are often not computer experts) match the
computer’s features with their needs.
a) Personal computers
1. 1950s
b) When computers became affordable for non-
2. 1960s specialist
3. 1990s c) A less expensive and smaller computers than a
mainframe that allowed more companies to
4. Mainframe
affordable computers
5. Midsize computer d) When accessibility to computers was limited to
6. microcomputer very few people
e) When large companies began to use
computers
f) Until recently, one of the largest, fastest and
most powerful computers
3
North Luzon Philippines State College
CS 2 - Fundamentals of Programming
✓ Central processing unit (CPU), which contains the control unit (CU), arithmetic logic
unit (ALU), and various registers for special purposes such as the instruction register
(IR) and program counter (PC);
✓ Main memory (MM), also called random access memory (RAM); and
✓ Input/output devices and secondary storage
The CPU is the brain of the computer and determines the computer’s speed. The ALU, an
important
component of the CPU, carries out all arithmetic and logical operations. The accumulator, holds the
results of the operations performed by the ALU. Amin memory is directly connected to the CPU. Main
memory is an ordered sequence of cells. Each cell has a unique location in a memory, called the
address of the cell. Both data and instructions (program) are stored in a main memory. All instructions
(programs) and data must be loaded into main memory before they can be executed or performed.
Programs and data are transferred to secondary storage when they are not being executed. Programs
4
North Luzon Philippines State College
CS 2 - Fundamentals of Programming
are commands that perform input (get data), produce output (display result), provide storage, and
calculate arithmetic and logical operations. There are two types of programs, system programs and
applications programs. Application programs perform a specific task. Examples of application
programs include word processing, spreadsheets, and games.
6
North Luzon Philippines State College
CS 2 - Fundamentals of Programming
7
North Luzon Philippines State College
CS 2 - Fundamentals of Programming
4. The digits 0 and 1 are called ____________ or the shortened term ____________.
5. The digits 0s and 1s is referred to as ____________.
6. The sequence of eight bits is referred to as ____________.
7. The most common encoding scheme on personal computer is ____________ and is
abbreviated as ____________.
8. C++ differentiates uppercase and ____________ characters.
9. A program that translate assembly language instructions into machine language is called
a ____________.
10. A program that translate instructions written in a high-level language into machine code
is called a ____________.
8
North Luzon Philippines State College
CS 2 - Fundamentals of Programming
1. Identify the process needed to convert a high-level language program, in this case C++ to
an executable program
1 #include <iostream>
2 using namespace std;
3
4 int main()
5 {
6 cout << “Welcome to the C++ Programming “ << endl << endl;
7 cout << “Anything in double quotes is a string.” << endl;
8 cout << “ Numbers in quotes are a string like 8 + 7 “ << endl;
9 cout << “ Numbers not in quotes like “ << 8 << “ or “
<< 7<< “ have their values printed.” << endl;
10 cout << Numbers not in quotes with arithmetic operations are “
<< “evaluated “ << 8+7 << endl;
11 return 0;
12 }
9
North Luzon Philippines State College
CS 2 - Fundamentals of Programming
The line numbers along the left margin of the code are not part of the program but are used
to identify the line; each number line refers to a statement in the code, as explained in the following:
Line 2 using namespace std; is required in order to use cout ( the predefined object) and endl (the
manipulator); cout is used for output and endl is used for moving the insertion point to the next line.
Line 4 identifies the beginning of the main function, int main (). All programs are functions in C++.
Line 5 begin with an opening brace ( { ), is the beginning of the body of the main function. All functions
begin with an opening and end with a closing ( } ).
Line 6, 7 and 8 the cout object and the insertion operator ( << ) cause the values between double
quotes, referred to as a string to be displayed exactly as written. Each string, expression, or
manipulator is preceded by the insertion operator ( << ) within the cout statement.
Line 9 an output statement that contains both a string and literal numbers ( numbers not in quotes)
as separate data items ( called expressions ). Numbers displayed as their literal value.
Line 10 is another output statement that contains a string and an arithmetic operation (expression).
The arithmetic operation is evaluated and displayed as evaluated. Lines 9 and 10 are continued the
next line but remain part of the same statement
Line 11 contains the reserved word return. When the program finishes, a return value of 0 tells the
operating system that the program has completed.
C++m is up one language level from assembly language. It is one of many high-level language
that use parts of a natural language to make it easier to understand. Six steps are necessary to
process a program written in a high-level language:
1. Use a text editor to create source code in the high level language. The text editor is contained
in the SDK. The source code must follow the rules of (syntax) of the language. Save the
source code of the program in a file that has a .cpp file extension. The next editor contained
in the SDK.
2. Begin with the preprocessor directives needed for the program. This statement is processed
by a program called the preprocessor.
3. The compiler is a program that verifies that the source code obeys the rules of the
programming language (the syntax). When the program is syntactically correct, the compiler
10
North Luzon Philippines State College
CS 2 - Fundamentals of Programming
translates the program into a machine language program called an object program. The
compiler is a part of a software development kit (SDK).
4. Another program in the SDK is called a linker, which combines the object program with
prewritten code from libraries, such as iostream, creating an executable program. This is
usually performed with the “Build” or “ Make” command in the SDK.
5. An additional program in the SDK is called the loader, which loads the executable program
into main memory.
6. Finally, execute or run programs.
2. A file that contains the program after it has been translated into machine code is
a. editor file c. object file
b. source code file d. .cpp file
3. An assembler is
a. A high-level language that uses a natural language
b. A program is the SDK that links source code with prewritten code
c. A program that translates assembly code into machine code
d. A program that place a source code file into main memory
4. The rules for correctly writing a C++ source code program are known as
a. Grammar c. Preprocessing
b. Syntax d. SDK
5. The program that places the executable program into main memory in
a. Compiler c. Preprocessor
b. Editor d. loader
11
North Luzon Philippines State College
CS 2 - Fundamentals of Programming
Answer the following questions in a short bond and complete the steps for problem solving.
References
Bronson, G. (2006). Program development and design using C++, 3rd ed. USA:
Course technology
https://www.tutorialspoint.com/cplusplus/cpp_basic_syntax.htm
https://www.computerscience.gcse.guru/topic/programming
https://edu.glogster.com/glog/the-evolution-of-the-omputer/243q4cn92aq?=
glogpedia-source
https://www.w3schools.com/cpp/
https://play.google.com/store/apps/details?id=org.zhiyuan.zhiyuan24r/243q4cn92aq?=
12