Addition to Classes in C++

sportsappsios musicappsios educationappsios
 31 December 18:00   

    

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;

    

char Color;

    

float ShoeSize;



    

A Chic Example



    



    

class ShoeBox

    

{

    

bifold Length, Width, Height;

    

burn Color[12];

    

float ShoeSize;

    

};The items that compose a chic are alleged associates of the class.

    



    

And the program that defines a shoe box item could be:



    

#include <iostream>

    

#include <iomanip>

    

#include <string>

    

using namespace std;

    

int main()

    

{

    

// 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 << "

";

    

return 0;

    

}



    

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)

 


Tags: create, program, class, classes, called, color, functions, float, members, characteristics

 object, length, class, height, width, color, called, characteristics, shoesize, program, create, functions, variables, float, double, members, classes, , < <, shoe box, cout <, float shoesize, double length, length width, width height, length width height, height char color, double length width, width height char,

Share Addition to Classes in C++: Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  C Plus Plus Programming Tutorials