×
DONT COMPLAIN; JUST WORK HARDER
--Your friends at LectureNotes
Close

Object Oriented Programming Using Cpp

by Anna SuperkingsAnna Superkings
Type: NoteViews: 28Uploaded: 4 months ago

Share it with your friends

Suggested Materials

Leave your Comments

Contributors

Anna Superkings
Anna Superkings
Sri vidya College of Engineering & Technology, Virudhunagar Notes) Course Material(Lecture Overview of C++ Basic Introduction: C++ is derived from C Language. It is a Superset of C. Earlier C++ was known as C with classes. C++ was developed by Bjarne Stroustrup in the 1980 at Bell Labs. Most C Programs can be compiled in C++ compiler. C++ expressions are the same as C expressions. Structure of C++ Program: Layout of C++ Program Simple C++ Program Input Statement: Cin : Extracting Input from User Using Keyboard Syntax : cin >> variable; ( The operator >> called as extraction operator or get from operator) Example: 1 EC6301 & Object oriented programming and Data Structures Unit I Page 1
Sri vidya College of Engineering & Technology, Virudhunagar Notes) Course Material(Lecture int number1; int number2; cout<<"Enter First Number: "; cin>>number1; cout<<"Enter Second Number: "; cin>>number2; Example: 2 int a,b; cin >> a >> b; Output Statement: Cout: Display Output to User Using Screen(Monitor) Syntax : cout << variable; Example: 1 int tempNumber=6; cout << tempNumber; Example: 2 int a=10; int b=20; cout << a << b; Structures Definition: A Structure contains one or more data items of different type in which the individual elements can differ in type. Declaring a structure: The structure can be declared with the keyword struct following the name and opening brace with data elements of different type then closing brace with semicolon as below Syntax: struct structure_name EC6301 & Object oriented programming and Data Structures Unit I Page 2
Sri vidya College of Engineering & Technology, Virudhunagar Notes) Course Material(Lecture { structure_element 1; structure_element 2; ……… structure_element n; }; struct structure_name v1,v2,……..vn; Example: stuct book { char name[10]; float price; int pages; }; struct book b1,b2,b3; Accessing structure elements Members of structures are accessed using the member access operators – dot operator (.) and arrow operator(->) Example: stuct std { char name[10]; int no; int marks; }; struct std s; For accessing the structure member from the above example s.no; s.name; s.marks; Where s is the structure variable Example Program #include<iostream.h> #include<conio.h> Struct School { Int roll; Char name [25]; Char address [25]; Float weight; } stu; Void main () EC6301 & Object oriented programming and Data Structures Unit I Page 3
Sri vidya College of Engineering & Technology, Virudhunagar Notes) Course Material(Lecture { Cout<<”\n enter the roll no”; Cin>>stu.roll; Cout<<”\n enter name”; Cin>>stu.name; Cout<<”\n enter address”; Cin>>stu.address; Cout<<”\n ether weight”; Cin>>stu.weight; Cout<<”\n the student details are:”; Cout<<”\n Name :”<< stu.name; Cout<<”\n Roll no”<<stu.roll; Cout<<”\n address”<<stu.address; Cout<<”\n weight”<<stu.weight; getch (); } Class Definition A class is a user defined type or data structure declared with keyword class that has data and functions (also called methods) as its members whose access is governed by the three access specifiers private, protected or public (by default access to members of a class is private). Defining the Class class class_name { // some data // some functions EC6301 & Object oriented programming and Data Structures Unit I Page 4

Lecture Notes