Skip to content

talha309/object-oriented-programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿง‘โ€๐Ÿ’ป Student Class (C++ Project) ๐Ÿ“˜ About This Project

This C++ program explains the basic concepts of Object-Oriented Programming (OOP). It uses a Student class to show how objects, encapsulation, and constructors work in a simple and easy way.

๐Ÿงฉ What is a Class?

A class is like a blueprint for creating objects. It defines what data (variables) and actions (functions) an object will have.

Example: If Student is a class, it can have data like name, degree, and CGPA, and functions like showDetails().

๐Ÿง  What is an Object?

An object is a real example (instance) of a class. If Student is a class, then student1 and student2 are two real students (objects).

Example in code:

Student student1; Student student2("Ali", "6032-ag-2024", "Software Engineering", 3.8);

๐Ÿ”’ What is Encapsulation?

Encapsulation means hiding important data from direct access and only allowing it through functions.

In this program:

Data like password is private โ†’ cannot be accessed directly.

Other data like name, degree, and CGPA are public โ†’ can be accessed easily.

Access Modifiers:

public: โ€” can be used anywhere in the program.

private: โ€” only used inside the class for security.

โš™๏ธ What are Constructors?

Constructors are special functions that run automatically when an object is created. They are used to set values when the object starts.

Types of Constructors:

Default Constructor Runs automatically and can print a message or set default values.

Student() { cout << "Student object created!" << endl; }

Parameterized Constructor Takes arguments (data) when creating an object and assigns them automatically.

Student(string n, string ag, string deg, float cg) { name = n; ag_number = ag; degree = deg; CGPA = cg; }

๐Ÿงพ Example Output Student object created! Enter Student Name: Ahmed Enter AG Number: 6032-ag-2024 Enter Degree: Software Engineering Enter CGPA: 3.5

Student Name: Ahmed AG Number: 6032-ag-2024 Degree: Software Engineering CGPA: 3.5 Password: abc123

๐Ÿ› ๏ธ How to Run g++ student_class_summary.cpp -o student ./student

๐Ÿ Summary

This program helps you understand:

What a class and object are

How encapsulation protects data

How constructors automatically set values when creating objects

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages