0% found this document useful (0 votes)
4 views

CPPPT

Uploaded by

Æyan Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

CPPPT

Uploaded by

Æyan Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

MADHAV INSTITUTE OF TECHNOLOGY AND SCIENCE, GWALIOR

(A Govt. Aided UGC Autonomous Institute, Affiliated to RGPV, Bhopal)


NAAC Accredited with A++ Grade

A PRESENTATION
FOR
PROFICIENCY TEST
On
Computer Programming
Topic : Classes in C++

Branch: Internet of Things(IoT) I Year I Semester

Submitted By: Submitted To:


Ayan Ahmed Khan Prof. Sanjiv Sharma
(0901IO231011) Department of IT
Classes
What is Class?
Class in C++ is the building block that leads to Object-Oriented programming. It is a
user-defined data type, which holds its own data members and member functions, which
can be accessed and used by creating an instance of that class. A C++ class is like a
blueprint for an object. For Example: Consider the Class of Cars. There may be many
cars with different names and brands but all of them will share some common properties
like all of them will have 4 wheels, Speed Limit, Mileage range, etc. So here, Car is the
class, and wheels, speed limits, and mileage are their properties.
Defining Class
A class is defined in C++ using the keyword class followed
by the name of the class. The body of the class is defined
inside the curly brackets and terminated by a semicolon at the
end.
Examples of Classes
1.Class Definition (class Student):
#include <iostream> •The Student class is defined with two data members (id and name),
using namespace std; both declared as public.
•id is an integer, and name is a string
class Student {
public: 2.Data Members (int id and string name):
•These are instance variables or data members of the Student class. They
int id; //data member (also instance variable) represent properties or attributes of a student.
string name; //data member(also instance variable)
3.Object Creation (Student s1):
}; •In the main function, an object of the Student class is created named s1
int main() {
4.Setting Values (s1.id = 11 and s1.name = "Ayan Ahmed Khan"):
Student s1; //creating an object of Student •Values are assigned to the data members of the s1 object. The student
s1.id = 11; with ID 11 is given the name "Ayan Ahmed Khan.“
s1.name = “Ayan Ahmed Khan"; 5.Printing Values (cout << s1.id << endl and cout << s1.name << endl):
cout<<s1.id<<endl; •The program then prints the values of the id and name data members of
the s1 object.
cout<<s1.name<<endl;
return 0;
}
Difference Between class and Structure

Class Structure

1. Members of a class are private by default. 1. Members of a structure are public by default.

2. An instance of structure is called the ‘structure


2. An instance of a class is called an ‘object’.
variable’.

3. Member classes/structures of a class are private


3. Member classes/structures of a structure are
by default but not all programming languages have
public by default.
this default behavior eg Java etc.

4. It is declared using the class keyword. 4. It is declared using the struct keyword.

5. It is normally used for data abstraction and further


5. It is normally used for the grouping of data
inheritance.
References
• https://www.geeksforgeeks.org/structure-vs-class-in-cpp/
• https://www.remove.bg/upload
• https://chat.openai.com/c/7f2a580b-63c3-465b-b02e-7e69e51ff462
• https://www.javatpoint.com/cpp-object-and-class
• https://slidesgo.com/theme/brackets-lesson-for-coding-and-programming#position-3&related-1&rs=
detail-related
• https://www.simplilearn.com/tutorials/cpp-tutorial/classes-in-cpp
• https://www.geeksforgeeks.org/c-classes-and-objects/
Conclusion
In C++, classes are the building blocks of object-oriented programming (OOP),
encapsulating both data and functionality within a single entity. They facilitate code
organization and reuse through concepts like inheritance and polymorphism. Constructors
initialize object states, ensuring proper setup, while destructors handle resource cleanup
upon object destruction. Access modifiers control member visibility, safeguarding data and
implementation details. Member initialization lists enhance initialization efficiency. Static
members provide shared properties or methods for the entire class. Friend functions and
classes allow controlled access to private members, fostering flexibility in code design.
Overall, classes in C++ promote modularity, maintainability, and effective software
development practices.
Thank You!

You might also like