Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 02-03-2010
Member
 
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???
Reply With Quote
  #2  
Old 02-03-2010
Member
 
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;
Reply With Quote
  #3  
Old 02-03-2010
Member
 
Join Date: May 2008
Posts: 2,008
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!!!
Reply With Quote
  #4  
Old 02-03-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
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;
}
Reply With Quote
  #5  
Old 02-03-2010
Member
 
Join Date: May 2008
Posts: 2,293
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.
Reply With Quote
  #6  
Old 02-03-2010
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 08:39 PM.