Untitled

 avatar
unknown
plain_text
2 years ago
3.0 kB
2
Indexable
Q3) WHAT ARE THE SYNTAX FOR CLASS DECLERATION??


Here, inside the class, there are access-modifiers, data variables, and member functions. Now, understand them in detail.
Access modifiers: These are the specifiers which provide or grant access for the members. They are of three types:
Private: Only members of the same class have access to private members.
Public: You can access the public members from within, as well as from outside of the class.
Protected: You can access the protected members from the same class members and members of the derived class. It is also accessible from outside the class but with the help of the friend function.
Member-function: Member functions are standard functions declared inside a class. You can invoke it with the help of the dot operator and object.

SYNTAX::

class car
{
public:
  int a;
  void engine()
  {
  body
  }
};



Q1) WHAT ARE THE DIFFERENCE BETWEEN STRUCTURE AND THE CLASS IN C++??


In C++, a structure works the same way as a class, except for just two small differences. The most important of them is hiding implementation details. A structure will by default not hide its implementation details from whoever uses it in code, while a class by default hides all its implementation details and will therefore by default prevent the programmer from accessing them. The following table summarizes all of the fundamental differences.


                    Class                                                 Structure


1. Members of a class are private by default.	         1. Members of a structure are public by default. 
2. An instance of a class is called an ‘object’.	     2. An instance of structure is called the ‘structure variable’.
3. Member classes/structures of a class are private      3. Member classes/structures of a structure are public by default.
   by default but not all programming languages          4. It is declared using the struct keyword. 
   have this default behavior eg Java etc                5. It is normally used for the grouping of data
4. It is declared using the class keyword.	             6. NULL values are not possible.
5. It is normally used for data abstraction
   and further inheritance.
6. NULL values are possible in Class.	



Q2) IS IT POSSIBLE TO CREATE ARRAY OF OBJECTS FOR CLASS AS WELL???

Array of Objects in c++
Like array of other user-defined data types, an array of type class can also be created. The array of type class contains the objects of the class as its individual elements. Thus, an array of a class type is also known as an array of objects.


Q4) WRITE THE SYNTAX FOR ACCESSING THE CLASS MEMBERS IN C++??
 

C++ Access Data Members and Member Functions
We can access the data members and member functions of a class by using a . (dot) operator

FOR EXAMPLE::

room2.calculateArea();
This will call the calculateArea() function inside the Room class for object room2.

Similarly, the data members can be accessed as:

room1.length = 5.5;
In this case, it initializes the length variable of room1 to 5.5.