Unit 2 Programmnig
Unit 2 Programmnig
LESSON 1
HOW DO YOU APPLY
WHAT YOU HAVE LEARNED?
Answer the following questions. Read carefully and write your answer on the space provided.
Encapsulation
Abstraction
Inheritance
Polymorphism
language features.
Compiler-Based
2. Illustrate and discuss the steps required to process a program written in C++.
A text editor is used in creating C++ program using the rules or syntax of the
programming language. The written program is called the source code, or source program and
must be saved in a text file format that has the extension .cpp.
The programmer gives the command to compile the program. In a C++ system, a
preprocessor program executes automatically before the compiler’s translation. The C++
preprocessor obeys commands called preprocessor directives, which indicate that certain
Step 3: Linker
The programs that you write/compose in a high-level language are developed using an
integrated development environment (IDE). The IDE provides programs that are useful in
developing your program. A program known as linker combines the object program with the
Step 4: Loader
Before a program can be executed, it must first be placed in memory. This is done by
the loader, which takes the executable image from disk and transfers it to memory. Additional
components from shared libraries that support the program are also loaded.
Finally, the computer, under the control of its CPU, executes the program one instruction
at a time.
TRUE OR FALSE. Write T if the statement is true. If not, write F.
1. The C++ Standard Library does not need a function to manipulate files, strings, etc.
Answer: F
2. Today C++ is now partially used to write device drivers and other software that rely on
direct manipulation of hardware under real-time constraints.
Answer: T
3. C++ is broadly used for teaching and research because it is clean enough for the
effective teaching of basic concepts.
Answer: T
4. Programmers who have used either an Apple Macintosh or a PC running Windows have
indirectly used C++ for the primary or the central user interfaces of these systems are
written in C++.
Answer: T
5. C++ was developed by Bjarne Stroustrup in 1969 at Bell Labs in Murray Hill, New Jersey,
as an improvement version to the C language and originally named C with Classes, but
later it was renamed C++ in 1988.
Answer: F
6. The preprocessor observes the code before the actual compilation of various code
begins and resolves all these directives.
Answer: T
7. C++ is a subset of C, and that virtually any legal C program is a standard C++ program.
Answer: T
8. The IDE does not contain a program that is not useful in creating your program.
Answer: F
9. A program called a linker that integrates the object program with the programs from
libraries.
Answer: T
10. Encapsulation is a process of separating data members and functions in a single unit
called class.
Answer: F
1. It is one of the OOP features which allows the child class to acquire the properties and
functionality of the parent class.
Answer: Encapsulation
2. A ___ are lines included in the code of programs preceded by a hash sign.
Answer: Preprocessor Directives
3. In C++ programming, this program loads an executable program into the main memory?
Answer: Loader
4. It is the machine language version of the high – level language program. It also knows how to
perform specific actions and how to interact with other elements of the program.
Answer: Source Program
5. This class ___ inherits another class known as a derived class or subclass.
Answer: Child Class
6. While this class is being inherited by another class, it is also known as the superclass or base
class.
Answer: Parent Class
7. It is one of OOP features where you show only relevant details to the user and hide irrelevant
information.
Answer: Inheritance
8. The ___ is an attempt to ensure that C++ is portable that code you write for Microsoft compiler
will compile without errors, using a computer on a Mac, UNIX, a Windows box, or an Alpha.
Answer: ANSI Standard
9. The ___ checks a source program for syntax errors and if no error is
found, translates the program into the equivalent machine program.
Answer: Compiler
RELATIONAL OPERATOR
Symbol Definition
LOGICAL OPERATOR
Symbol Definition
1. int x, y, z;
x=2;y=3;z=4;
x+=1;
y*=z;
x++;
3. Copy the value of int variable firstnum into an int variable secondnum
Answer: int firstnum,secondnum;
secondnum=firstnum;
4. Declare a char variable grade and set the value of grade to ‘A’;
Answer: char grade;
grade=’A’;
5. The user will input the length and width of a rectangle. Store the inputted length to int variable l
and the inputted width to int variable w
Answer: int l,w;
printf(“input length:”);
scanf(“%d”,&l);
printf(“input width:”);
scanf(“%d”,&w);
6. Suppose an int variable x has an initial value of 2, write one (1) print statement that will display
the given sequence of numbers from the initial value of x.
2 4 6 8 10
Answer: int x,x1,x2,x3,x4;
x=2;
x1=2+2;
x2=2+2+2;
x3=2+2+2+2;
x4=2+2+2+2+2;
printf(“%d %d %d %d”,x,x1,x2,x3,x4);
Instruction: Answer the following questions. Read carefully and write your answer on the space
provided.
1. 4>=3 True
2. z=5; z == 0 False
3. 6 >= 8 False
4. a=1; if (a != 1) False
a. Variable
b. Data types
c. Operators
ANSWER: A
2. This arithmetic operator is the remainder after dividing one number by another.
a. Multiplication
b. Division
c. Modulus
ANSWER: C
3. What symbol do we use in C++ programming when putting a single line comment?
a. / /
b. /* */
c. */ /*
ANSWER: A
4. One of the rules in the naming of an identifier should start with a capital letters A through Z.
a. True
b. False
ANSWER: A
a. Variable
b. Data types
c. Operators
ANSWER: B
UNIT 2: C++ B
6. An ___ is a symbol that tells the compiler to perform specific mathematical or logical manipulations.
a. Variable
b. Data types
c. Operators
ANSWER: C
7. What symbol do we use for Increment Operators?
a. ++
b. --
c. ==
ANSWER: A
a. ++
b. --
c. ==
ANSWER: B
9. This arithmetic operation represents the operation of removing objects from a collection.
a. Addition
b. Division
c. Subtraction
ANSWER: C
a. !=
b. >=
c. %
ANSWER: C
FILL IN THE BLANKS. Find the missing Data Type value. Write your answer on the space
provided.