A-WPS Office

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 8

Mary Cristine Ann Catipay

C++ What is OOP?

OOP stands for Object-Oriented Programming.

Procedural programming is about writing procedures or functions that perform operations on


the data, while object-oriented programming is about creating objects that contain both data
and functions.

Object-oriented programming has several advantages over procedural programming:

OOP is faster and easier to execute

OOP provides a clear structure for the programs

OOP helps to keep the C++ code DRY "Don't Repeat Yourself", and makes the code easier to
maintain, modify and debug

OOP makes it possible to create full reusable applications with less code and shorter
development time

C++ What are Classes and Objects?

Classes and objects are the two main aspects of object-oriented programming.

Look at the following illustration to see the difference between class and objects:

class

Fruit

objects
Apple

Banana

Mango

Another example:

class

Car

objects

Volvo

Audi

Toyota

So, a class is a template for objects, and an object is an instance of a class.

When the individual objects are created, they inherit all the variables and functions from the
class.

The four pillars for OOP are Abstraction, Encapsulation, Inheritance, Polymorphism.
Abstraction : Abstraction is the process of showing only essential/necessary features of an
entity/object to the outside world and hide the other irrelevant information. For example to
open your TV we only have a power button, It is not required to understand how infra-red
waves are getting generated in TV remote control.

Encapsulation : Encapsulation means wrapping up data and member function (Method)


together into a single unit i.e. class. Encapsulation automatically achieve the concept of data
hiding providing security to data by making the variable as private and expose the property to
access the private data which would be public.

Inheritance : The ability of creating a new class from an existing class. Inheritance is when an
object acquires the property of another object. Inheritance allows a class (subclass) to acquire
the properties and behavior of another class (super-class). It helps to reuse, customize and
enhance the existing code. So it helps to write a code accurately and reduce the development
time.

Polymorphism: Polymorphism is derived from 2 Greek words: poly and morphs. The word
"poly" means many and "morphs" means forms. So polymorphism means "many forms". A
subclass can define its own unique behavior and still share the same functionalities or behavior
of its parent/base class. A subclass can have their own behavior and share some of its behavior
from its parent class not the other way around. A parent class cannot have the behavior of its
subclass.

Computer Organization refers to the level of abstraction above the digital logic level, but below
the operating system level.

[HIERARCHY]

Click on the image to test your understanding of this hierarchy of abstraction in systems
organization.

At this level, the major components are functional units or subsystems that correspond to
specific pieces of hardware built from the lower level building blocks described in the previous
module.

A closely related term, computer architecture, emphasizes the engineering decisions and
tradeoffs that must be made in order to produce a "good" design. The computer architect
answers questions like...

How many registers should there be?


What machine instructions should there be?

How should the cache be organized?

What hardware support should there be for virtual memory?

Assembly Language

An assembly language is a low-level programming language designed for a specific type of


processor. It may be produced by compiling source code from a high-level programming
language (such as C/C++) but can also be written from scratch. Assembly code can be converted
to machine code using an assembler.

Since most compilers convert source code directly to machine code, software developers often
create programs without using assembly language. However, in some cases, assembly code can
be used to fine-tune a program. For example, a programmer may write a specific process in
assembly language to make sure it functions as efficiently as possible.

While assembly languages differ between processor architectures, they often include similar
instructions and operators. Below are some examples of instructions supported by x86
processors.

MOV - move data from one location to another

ADD - add two values

SUB - subtract a value from another value

PUSH - push data onto a stack

POP - pop data from a stack

JMP - jump to another location

INT - interrupt a process

The following assembly language can be used to add the numbers 3 and 4:
Instruction Set Architecture (ISA)

The Instruction Set Architecture (ISA) is the part of the processor that is visible to the
programmer or compiler writer. The ISA serves as the boundary between software and
hardware. We will briefly describe the instruction sets found in many of the microprocessors
used today. The ISA of a processor can be described using 5 catagories:

Operand Storage in the CPU

Where are the operands kept other than in memory?

Number of explicit named operands

How many operands are named in a typical instruction.

Operand location

Can any ALU instruction operand be located in memory? Or must all operands be kept internaly
in the CPU?

Operations

What operations are provided in the ISA.

Type and size of operands

What is the type and size of each operand and how is it specified?

Of all the above the most distinguishing factor is the first.

The 3 most common types of ISAs are:

Stack - The operands are implicitly on top of the stack.

Accumulator - One operand is implicitly the accumulator.

General Purpose Register (GPR) - All operands are explicitely mentioned, they are either
registers or memory locations.
Lets look at the assembly code of

C = A + B;

in all 3 architectures:

Stack Accumulator GPR

PUSH A LOAD A LOAD R1,A

PUSH B ADD B ADD R1,B

ADD STORE C STORE R1,C

POP C - -

Not all processors can be neatly tagged into one of the above catagories. The i8086 has many
instructions that use implicit operands although it has a general register set. The i8051 is
another example, it has 4 banks of GPRs but most instructions must have the A register as one
of its operands.

What are the advantages and disadvantages of each of these approachs?

Stack

Advantages: Simple Model of expression evaluation (reverse polish). Short instructions.

Disadvantages: A stack can't be randomly accessed This makes it hard to generate eficient code.
The stack itself is accessed every operation and becomes a bottleneck.

Accumulator

Advantages: Short instructions.


Disadvantages: The accumulator is only temporary storage so memory traffic is the highest for
this approach.

GPR

Advantages: Makes code generation easy. Data can be stored for long periods in registers.

Disadvantages: All operands must be named leading to longer instructions.

Earlier CPUs were of the first 2 types but in the last 15 years all CPUs made are GPR processors.
The 2 major reasons are that registers are faster than memory, the more data that can be kept
internaly in the CPU the faster the program wil run. The other reason is that registers are easier
for a compiler to use.

Software, instructions that tell a computer what to do. Software comprises the entire set of
programs, procedures, and routines associated with the operation of a computer system. The
term was coined to differentiate these instructions from hardware—i.e., the physical
components of a computer system. A set of instructions that directs a computer’s hardware to
perform a task is called a program, or software program.

Computer hardware is any physical device used in or with your machine, whereas software is a
collection of programming code installed on your computer's hard drive. In other words,
hardware is something you can hold in your hand, whereas software cannot be held in your
hand. You can touch hardware, but you cannot touch software. Hardware is physical, and
software is virtual.

Memory

Hard Drive or Solid State Drive

Video card

Motherboard

Processor
Power Supply

Monitor

Keyboard and Mouse

Optical Drive DVD/RW

Ethernet or Wireless card

Quite simply, computer hardware is the physical components that a computer system requires
to function. It encompasses everything with a circuit board that operates within a PC or laptop;
including the motherboard, graphics card, CPU (Central Processing Unit), ventilation fans,
webcam, power supply, and so on.

You might also like