#include "iostream"
class rectangle { // A simple class
int height;
int width;
public:
rectangle(void); // with a constuctor,
int area(void); // two methods,
void initialize(int, int);
~rectangle(void); // and a destructor
};
rectangle::rectangle(void) // constuctor
{
height = 6;
width = 6;
}
int rectangle::area(void) //Area of a rectangle
{
return height * width;
}
void rectangle::initialize(int init_height, int init_width)
{
height = init_height;
width = init_width;
}
rectangle::~rectangle(void) // destructor
{
height = 0;
width = 0;
}
struct pole {
int length;
int depth;
};
main()
{
rectangle box, square;
pole flag_pole;
cout << "The area of the box is " <<
box.area() << "\n";
cout << "The area of the square is " <<
square.area() << "\n";
// box.height = 12;
// box.width = 10;
// square.height = square.width = 8;
box.initialize(12, 10);
square.initialize(8, 8);
flag_pole.length = 50;
flag_pole.depth = 6;
cout << "The area of the box is " <<
box.area() << "\n";
cout << "The area of the square is " <<
square.area() << "\n";
// cout << "The funny area is " <<
// area(square.height, box.width) << "\n";
// cout << "The bad area is " <<
// area(square.height, flag_pole.depth) << "\n";
}
// Result of execution
//
// The area of the box is 36
// The area of the square is 36
// The area of the box is 120
// The area of the square is 64
Subscribe dengan Rohaza Dollah dot com untuk mendapat tipstips/produk/idea terkini tentang pernigaaan internet.
Subscribe melalui Email
Subscribe melalui Email
ATAU
Categories
- Affiliate Program (1)
- Ainul Mardhiah (1)
- Articles (1)
- Audio Book (1)
- birthday (1)
- Business (5)
- Cerekarama Online (1)
- Computer Ethic (1)
- Diariku (13)
- dns (1)
- domain (1)
- final countdown (1)
- Health (1)
- Isu Semasa (2)
- Java (2)
- Jokes (2)
- Make Money Online (3)
- Million Challenge (1)
- Motivation (3)
- Pengaturcaraan C++ (10)
- penyakit rohani (1)
- Petua Hebat Blogging (5)
- Politik (1)
- Russell Brunson (1)
- server (1)
- web hosting (1)
- Worth Reading (1)
April 22, 2008
Contoh Aturcara C++ -Constructor & Destructor
Labels: Pengaturcaraan C++
Subscribe to:
Post Comments (Atom)
Work at Home, Stay at Home
Download PERCUMA
Dapatkan secara percuma beberapa material yang boleh dimuat turun secara PERCUMA.
Pengiklanan Berkesan
Online Success Plan
.....dan banyak lagi akan ditambah dari masa ke semasa.
Pengiklanan Berkesan
Online Success Plan
.....dan banyak lagi akan ditambah dari masa ke semasa.
0 comments:
Post a Comment