Object-Oriented Programming in C++ (Level 2) PDF
Document Details
Tags
Summary
This document provides an introduction to object-oriented programming in C++. It defines programming languages, their usage, operating systems, and different types, including machine, assembly, and high-level languages. It explores the object-oriented approach in programming and details a basic C++ program example.
Full Transcript
Object-Oriented Programming in C++ ( level 2) Chapter 1 Introduction 1.1 Introduction to Programming Languages Programming Language is a language used to communicate with the computer by writing programs. Programming...
Object-Oriented Programming in C++ ( level 2) Chapter 1 Introduction 1.1 Introduction to Programming Languages Programming Language is a language used to communicate with the computer by writing programs. Programming language is widely used in the development of operating systems. An Operating System (OS) is a software (collection of programs) that controls the various functions of a computer. Also it makes other programs on your computer work. The instructions you write using a programming language are called program code; when you write instructions, you are coding the program. Every programming language has rules governing its word usage and punctuation. These rules are called the language’s syntax. Mistakes in a language’s usage are syntax errors. After a computer program is typed using programming language statements and stored in memory, it must be translated to machine language. Each programming language uses a piece of software, called a compiler or an interpreter, to translate your source code into machine language. Machine language is also called binary language, and is represented as a series of 0s and 1s. The compiler or interpreter that translates your code tells you if any programming language component has been used incorrectly. Syntax errors are relatively easy to locate and correct because your compiler or interpreter highlights them. After a program’s source code is successfully translated to machine language, the computer can carry out the program instructions. When instructions are carried out, a program runs, or executes. 1.2 Types of Programming Languages 1. Machine Language: Every computer has its own language called machine language. It depends on the specific Hardware of the computer. A machine language is also known as low level language. Computer understands & executes the program only in machine level language. This low level language is in the form of (1’s and 0’s) binary code. 2. Assembly Language: Assembly language is the mnemonic language written in some specific symbolic codes, such as ADD, SUB etc. An assembly language program is first translated into machine language instruction by system program called assembler, before it can be executed. 3. High Level Language: A High level lay program also needs to be transferred into machine language instructions before it can be executed because computer understands only machine level language. Rules for programming in a particular high-level language are much the same for all computers, so that a program written for one computer can generally be run on many different computers with little or no alteration. Some popular High Level languages are Basic, Fortran, Cobol, Pascal, C & C++. High-level language offers three significant advantages over machine language: simplicity, uniformity and portability (i.e., machine independence). 1.3 The Object-Oriented Approach The fundamental idea behind object-oriented languages is to combine into a single unit both data and the functions that operate on that data. Such a unit is called an object. An object’s functions, called member functions in C++, typically provide the only way to access its data. If you want to read a data item in an object, you call a member function in the object. It will access the data and return the value to you. You can’t access the data directly. Data and its functions are said to be encapsulated into a single entity. Data encapsulation and data hiding are key terms in the description of object-oriented languages. 1.4 Basic Program Construction Let’s look at a very simple C++ program. This program is called FIRST, so its source file is FIRST.CPP. It simply prints a sentence on the screen. Here it is: #include using namespace std; int main() { cout