Results 1 to 4 of 4

Thread: What is the general structure of class in C++?

  1. #1
    Join Date
    Dec 2010
    Posts
    16

    What is the general structure of class in C++?

    Hello Guys, I want to know what the general structure of class in C++ is. I very much keen to know what it is all about. Is it bit difficult to understand or what? One of my friends was saying that it is very difficult to understand. But, as per my knowledge I don’t think it is difficult. The basic topics are quite easy to understand. I hope that further topics must be also easy. If anybody having any knowledge then please let me know.

  2. #2
    Join Date
    May 2009
    Posts
    539

    Re: What is the general structure of class in C++?

    A class is a new data type that contains data and function. Collectively these are known as member of the function. Data are known as data member and functions are known as function member. The function defines the set of operation that can be performed on the data members of the class. This property of C++ which allows association of data and function into a single unit is called encapsulation.

  3. #3
    Join Date
    May 2009
    Posts
    511

    Re: What is the general structure of class in C++?

    Code:
        The General Form of class is as follows.
    
    class classname
    {
    access specifier     Data type variabl_1;
    access specifier     Data type variabl_2;
    ……
    access specifier     Data type variabl_n;
    
    access specifier     Return type function_1(argument list);
    access specifier     Return type function_2(argument list)
    …….
    access specifier     Return type function_n(argument list)
    
    };
    The class is a reserve keyword.The classname is the name of the class.variable_1 through variable_n are the variables of the class and function_1 through function_n are the functions of the class.The body of the class is enclosed within the curly braces followed by semicolon.

    The variable and function of the class has to be declared with one of the access specifier. C++ has three access specifier public ,private , protected.

  4. #4
    Join Date
    May 2009
    Posts
    527

    Re: What is the general structure of class in C++?

    Code:
     For example
    class Box
    {
       int l,h,w;
    
    public :
    
    void get_data()
    {
    cout<<”enter the length width and height of box”;
    cin>>l>>h>>w;
    }
    
    void display()
    {
    cout<<”the length of box is<<l;
    cout<<”the height of box is<<h;
    cout<<”the width of box is<<w; 
    }
    };

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. Replies: 5
    Last Post: 12-02-2010, 06:23 PM
  3. Replies: 3
    Last Post: 11-09-2009, 09:59 AM
  4. Ultra solid drives:Imation M-Class and S-Class
    By Regina in forum Portable Devices
    Replies: 1
    Last Post: 03-04-2009, 10:34 AM
  5. Good news for CBSE CLASS X & CLASS IX - visit learnnext
    By surya_expert in forum Education Career and Job Discussions
    Replies: 0
    Last Post: 13-12-2008, 12:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,969,268.28953 seconds with 17 queries