Chapter – 5. CONSTRUCTORS & DESTRUCTORS

A function Assign() which calculate and the value of GPrice as follows. For the value of GFabric “COTTON” ,

GType GPrice(RS)
TROUSER 1300
SHIRT 1100

For GFabric other than “COTTON”, the above mentioned GPrice gets reduced by 10%

public members: A constructor to assign initial values of GCode,GType and GFabric with the a word “NOT ALLOTED”and Gsize and Gprice with 0.

A function Input ()to the values of the data membersGCode, GType,Gsize and GFabric and invoke the Assign() function.

A function Display () which displays the content of all the data members for a garment.

#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
class Garments
{
char GCode[21],GType[21];
int Gsize;
char Gfabric[21];
float Gprice;
void Assign( )
{
if(strcmp(strupr(Gfabric),"COTTON")==0)
{
if(strcmp(strupr(GType),"TROUSER")==0) Gprice=1300;
if(strcmp(strupr(GType),"SHIRT")==0) Gprice=1100;
}
else
{
if(strcmp(strupr(GType),"TROUSER")==0) Gprice=1300*0.90;
if(strcmp(strupr(GType),"SHIRT")==0) Gprice=1100*0.90;
}
}
public: Garments( )
{
strcpy(GCode,"NOT ALLOTED");
strcpy(GType,"NOT ALLOTED"); Gsize=0;
strcpy(Gfabric,"NOT ALLOTED"); Gprice=0;
}
void Input( )
{
cout<<"\nEnter the Grament Code: ";
gets(GCode);
cout<<"\nEnter the Garment Type: ";
gets(GType);
cout<<"\nEnter the Garment Size: ";
cin>>Gsize;
cout<<"\nEnter the Garment Fabric: ";
gets(Gfabric); Assign( );
}
void display( )
{
cout<<"\nThe Garment Code: "<<GCode;
cout<<"\nThe Garment Type: "<<GType;
cout<<"\nThe Garment Size: "<<Gsize;
cout<<"\nThe Garment Fabric: "<<Gfabric;
cout<<"\nThe Garment Price: "<<Gprice;
}
};
void main( )
{
Garments G;
G.Input( );
G.display( );
}