// OOP.Laba.1.cpp: определяет точку входа для консольного приложения. // #include "stdafx.h" #include using namespace std; class Device{ private: char name[15]; int length; int height; int width; int statePower; //1 - on; 0 - off int stateWorking;//1 - works fine; 0 - is broken int numberExtras; struct parts { char name[15]; int quantity; char dealer[15]; }; parts part[]; public: Device(){ cout << "CONSTRUCTOR W/O ARGs:\n"; cout << "Name: "; cin >> name; cout << "Length: "; cin >> length; cout << "Height: "; cin >> height; cout << "Width: "; cin >> width; cout << "Powered or not? (0/1): "; cin >> statePower; cout << "Does it work? (0/1): "; cin >> stateWorking; cout << "How many extra parts does it have? : "; cin >> numberExtras; parts* part = new parts[numberExtras]; for (int i(0); i < numberExtras; i++) { cout << i+1 << ".\n"; cout << "Name: "; cin >> part[i].name; cout << "Quantity: "; cin >> part[i].quantity; cout << "Dealer: "; cin >> part[i].dealer; } }; Device(char* n, int l, int h, int w, int sP, int sW, int num, char* pN, int pQ, char* pD) { strcpy(name, n); length = l; height = h; width = w; statePower = sP; stateWorking = sW; numberExtras = num; parts* part = new parts[numberExtras]; strcpy(part[0].name, pN); part[0].quantity = pQ; strcpy(part[0].dealer, pD); }; void showData(){ cout << "\nName: " << name; cout << "\nLength: " << length; cout << "\nHeight: " << height; cout << "\nWidth: " << width; if (statePower == 1) { cout << "\nPowered"; } else { cout << "\nNot powered"; }; if (stateWorking == 1) { cout << "\nWorks fine\n"; } else { cout << "\nIs broken :(\n"; }; cout << "Number of extras: " << numberExtras << endl; for (int i(0); i < numberExtras; i++) { cout << i + 1 << ".\n"; cout << "Name: " << part[i].name; cout << "\nQuantity: " << part[i].quantity; cout << "\nDealer: " << part[i].dealer << endl; } } ~Device(){ cout << "Destructed.\n"; }; }; int main() { Device device1; cout << "\nInfo for constructed W/O ARGs:\n"; device1.showData(); system("pause"); Device device2("Ruler", 200, 30, 20, 0, 1, 1, "grip", 1, "Hongjou inc."); cout << "\nInfo for constructed WITH ARGs:\n"; device2.showData(); system("pause"); return 0; }