specifying a class in C++

SPECIFING A CLASS in C++

A class is a way to bind the data and its associated functions together.. Class is a user defined data type, which holds its own data members and member functions.

It allows the data members(and functions) to be hidden, if necessary, from external uses. When we defining a class, we are creating a new abstract data type that can be treat like any other user define data type or built in data type. Basically a class specification has two parts.

1. class declaration
2. class function definitions

In the first part The class declaration describes the types and scope of its members. The class function definitions describe how the class functions are implemented.
The general form of a class declaration

class class_name
{
private :
variable declarations;
function declarations;
public :
variable declarations;
function declaration;
};

The class declaration is similar to a (structure) or struct declaration. The keyword class specifies, that what follows is an abstarct data of type class_name. The body of the class is enclosed within braces and terminated by a semicolon. The class body contains the declaration of functions and variables. These functions and variables are called class members, they are usually grouped under two sections, namely, private and public to denote which of the members are public and which of them are private . The keywords public and private are known as visibility labels.
Note that these keywords are followed by colon.

The class members that have been declared with private keyword can be accessed only from within the class. on the other hand, with public keyword members can be accessed from outside the class also the data hiding(using private declaration) is the key feature of OOPS. The use of the private keyword is optional by default the members of a class are private. if both the labels are missing, then by default all the members and functions are private. such a class is completely hidden from the outside scope student

The variable declared inside the class are known as data members and the functions are known as member functions. only the member functions can have access to the private data members and private functions. However public members(both functions and data members) can be accessed from outside the class.

Example of class ,class declaration would look like

class student
{
int fees; // variable declaration
int roll; // private by default
public:
void getdata(int f, int r); // functions declaration
void displayData();
// using prototype
};

we give class with meaningful name, such that student. This name now becomes a new type identifier that will be used to declare instances or create object of that class type. The class item contains two function members and two data members.
The data members are private by default while both the member functions are public by declaration. so The function getdata() can be used to assign values to the class members from outside the class.
This means that the data cannot be accessed by any function that is not a member of the class item.
Note that the functions are declared, not defined. Actual function definitions definitions will appear later in the program. The data members are usually declared as private and the member functions as public

Represent the class in the oops

class representation in c++ picture

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise