|
|
@@ -0,0 +1,36 @@
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
+using namespace std;
|
|
|
+
|
|
|
+// structure is a user defined data type
|
|
|
+// this is a buleprint, it does not contain any values
|
|
|
+struct SmartPhone
|
|
|
+{
|
|
|
+ string name = "iPhone 12";
|
|
|
+ int storageSpace = 256;
|
|
|
+ string color = "Space Grey";
|
|
|
+ float price;
|
|
|
+};
|
|
|
+
|
|
|
+int main()
|
|
|
+{
|
|
|
+ // If we want to define a phone
|
|
|
+ string name = "iPhone 12";
|
|
|
+ int storageSpace = 256;
|
|
|
+ string color = "Space Grey";
|
|
|
+ float price = 999.99;
|
|
|
+
|
|
|
+ // We must copy all the code to define second phone
|
|
|
+ string name2 = "Samsung S21 Ultra";
|
|
|
+ int storageSpace2 = 128;
|
|
|
+ string color2 = "Space Grey";
|
|
|
+ float price2 = 899.99;
|
|
|
+
|
|
|
+ SmartPhone Apple;
|
|
|
+ Apple.name = "iPhone12";
|
|
|
+ Apple.color = "Space Grey";
|
|
|
+ Apple.price = 999.99;
|
|
|
+ Apple.storageSpace = 512;
|
|
|
+
|
|
|
+ cout << Apple.name << endl;
|
|
|
+}
|