0% found this document useful (0 votes)
58 views

Unit 2 Programmnig

The document provides information about a student named Norberte Mark Junnel C. who is enrolled in Section BIT CT-2A and taking the subject CP 201 Computer Programming 1. It includes two lessons that discuss features of the C++ programming language like object-oriented programming, how a C++ program is processed and compiled, relational and logical operators, and examples of C++ code. The lessons contain questions to test the student's understanding that are either true/false or involve identifying terms.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Unit 2 Programmnig

The document provides information about a student named Norberte Mark Junnel C. who is enrolled in Section BIT CT-2A and taking the subject CP 201 Computer Programming 1. It includes two lessons that discuss features of the C++ programming language like object-oriented programming, how a C++ program is processed and compiled, relational and logical operators, and examples of C++ code. The lessons contain questions to test the student's understanding that are either true/false or involve identifying terms.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Name: Norberte, Mark Junnel C.

Section: BIT CT-2A                                                                             

Subject: CP 201 Computer Programming 1

Topic: Unit 2 C++ Basics

LESSON 1
HOW DO YOU APPLY
WHAT YOU HAVE LEARNED?
Answer the following questions. Read carefully and write your answer on the space provided.

1. Give features of C++ as programming language.

 OOP (Object-Oriented Programming)

Encapsulation

Abstraction

Inheritance

Polymorphism

 Platform or Machine Independent/ Portable

 Middle-level language, as it covers combination of both low-level and high-level

language features.

 Compiler-Based
2. Illustrate and discuss the steps required to process a program written in C++.

Step 1: Create a Program

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.

Step 2: Processing and Compiling a C++ Program

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

manipulations are to be performed on the program before compilation. 

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

programs from libraries.

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.

Step 5: Execute the Program

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

IDENTIFICATION. Identify the following questions below.

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

10. It is a statically typed, compiled, general-purpose, case-sensitive, freeform.


Answer: C++
LESSON 2
HOW DO YOU APPLY
WHAT YOU HAVE LEARNED?

A. Think About This!

Enumerate the relational and logical operators and its definition.

RELATIONAL OPERATOR

Symbol Definition

< Compares if the value of the left operand is less


than the value of the right operand.

> Compares if the value of the left operand is


greater than the value of the right operand.

<= Compares if the value of the left operand is less


than or equal to the value of the right operand.

>= Compares if the value of the left operand is less


than or equal to the value of the right operand.

== Compares if the values of two operands are


equal or not.

!= Compares if the values of two operands are


equal or not.

LOGICAL OPERATOR

Symbol Definition

&& Logical AND operator. If both the operands are


nonzero, then the condition becomes true.

|| Logical OR Operator. If any of the two operands


is non-zero, then condition becomes true.

! Logical NOT Operator. Use to reverses the


logical state of its operand. If a condition is true,
then Logical NOT operator will make false.
B. Find the final value of each variable.

1. int x, y, z;

x=2;y=3;z=4;
x+=1;
y*=z;
x++;

x =__3__ y = _12___ z =____4___

Write the appropriate C++ statements to accomplish the


following:

1. Declare variables x and y as integers. Initialize x to 5 and y to 10.


Answer: int x,y;
x=5;
y=10;

2. Update the value of an int variable x by adding 5 to it.


Answer: int x,y;
X=5+5;
Y=10;

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.

A. Identify each given identifier if valid or invalid.

No Identifier Valid or Invalid


1. _123abc INVALID
2. 1st_year INVALID
3. first-number INVALID
4. first_number VALID
5. Last Name INVALID
6. percent% INVALID
7. int_x; INVALID
8. a=7 INVALID
9. Second VALID
10. difference2 VALID
B. Find the Boolean result of each given expression.

No Boolean Expression Result

1. 4>=3 True

2. z=5; z == 0 False
3. 6 >= 8 False

4. a=1; if (a != 1) False

5. y=2; y <= 7 True

C. Circle the letter of the correct answer.

1. A ___ is used to hold data.

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

5. A ___ defines a set of values that a variable can hold.

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

8. What symbol do we use for Decrement Operators?

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

10. Which symbol does not belong to Relational Operator?

a. !=

b. >=

c. %
ANSWER: C
FILL IN THE BLANKS. Find the missing Data Type value. Write your answer on the space
provided.

Type Typical Bit Width Typical Range

char 1byte -127 to 127 or 0 to 255

unsigned char 1byte 1. 0 to 255

signed char 2. 1byte -127 to 127

3. int 4bytes -2147483648 to 2147483647

4. unsigned int 4bytes 5. -2147483648 to 2147483647

signed int 4bytes -2147483648 to 2147483647

6. short int 2bytes 7. -32768 to 32767

unsigned short int 8. Range 0 to 65,535

signed short int 9. Range 10. -32768 to 32767

long int 4bytes -2,147,483,647 to 2,147,483,647

signed long int 11. 4bytes 12. same as long int

unsigned long int 4bytes 0 to 4,294,967,295

13. float 4bytes +/- 3.4e +/- 38 (~7 digits)

14. double 8bytes +/- 1.7e +/- 308 (~15 digits)

long double 8bytes +/- 1.7e +/- 308 (~15 digits)

15. wchar_t 2 or 4 bytes 1 wide character

You might also like