Results 1 to 6 of 6

Thread: How to create the Classes in the C++

  1. #1
    Join Date
    Dec 2009
    Posts
    26

    How to create the Classes in the C++

    I am just started for learning the C++ programming. I have the good knowledge of the programming. I can also have the good programming logic. Generally, I can have the basic idea of the classes. But I can not know how the classes can be used in the C++ language. So, I want to know about How the classes can be created in the C++ language. Can anyone knows about the classes???

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Classes in the C++

    A class can be an extended concept of the structure of the data, in spite of holding data only. A class can hold both the methods and the data members. An object can be an instantiation of a class. An object could be the variable and class could be the type, In order of variables. The Classes can be declared basically with the class keyword. The classes can have the following format of declaration :
    Code:
    class classname 
    {
          member1;
          member2;
           ...
           ...
    } 
    object names;

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How to create the Classes in the C++

    The class can be the mechanism or type that can encapsulate or holds the data and the methods. A class can be defined by using the keyword class before the class name. A class can have the base classes and the members that can be private by default. The body of the class declaration can have the data members which can be either the function or the data declarations. I hope you should understands from the above explanation about the classes. Have a nice a Day!!!

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    A Classes : C++

    I think from the following code of lines you can easily came to know that how to create the class and how to implement the class in the C++ language :
    Code:
    #include <iostream>
    using namespace std;
    class CRectangle 
    {
    int p, q;
    public:
    void sval (int,int);
    int area ()
    {
    return (p*q);
    }
    };
    void DRectangle::sval(int i, int j) 
    {
      p = i;
      q = j;
    }
    int main () 
    {
      DRectangle rc;
      rc.stval (3,4);
      cout << "area: " << rc.area();
      return 0;
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How to create the Classes in the C++

    The default access for the members can be depends on the key of the class :
    1. By default the members of a union can be public. A union cannot be used as a parent class in a derivation.
    2. By default the members of a class can be declared with the word struct can be public. By default the structure can be inherited publicly.
    3. By default the members of a class can be declared with the word class can be private. By default a class can be inherited privately.

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to create the Classes in the C++

    The following program help's you to learn about how to implement the classes in the C++ language :
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
     class prsn
    {
    public:
      string nm;
      int ag;
    };
     int main ()
    {
      prsn p,q;
      p.nm = "Calvin";
      q.nm = "Hobbes";
      p.ag = 30;
      q.ag = 20;
      cout << p.name << ": " << p.age << endl;
      cout << q.name << ": " << q.age << endl;
      return 0;
    }
    output :
    Code:
    Calvin: 30
    Hobbes: 20

Similar Threads

  1. How to Create and use custom classes in VB 6.0?
    By Mr.ken in forum Software Development
    Replies: 4
    Last Post: 27-02-2010, 06:39 AM
  2. Use of abstract classes
    By ScarFace 01 in forum Software Development
    Replies: 5
    Last Post: 25-01-2010, 09:07 AM
  3. Sealed Classes in C#
    By Reegan in forum Software Development
    Replies: 5
    Last Post: 27-11-2009, 09:16 AM
  4. C # using classes in C + +
    By klite in forum Software Development
    Replies: 3
    Last Post: 01-10-2009, 10:15 AM
  5. Classes in VB.NET
    By Samir_1 in forum Software Development
    Replies: 2
    Last Post: 10-04-2009, 12:07 AM

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,714,065,495.80176 seconds with 16 queries