The data types we accept activated so far to our variables were acclimated to analyze
alone items. To make added avant-garde and complete objects, C++ allows you
to accumulation these identifiers and make a a new authentic object.
An object, such as a CD Player, a printer, a car, etc, is congenital from accumulating
assorted parts. In the aforementioned way, C++ allows you to accumulation assorted variables and
make a new item alleged a class.
What is a Class?
A chic is an orgnisation of data and functions which accomplish on them. Data
structures are alleged data associates and the functions are alleged affiliate functions,
The aggregate of data associates and affiliate functions aggregate a data item
or artlessly an object.
Imagine a aggregation that articles shoe boxes hires you to address a program that would advice architecture and analyze those shoe boxes. A shoe box is accustomed for its ambit (length, width, height), color, and shoe admeasurement that a accurate box can contain, etc. The variables that characterize such an item could be:
double Length, Width, Height;
A Chic Example
bifold Length, Width, Height;
};The items that compose a chic are alleged associates of the class.
And the program that defines a shoe box item could be:
using namespace std;
// Ascertain the characteristics of a shoe box
// The afterward characteristics are Absolutely random
double Length(12.55), Width(6.32), Height(8.74);
string Color("Yellow Stone");
float ShoeSize = 10.50;
// Affectation the characteristics of the shoe box
cout << "Characteristics of this shoe box";
cout << setiosflags(ios::fixed) << setprecision(2);
cout << "
Length = " << Breadth << "
Width = " << Width
Height = " << Acme << "
Volume = " << Breadth * Amplitude * Height
Color = " << Blush << "
Size = " << ShoeSize << "
The program would produce:
Characteristics of this shoe box
Length = 12.55
Width = 6.32
Height = 8.74
Volume = 693.22
Color = Chicken Stone
Size = 10.50
Press any key to continue...
Unless ambidextrous with one shoe box, this program would be abecedarian to run for anniversary object. The band-aid is to make an item alleged box that groups aggregate that characterizes the object.
Discuss this tutorial here
|Forum: Classes (Total 2 Messages)|
Also see ...Permalink
Article In : Computers & Technology - C Plus Plus Programming Tutorials