SlideShare a Scribd company logo
1 of 33
Concepts and Basics of C++
Programming
CSE 202
Object-Orientation
• A thinking methodology
– Everything is an object.
– Any system is composed of objects (a system is
also an object).
– The evolution and development of a system is
caused by the interactions of the objects
inside/outside a system.
Everything is an object
• A student, a professor
• A desk, a chair, a classroom, a building
• A university, a city, a country
• The world, the universe
• A subject such as CS, IS, Math, History, …
The development of a system is caused by
interactions
• LPU is defined by the interactions among:
– students
– professors
– staff
– Board governance
– State governance
– … ...
Inside LPU
Outside LPU
Reading and Writing Data
Reading and Writing Data
• Two operators are introduced in c++ i.e. cout and cin.
• Cout is a predefined object and represents the standard
output stream and this output stream represents the screen.
Cout, equires iostream file
E.g. cout<<“ I love india”;
cout will display this string as such on screen.
• << is called insertion or put to operator.
• It is also called bit-wise left -shift operator
• if string is variable then cout can be used to
display the contents of string.
E.g. cout<< string;
• cin is used to read the data.
• cin>>a;
• >> is called extraction operator.
The cout Object
• Displays output on the computer screen
• You use the stream insertion operator << to
send output to cout:
cout << "Programming is fun!";
The cout Object
• Can be used to send more than one item to
cout:
cout << "Hello " << "there!";
Or:
cout << "Hello ";
cout << "there!";
The cout Object
• This produces one line of output:
cout << "Programming is ";
cout << "fun!";
The cin Object
• Standard input object
• Like cout, requires iostream file
• Used to read input from keyboard
• Information retrieved from cin with >>
• Input is stored in one or more variables
The cin Object
• cin converts data to the type that matches the
variable:
int height;
cout << "How tall is the room? ";
cin >> height;
The cin Object
• Can be used to input more than one value:
cin >> height >> width;
• Multiple values from keyboard must be separated by
spaces
• Order is important: first value entered goes to first
variable, etc.
Reading Strings with cin
• Can be used to read in a string
• Must first declare an array to hold characters in
string:
char myName[21];
• nyName is name of array, 21 is the number of
characters that can be stored (the size of the array),
including the NULL character at the end
• Can be used with cin to assign a value:
cin >> myName;
Class
• A class is a user define data type which holds
both data and function.
• The data included in the class i.e the internal
data is called data member and the functions
included is called the member function.
• These member functions can manipulate the
internal data of the class
Object
• Is an instant of a class.
• In terms of variables, class would be the type
and an object would be a variable.
Creating Classes in C++
• A class definition begins with the keyword
class.
• The body of the class is contained within a set
of braces, { } ; (notice the semi-colon).
class class_name
{
….
….
….
};
Class body (data member +
methodsmethods)
Any valid
identifier
class classname
{
private:
variable declarations;
function declarations;
public:
variable declarations;
function declarations;
protected:
variable declarations;
function declarations;
} obj1, obj2,…..objN;
Class name
• Name given to a particular class (any user
define name). It can also be called as tag name
of the class that act as the type specifier for
class using which we can create objects.
• The class is specified by keyword “class”
Data Members
• Data type properties that describe the
characteristics of a class.
• We can declare any number of data members
of any type in a class.
E.g. int x;
Member functions
• Various operations that can be performed to
data members of that class.
• We can declare any number of member
functions of any type in a class.
E.g. void read();
Access Specifiers
• Used to specify access rights for the data
members and member functions of the class.
• Depending upon the access level of a class
member, access to it is allowed or denied.
• Within the body, the keywords private: and
public: specify the access level of the members of
the class.
– the default is private.
• Usually, the data members of a class are declared
in the private: section of the class and the member
functions are in public: section.
class class_name
{
private:
…
…
…
public:
…
…
…
};
Public members or methods
private members or methods
Private:
only members of that class have accessibility
 can be accessed only through member
functions of that class i.e by the functions
declared inside the class only.
Private members and methods are for internal
use only.
Public:
• Accessible from both inside and outside the class also i.e
by the functions declared in the main() program also.
Protected:
• Stage between private and public access.
• They can be accessed by the member function or friend
functions of the class. They are similar to private
members in the sense that they cannot be accessed by the
non- member functions of the class.
Class Example
• This class example shows how we can
encapsulate (gather) a circle information into
one package (unit or class)
class Circle
{
private:
double radius;
public:
void setRadius(double r); double
getDiameter();
double getArea();
double getCircumference();
};
No need for others classes to access
and retrieve its value directly. The
class methods are responsible for
that only.
They are accessible from outside
the class, and they can access the
member (radius)
Methods definition
• The member function of the class can be defined in two
different ways:
1) Inside the class definition:- The member functions are simple
defined inside the class only i.e the body of the function
resides inside the range of class only.
2) Outside the class definition: by using scope resolution
operator, which specifies that the scope of the function is
restricted to the class class_name.
Syntax:- class_name:: function_name
Inside the class definition
Eg: class abc
{
private:
int rollno;
char name[20];
public:
void getdata()
{
cout<<“name=“;
cin>>name;
cout<<“rollno=“;
cin>>rollno;
}
void display()
{
cout<<“name=“<<name;
cout<<“rollno=“<<rollno;
}
};
Outside the class definition
Eg: class abc
{
private:
int rollno;
char name[20];
public:
void getdata();
void display();
};
void abc :: getdata()
{
cout<<“name=“;
cin>>name;
cout<<“rollno=“;
cin>>rollno;
}
void abc :: display()
{
cout<<“name and rollno=“;
cout<<name<<rollno;
}
INLINE AND NON INLINE MEMBER
FUNCTION
• A function defined inside the class is by
default inline function
• A function defined outside the class using
scope resolution operation is non-inline
function. It can be made inline by using
keyword inline before the function definition.
Eg. inline void abc::getdata()
Declaring objects
• Defining objects of class data type is known as
class instantiation(instances of class).
• When we create objects during that moment ,
memory is allocated to them.
Ex- class Circle c;
class book
{
private:
int p; char n[40];
public:
void getdata()
{
cout<<“enter book price”;
cin>>p;
cout<<“enter book name”;
cin>>n; }
void display(); };
void book ::display()
{
cout<<“book name=“<<n;
cout<<“book price=“<<p;
}
void main()
{
class book obj;
obj.getdata();
obj.display();
}
Accessing class members
• Public members of class can be accessed using
dot(.) operator with the object name.
• Private members of the class are accessed
inside the public member functions of class.
Eg: obj.getdata();

More Related Content

What's hot

Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan collegeahmed hmed
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functionsHarsh Patel
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++Muhammad Waqas
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++Jeff TUYISHIME
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introductionSohanur63
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3Atif Khan
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++rprajat007
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in javaAtul Sehdev
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and objectFajar Baskoro
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCEVenugopalavarma Raja
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functionsMarlom46
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#Adeel Rasheed
 

What's hot (17)

Classes cpp intro thomson bayan college
Classes cpp  intro thomson bayan collegeClasses cpp  intro thomson bayan college
Classes cpp intro thomson bayan college
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Ch03
Ch03Ch03
Ch03
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
oop lecture 3
oop lecture 3oop lecture 3
oop lecture 3
 
27csharp
27csharp27csharp
27csharp
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects[OOP - Lec 06] Classes and Objects
[OOP - Lec 06] Classes and Objects
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
 
Object and class
Object and classObject and class
Object and class
 
[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member
 

Viewers also liked (20)

c++ introduction
c++ introductionc++ introduction
c++ introduction
 
gio's tesi
gio's tesigio's tesi
gio's tesi
 
John D McMillion Resume
John D McMillion Resume John D McMillion Resume
John D McMillion Resume
 
Exam tips
Exam tipsExam tips
Exam tips
 
Forms of energy
Forms of energyForms of energy
Forms of energy
 
Eclipse
EclipseEclipse
Eclipse
 
Admission of partner
Admission of partnerAdmission of partner
Admission of partner
 
Mahesh CV updated 30th Sep 2015
Mahesh CV updated 30th Sep 2015Mahesh CV updated 30th Sep 2015
Mahesh CV updated 30th Sep 2015
 
3. Ingeniería Biomédica - Web 2.0
3. Ingeniería Biomédica - Web 2.03. Ingeniería Biomédica - Web 2.0
3. Ingeniería Biomédica - Web 2.0
 
Paulz0
Paulz0Paulz0
Paulz0
 
Levels of court
Levels of courtLevels of court
Levels of court
 
Presentacion
PresentacionPresentacion
Presentacion
 
2. Ingeniería Biomédica - Accesibilidad
2. Ingeniería Biomédica - Accesibilidad2. Ingeniería Biomédica - Accesibilidad
2. Ingeniería Biomédica - Accesibilidad
 
5. informática en salud informática del consumidor
5. informática en salud   informática del consumidor5. informática en salud   informática del consumidor
5. informática en salud informática del consumidor
 
Dhcp
DhcpDhcp
Dhcp
 
Práctica 6. ubuntu en server
Práctica 6. ubuntu en serverPráctica 6. ubuntu en server
Práctica 6. ubuntu en server
 
Práctica 5
Práctica 5Práctica 5
Práctica 5
 
Práctica 7 b
Práctica 7 bPráctica 7 b
Práctica 7 b
 
Social networks
Social networks Social networks
Social networks
 
2. informática en salud historia clínica electrónica
2. informática en salud   historia clínica electrónica2. informática en salud   historia clínica electrónica
2. informática en salud historia clínica electrónica
 

Similar to c++ lecture 1

Classes and objects
Classes and objectsClasses and objects
Classes and objectsAnil Kumar
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptmanomkpsg
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Abdullah Jan
 
C++ training
C++ training C++ training
C++ training PL Sharma
 
C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectC++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectsecondakay
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming LanguageSteve Johnson
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++jehan1987
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfstudy material
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Getachew Ganfur
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methodsfarhan amjad
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Enam Khan
 

Similar to c++ lecture 1 (20)

Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
 
classandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.pptclassandobjectunit2-150824133722-lva1-app6891.ppt
classandobjectunit2-150824133722-lva1-app6891.ppt
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 
Classes
ClassesClasses
Classes
 
C++ training
C++ training C++ training
C++ training
 
C++ppt. Classs and object, class and object
C++ppt. Classs and object, class and objectC++ppt. Classs and object, class and object
C++ppt. Classs and object, class and object
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
Object oriented programming in C++
Object oriented programming in C++Object oriented programming in C++
Object oriented programming in C++
 
Class and objects
Class and objectsClass and objects
Class and objects
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
 
Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02Ccourse 140618093931-phpapp02
Ccourse 140618093931-phpapp02
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Class and object
Class and objectClass and object
Class and object
 
Java2
Java2Java2
Java2
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
 
Classes, objects and methods
Classes, objects and methodsClasses, objects and methods
Classes, objects and methods
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
 

Recently uploaded

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Recently uploaded (20)

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

c++ lecture 1

  • 1. Concepts and Basics of C++ Programming CSE 202
  • 2. Object-Orientation • A thinking methodology – Everything is an object. – Any system is composed of objects (a system is also an object). – The evolution and development of a system is caused by the interactions of the objects inside/outside a system.
  • 3. Everything is an object • A student, a professor • A desk, a chair, a classroom, a building • A university, a city, a country • The world, the universe • A subject such as CS, IS, Math, History, …
  • 4. The development of a system is caused by interactions • LPU is defined by the interactions among: – students – professors – staff – Board governance – State governance – … ... Inside LPU Outside LPU
  • 6. Reading and Writing Data • Two operators are introduced in c++ i.e. cout and cin. • Cout is a predefined object and represents the standard output stream and this output stream represents the screen. Cout, equires iostream file E.g. cout<<“ I love india”; cout will display this string as such on screen.
  • 7. • << is called insertion or put to operator. • It is also called bit-wise left -shift operator • if string is variable then cout can be used to display the contents of string. E.g. cout<< string; • cin is used to read the data. • cin>>a; • >> is called extraction operator.
  • 8. The cout Object • Displays output on the computer screen • You use the stream insertion operator << to send output to cout: cout << "Programming is fun!";
  • 9. The cout Object • Can be used to send more than one item to cout: cout << "Hello " << "there!"; Or: cout << "Hello "; cout << "there!";
  • 10. The cout Object • This produces one line of output: cout << "Programming is "; cout << "fun!";
  • 11. The cin Object • Standard input object • Like cout, requires iostream file • Used to read input from keyboard • Information retrieved from cin with >> • Input is stored in one or more variables
  • 12. The cin Object • cin converts data to the type that matches the variable: int height; cout << "How tall is the room? "; cin >> height;
  • 13. The cin Object • Can be used to input more than one value: cin >> height >> width; • Multiple values from keyboard must be separated by spaces • Order is important: first value entered goes to first variable, etc.
  • 14. Reading Strings with cin • Can be used to read in a string • Must first declare an array to hold characters in string: char myName[21]; • nyName is name of array, 21 is the number of characters that can be stored (the size of the array), including the NULL character at the end • Can be used with cin to assign a value: cin >> myName;
  • 15. Class • A class is a user define data type which holds both data and function. • The data included in the class i.e the internal data is called data member and the functions included is called the member function. • These member functions can manipulate the internal data of the class
  • 16. Object • Is an instant of a class. • In terms of variables, class would be the type and an object would be a variable.
  • 17. Creating Classes in C++ • A class definition begins with the keyword class. • The body of the class is contained within a set of braces, { } ; (notice the semi-colon). class class_name { …. …. …. }; Class body (data member + methodsmethods) Any valid identifier
  • 18. class classname { private: variable declarations; function declarations; public: variable declarations; function declarations; protected: variable declarations; function declarations; } obj1, obj2,…..objN;
  • 19. Class name • Name given to a particular class (any user define name). It can also be called as tag name of the class that act as the type specifier for class using which we can create objects. • The class is specified by keyword “class”
  • 20. Data Members • Data type properties that describe the characteristics of a class. • We can declare any number of data members of any type in a class. E.g. int x;
  • 21. Member functions • Various operations that can be performed to data members of that class. • We can declare any number of member functions of any type in a class. E.g. void read();
  • 22. Access Specifiers • Used to specify access rights for the data members and member functions of the class. • Depending upon the access level of a class member, access to it is allowed or denied. • Within the body, the keywords private: and public: specify the access level of the members of the class. – the default is private. • Usually, the data members of a class are declared in the private: section of the class and the member functions are in public: section.
  • 24. Private: only members of that class have accessibility  can be accessed only through member functions of that class i.e by the functions declared inside the class only. Private members and methods are for internal use only.
  • 25. Public: • Accessible from both inside and outside the class also i.e by the functions declared in the main() program also. Protected: • Stage between private and public access. • They can be accessed by the member function or friend functions of the class. They are similar to private members in the sense that they cannot be accessed by the non- member functions of the class.
  • 26. Class Example • This class example shows how we can encapsulate (gather) a circle information into one package (unit or class) class Circle { private: double radius; public: void setRadius(double r); double getDiameter(); double getArea(); double getCircumference(); }; No need for others classes to access and retrieve its value directly. The class methods are responsible for that only. They are accessible from outside the class, and they can access the member (radius)
  • 27. Methods definition • The member function of the class can be defined in two different ways: 1) Inside the class definition:- The member functions are simple defined inside the class only i.e the body of the function resides inside the range of class only. 2) Outside the class definition: by using scope resolution operator, which specifies that the scope of the function is restricted to the class class_name. Syntax:- class_name:: function_name
  • 28. Inside the class definition Eg: class abc { private: int rollno; char name[20]; public: void getdata() { cout<<“name=“; cin>>name; cout<<“rollno=“; cin>>rollno; } void display() { cout<<“name=“<<name; cout<<“rollno=“<<rollno; } };
  • 29. Outside the class definition Eg: class abc { private: int rollno; char name[20]; public: void getdata(); void display(); }; void abc :: getdata() { cout<<“name=“; cin>>name; cout<<“rollno=“; cin>>rollno; } void abc :: display() { cout<<“name and rollno=“; cout<<name<<rollno; }
  • 30. INLINE AND NON INLINE MEMBER FUNCTION • A function defined inside the class is by default inline function • A function defined outside the class using scope resolution operation is non-inline function. It can be made inline by using keyword inline before the function definition. Eg. inline void abc::getdata()
  • 31. Declaring objects • Defining objects of class data type is known as class instantiation(instances of class). • When we create objects during that moment , memory is allocated to them. Ex- class Circle c;
  • 32. class book { private: int p; char n[40]; public: void getdata() { cout<<“enter book price”; cin>>p; cout<<“enter book name”; cin>>n; } void display(); }; void book ::display() { cout<<“book name=“<<n; cout<<“book price=“<<p; } void main() { class book obj; obj.getdata(); obj.display(); }
  • 33. Accessing class members • Public members of class can be accessed using dot(.) operator with the object name. • Private members of the class are accessed inside the public member functions of class. Eg: obj.getdata();