Find the best tutors and institutes for C++ Language

Find Best C++ Language Classes

Please select a Category.

Please select a Locality.

No matching category found.

No matching Locality found.

Outside India?

Search for topics

Creating a class in c++

Mahesh C
31/10/2018 0 0

Introduction

Before we proceed with understanding as to how to create a class in c++, we need to first understand the what is a class.

Definition : A class is a container of related data and methods (functions).

Example

StudentDetails Class
Data Members : StudentName , StudentAge ,  StudentAddress
Methods : GetStudentData , SetStudentData

The above example shows a simple example as how we can group details of the students and the methods that will be used to access them.

Syntax for creating a class:

class name 

{

        Access Modifier:

                             Data members;

       Access Modifier:

                            Methods;

};

Access Modifiers can be:

private  Visible only inside the class.
protected Visible inside the class as well as derived (inherited) class.
public  Visible to every one.

Note : Normally data members will be either private or protected and methods will be public.

Example:

class StudentDetails{

            private:

                  int studentAge;

                  char studentName[20];

                  char studentAddress[50];

            public :

                 void SetStudentData(){

                             //you can write the logic for setting the data

                 }; 

                void GetStudentData(){

                           //you can write the logic for displaying the student data

               }

};

                           

 

 

0 Dislike
Follow 1

Please Enter a comment

Submit

Other Lessons for You

Advantages of C++ Language
Advantages of C++ - C++ is a profoundly convenient dialect and is frequently the dialect of decision for multi-gadget, multi-stage application advancement. - C++ is a protest situated programming dialect...

Swapping Two Numbers
Q. Swap two numbers using the following function. Complete the function. You won't be allowed to use a temporary variable to swap the two numbers. void swap ( ... ) { /* Swap code goes here */ } ...

Pooja R. | 17/04/2018

0 0
0

Implicit Typecasting & Explicit Typecasting
In C++ it is possible to cast child class reference variable to parent class Reference. When ever we are Converting a derived-class reference or pointer to a base-class reference or pointer is called...

Md Ajmat | 02/08/2017

2 0
0

Importance Of Function Prototype In C
Function prototype tells compiler about number of parameters function takes, data-types of parameters and return type of function. By using this information, compiler cross checks function parameters and...

Sunil Yadav | 14/07/2017

0 0
0

Is It Fine To Write “void main()” Or “main()” In C/C++?
The definition: void main() { /* ... */ } Is not and never has been C++, nor has it even been C. See the ISO C++ standard 3.6.1 or the ISO C standard 5.1.2.2.1. A conforming...

Sunil Yadav | 13/07/2017

0 0
2

Looking for C++ Language Classes?

Find best C++ Language Classes in your locality on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
Sponsored

Find Best C++ Language Classes?

Find Now »

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 25 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 6.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more