+ 1

Could someone help me get the errors sorted out for the following program?

based on class and objects part of c++. default constructor is used. not able to get the desired output after typing in the required input :( https://code.sololearn.com/cewDotZRSSyo/?ref=app

11th Jul 2017, 3:44 PM
Rahul George
Rahul George - avatar
2 odpowiedzi
+ 7
// main must return int. // getch() is not needed in Code Playground // strcmp(), strcpy() functions require <cstring> // gets() is obsolete. Use cin, or getline. #include <iostream> #include <string> #include <cstring> using namespace std; class Outfit { private : char OCode[20] ,OType[25] ,OFabric[55]; int OSize; float OPrice; void InitPrice(); public : Outfit(); void Input(); void Display(); }; void Outfit::InitPrice() { if (strcmp(OFabric , "DENIM")==0) { if (strcmp(OType , " TROUSER")==0) OPrice = 1500; else OPrice = 2500; } else { if (strcmp (OType , "TROUSER")==0) OPrice = 1500 - 1500*0.25; else OPrice = 2500 - 2500*0.25; } } Outfit::Outfit() { strcpy(OCode , " NOT INITIALISED"); strcpy(OType , "NOT INITIALISED"); strcpy(OFabric , " NOT INITIALISED"); OSize = 0; OPrice = 0.0; } void Outfit:: Input() { cout <<"\n Enter Outfit Code: "; cin >> OCode; cout <<" \n Enter Outfit Type: "; cin >> OType; cout <<" \n Enter Outfit Fabric: "; cin >> OFabric; cout <<" \n Enter Outfit Size: "; cin>>OSize; InitPrice(); } void Outfit::Display() { cout <<" \n Outfit Code: "<<OCode; cout <<" \n Outfit Type: "<<OType; cout <<" \n Outfit Fabric: "<<OFabric; cout <<" \n Outfit Size: "<<OSize; cout <<" \n Gross Price: "<<OPrice; } int main() { Outfit O; O.Input(); O.Display(); return 0; }
11th Jul 2017, 3:52 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
thanks a lot @Hatsy. I'll check it out
18th Jul 2017, 2:19 AM
Rahul George
Rahul George - avatar