You are on page 1of 4

LAB MANUAL 1:

BASIC OF OBJECT ORIENTED PROGRAMMING


PREPARED BY: M. MAHMUDUL HASAN
OBJECTIVE
An understanding of computer programming and OOP language
Understand the syntax and structure of C++ coding
To write a C++ program to perform input and output operation
PERQUISITE
Basic knowledge of inputs, outputs, and variables
Basic knowledge of functions, conditional statements and loops
THEORY AND PRACTICE OF OOP
COMPUTER PROGRAMMING
Programming is a core activity in the process of performing tasks or solving problems with the
aid of a computer
[Problem or task specification]-COMPUTER-[solution/completed task]
In reality, things are not (yet) that simple. In particular, the "specification" cannot be given to the
computer using natural language. Moreover, it cannot (yet) just be a description of the problem
or task, but has to contain information about how the problem is to be solved or the task is to be
executed. Hence we need programming languages.
PROGRAMMING LANGUAGE
There are many different programming languages, and many ways to classify them. For
example:
High-level programming languages are languages whose syntax is relatively close to natural
language (C, C++, Java)
The syntax of low-level languages includes many technical references to the nuts and bolts
(0's and 1's, etc.) of the computer.

HISTORY OF C++
C++ extensions of C were first invented by Bjarne Stroustrup in 1979 and it was called C with
classes, became C++ in 83. First revision 1985, Second revision 1990, Third revision 1994
(ISO standardization is an international organization for standardization) C++ is used by
hundreds of thousands of programmers in essentially every application domain.
C++ is being highly used to write device drivers and other software that rely on direct
manipulation of hardware under real-time constraints. C++ is an Object Oriented Programming
(OOP) Language. OOP is an approach that provides a way of modularizing programs by creating
partitioned memory area for both data & functions that can be used as templates for creating
copies of such modules on demand.
PROCEDURAL vs. OBJECT ORIENTED PROGRAMMING
Procedural programming is a programming paradigm, derived from structured programming,
based upon the concept of the procedure call. Procedures, also known as routines, subroutines,
methods, or functions.
Object-oriented programming (OOP) is an approach to problem-solving where all
computations are carried out using objects. An object is a component of a program that knows
how to perform certain actions and how to interact with other elements of the program.
PILLARS OF OOP DEVELOPMENT
Encapsulation (data hiding): The wrapping of data & functions together is known as
encapsulation.
Abstraction: Prevention of data accessing of a class for other class objects is known as data
abstraction.
Inheritance: A mechanism that helps objects of one class to inherit properties from objects
of other class. Inheritance supports re-usability.
Polymorphism: A same action can cause different reaction from different objects.

C++ CODING ENVIRONMENT


Introduce the environment of Code blocks. How to open a file, save a file with extension,
compile and execute a C++ code file.

C++ PROGRAM STRUCTURE


#include <iostream>
Modern C++ headers do not use .h extension
using namespace std;
A namespace creates a declarative region in which various program elements can be placed.
Namespace is used to group class, objects and functions. It says the program will be using names
that have a meaning defined for them in the std namespace (in this case the iostream header
defines meaning for cout and cin in the std namespace).
int main()
main() is where program execution begins.
{
int year;
cout << Enter Current Year;
cin >> year
cout << "Hello World \n ";
// prints Hello World
cout << "Hello World <<endl; // prints Hello World
cout << "Hello World << year << endl; // prints Hello World and year
return 0;
}
All characters inside any comment are ignored by C++ compiler. C++ supports single line and
multi-line comments. A comment can start with // (double slash) extending to the end
of the line
//This is a comment
C++ comments can also start with /* and end with */. For example:
/* This is a comment */
/* C++ comments can also span multiple lines */
REFERENCES
Teach Yourself C++, 3rd Edition, Herbert Schildt.
The C++ Complete Reference, 4th Edition, Herbert Schildt
http://www.tutorialspoint.com/cplusplus/index.htm
http://erlerobotics.gitbooks.io

LAB EXERCISE
EXERCISE: 1
Write a program that ask for a name and say hello to the name.
EXERCISE: 2
Create a directory (folder) called "Arithmetic_Calculation". Inside this directory, create a
program file called "Arithmetic.cpp", save the file, write the solution of following problems,
compile it, and run it.
Write a program that takes two input from the keyboard separately by displaying the following
text in the monitor and asking for Insert Number 1: and put this number into a variable n.
Then display Insert Number 2: in the monitor and ask for number 2 for variable m. Then
perform addition, subtraction, multiplication, and division from the stored number of variable n
to the stored number of variable m and display the arithmetic results each time.
EXERCISE: 3
Write a program that takes three numbers 51, 72 and 90 from the keyboard, calculate and display
the according grades against these numbers (grading criteria, A is 90 to100, B is from 80 to 89
and C is from 70 to 79, bellow 70 is F), display the evaluation of these grading as A is Excellent
B is Very Good, C is Good and F is Better Try Next Time