Don’t watch the clock; do what it does. Keep going.
--Your friends at LectureNotes

Note for Object Oriented Programming Using Cpp - OOP By Aman Kumar

  • Object Oriented Programming Using Cpp - OOP
  • Note
  • Uploaded 2 months ago
Aman Kumar
Aman Kumar
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

Object oriented programming using C++ Class1: Introduction to c++: C++ is a statically typed, compiled, generalpurpose, case-sensitive, free-form programming language that supports procedural, object-oriented, and generic programming. C++ is regarded as a middle-level language, as it comprises a combination of both high-level and low-level language features. C++ was developed by Bjarne Stroustrup starting in 1979 at Bell Labs in Murray Hill, New Jersey, as an enhancement to the C language and originally named C with Classes but later it was renamed C++ in 1983. C++ is a superset of C, and that virtually any legal C program is a legal C++ program. Object-Oriented Programming C++ fully supports object-oriented programming, including the four pillars of object-oriented development: 1. Encapsulation 2. Data hiding 3. Inheritance 4. Polymorphism Let us now briefly look into what do class, object, methods and instant variables mean. Object - Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behaviors - wagging, barking,

Text from page-2

eating. An object is an instance of a class. Class - A class can be defined as a template/blueprint that describes the behaviors/states that object of its type support. Methods - A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed. Instant Variables - Each object has its unique set of instant variables. An object's state is created by the values assigned to these instant variables. C++ Program Structure: Let us look at a simple code that would print the words Hello World. #include <iostream> using namespace std; // main() is where program execution begins. int main() { cout << "Hello World"; // prints Hello World return 0; } Let us look various parts of the above program: The C++ language defines several headers, which contain information that is either necessary or useful to your program. For this program, the header <iostream> is needed.

Text from page-3

The line using namespace std; tells the compiler to use the std namespace. Namespaces are a relatively recent addition to C++. The next line // main() is where program execution begins. is a single-line comment available in C++. Single-line comments begin with // and stop at the end of the line. The line int main() is the main function where program execution begins. The next line cout << "This is my first C++ program."; causes the message "This is my first C++ program" to be displayed on the screen. The next line return 0; terminates main( )function and causes it to return the value 0 to the calling process. The Input / Output operator: C++ is able to input and output the built-in data types using the stream extraction operator >> and the stream insertion operator <<. The stream insertion and stream extraction operators also can be overloaded to perform input and output for user-defined types like an object. Character And String Literals: A character literal is composed of a constant character. It is represented by the character surrounded by single quotation marks. There are two kinds of character literals: Narrow-character literals of type char, for example 'a' Wide-character literals of type wchar_t, for example L'a' A string literal represents a sequence of characters that together

Text from page-4

form a null-terminated string. The characters must be enclosed between double quotation marks. There are the following kinds of string literals: Narrow string literals, represented as "xxx". Wide string literals, represented as L"xxx". Comments C++ supports single-line and multi-line comments. All characters available inside any comment are ignored by C++ compiler. C++ comments start with /* and end with */. For example: /* This is a comment */ /* C++ comments can also * span multiple lines */ A comment can also start with //, extending to the end of the line. For example: #include <iostream> using namespace std; main() { cout << "Hello World"; // prints Hello World return 0; }

Lecture Notes