| 1. |
Define a class Clothing in C++ with the following descriptions: Private Members:Code of type stringTypeof type stringSizeof type integerMaterialof type stringPriceof type floatA function Calc_Price() which calculates and assign the values of GPrice as follows: For the value of Material as "COTTON":Type Price(Rs)TROUSER 1500SHIRT 1200For Material other than "COTTON" the above mentioned Price gets reduced by 25%. Public Members:A constructor to assign initial values of Code, Type and Material with word "NOT ASSIGNED" and Price with 0. A function Enter() to input the values of the data members Code, Type, Size and Material and invoke the Calc_Price() function.A function Show() to display the content of all the data members for a Clothing. |
|
Answer» class Clothing { char Code[15]; char Type[15]; int Size; char Meterial[15]; float Price; void Cal_Price() { if(strcmp(Material,"COTTON")==0) { if(strcmp(Type,"TROUSER")==0) Price=1500; else if(strcmp(Type,"SHIRT")==0) Price=1200; } else { if(strcmp(Type,"TROUSER")==0) Price=1500-1500*0.25; else if(strcmp(Type,"SHIRT")==0) Price=1200-1200*0.25; } } public: Clothing() { strcpy(Code,"NOT ASSIGNED"); strcpy(Type,"NOT ASSIGNED"); strcpy(Material,"NOT ASSIGNED"); Size=0; Price=0; } void Enter() { cout<"Enter code"; gets(Code); cout<<"\nEnter type:"; gets(Type); cout<<"\nEnter Size:"; cin>>Size; cout<<"\nEnter Material"; gets(Material); cout<<"\nEnter Price:"; cin>>Price; Calc_Price(); } void Show() { cout<<"\nCode:"<<Code<<end1; cout<<"\nType:"<<Type<<end1; cout<<"\nSize:"<<Size<<end1; cout<<"\nMaterial:"<<Material<<end1; cout<<"\nPrice:"<<Price<<end1; } |
|