answersLogoWhite

0


Best Answer

#include <iostream>

class foo{}; // Minimal class declaration.

int main()

{

foo a; // Instantiate an object of the class.

foo b(a); // Instantiate a copy of the class.

return(0);

// Both objects fall from scope at this point.

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

header "c.h" class C { private: /* default visibility*/ int field; // hidden from other classes and functions public: /* visible interface */ C(); // default constructor C(const C&) // copy constructor virtual ~C(); // destructor, needs to be virtual to not break destruction process in an inheritance hierarchy int getField() const; // access to private member void setField(int ); }; "c.cpp" /* Initialize field to 0 */ C:C():field(0){} C:C(const C& source):field(source.field){} ~C(){} int getField() const { return field; } void setField(int newVaule){ field = newValue; ) Usage in "main.cpp": #include "c.h" main(){ C object; // default constructor object.setField( 4 ); int i = object.getField(); // i has the value 4; }

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

A class is a data structure that is used to model real world things. Classes are generally very broad and have two things: member functions and member data. Think of the member functions as the "verbs" of the class and the member data as the "nouns" of the class. The verbs act on the nouns to do something, much how a verb describes what a noun is doing in a sentence.

Now, let's say I have a class called Student. Let's be basic here and say that the class Student has a member function called getGPA() and a member variable called GPA.

An example would look like this:

class Student

{

public:

int getGPA();

int GPA;

};

This class represents a very basic Student. It has a variable called GPA that tells what the Student's GPA is and a function to retrieve that data. In order to access a data member of a class, you need an object. An object is just an instance of a class. Think of it like this. I have a class called Dog. Dog is a class. Now I have an instance of the class Dog called German Shepherd. A German Shepherd is a type of dog but a dog doesn't necessarily have to be a German Shepherd.

You can keep adding more stuff to the class Student to describe it even more, such as a variable called int ID and a function called getID() to define and retrieve the Student's ID number.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

#include<iostream>

struct A {

int m_data;

~A() {}

A(const int i): m_data(i) {}

A(const A& a): m_data(a.m_data) {}

A& operator=(const A& a) { m_data=a.m_data; return(*this); }

};

struct B : public A {

~B() {}

B(const int i, const int j): A(i), m_data(j) {}

B(const B& b): A(b), m_data(b.m_data) {}

B& operator=(const B& b) { A::operator=(b); m_data=b.m_data; return(*this); }

};

int main()

{

B b(42, 0);

A a(b);

std::cout<<a.m_data<<std::endl;

}

Output:

42

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

C Plus Plus (C++) is a programming language.

If you meant to ask about IDEs (Integrated Development Environments - these allow you to code easier, i.e. without having to use terminal or shell), there are many available for use.

Here are a few I've previously used:

  • Dev-cpp (bloodshed.net)
  • Eclipse C/C++ (there is a Java version of this IDE also)
  • Visual Studio 2010 (this I am told, is the industry standard software for games programming in C++)
This answer is:
User Avatar

User Avatar

Wiki User

10y ago

#include<iostream>

int main()

{

std::cout<<"Hello world!"<<std::endl;

return(0);

}

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

rt s ysyh dfhadklfg adn;an klgsdnfg nsdflkghsdf; fgh

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Sample of c plus plus program using a class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Program to generate Fibonacci series using storage class in c plus plus?

i dn't know. haha


Write c plus plus program for new and delete operator using class?

#include&lt;iostream&gt; class foo{ int m_data; }; int main() { foo* p=new foo; delete( foo), foo=NULL; return(0); }


C plus plus program using a stacks converting a postfix-infix?

Yes


Can you use c in c plus plus without using class and object?

Sure.


Explain instantiation of objects in c plus plus?

Instantiation of a class literally means creating an instance of a class. This is the process of allocating memory for an object that you can use in your program.


Sample program of c plus plus by using an algorithm union?

The union of two data sequences is the combined set of both sequences. To create a union, copy the first data sequence then append the second to the copy. Both sequences must be of the same type.


Program to get a system time using c plus plus?

time in hours second minute


A class in a program whose objects are created and destroyed throughout the program It is desired that the total number of live objects in the program be known how you do this in C plus plus?

Create a static member variable to contain the count. This variable is common to all instances of the class.Initialize that variable to zero at the beginning of the program.In the class constructor, increment the variable.In the class destructor, decrement the variable.


What is the program to create a string class which stores a string value in c plus plus?

C++ already provides a string class in the C++ standard template library. #include&lt;iostream&gt; #include&lt;string&gt; int main() { using namespace std; string s {"Hello world!"}; cout &lt;&lt; s &lt;&lt; endl; }


How do you write a program in C plus plus plus plus How do you write a program in C to swap two variables without using the third oneo swap two variables without using the third one?

To swap two variables without using a third variable, use exclusive or manipulation... a ^= b; b ^= a; a ^= b;


Can somebody give me the program to find simple interest using friend function in c plus plus?

Here is an example program: class obj{ public: float p,n,r,si; friend void calc( obj temp); }; void calc( obj temp){ si = (p*n*r)/100; } The initialization and function calling is essential.


How do you write a C plus plus program that displays a pyramid of Xes on the screen using a for loop?

printf ("x")