cpp - lab manual 1 - basics of oop

Upload: shahazada-ali-imam

Post on 20-Feb-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/24/2019 CPP - Lab Manual 1 - Basics of OOP

    1/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 problemor 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. Forexample:

    High-level programming languages are languages whose syntax is relatively close to naturallanguage (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.

  • 7/24/2019 CPP - Lab Manual 1 - Basics of OOP

    2/4

    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 directmanipulation 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 creatingcopies 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 knowshow 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.

  • 7/24/2019 CPP - Lab Manual 1 - Basics of OOP

    3/4

    C++ PROGRAM STRUCTURE

    #include

    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 iostreamheader

    defines meaning for coutand cinin the std namespace).

    int main()

    main() is where program execution begins.

    {int year;

    cout > year

    cout

  • 7/24/2019 CPP - Lab Manual 1 - Basics of OOP

    4/4

    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 divisionfrom 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