structures.cpp 801 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <iostream>
  2. using namespace std;
  3. // structure is a user defined data type
  4. // this is a buleprint, it does not contain any values
  5. struct SmartPhone
  6. {
  7. string name = "iPhone 12";
  8. int storageSpace = 256;
  9. string color = "Space Grey";
  10. float price;
  11. };
  12. int main()
  13. {
  14. // If we want to define a phone
  15. string name = "iPhone 12";
  16. int storageSpace = 256;
  17. string color = "Space Grey";
  18. float price = 999.99;
  19. // We must copy all the code to define second phone
  20. string name2 = "Samsung S21 Ultra";
  21. int storageSpace2 = 128;
  22. string color2 = "Space Grey";
  23. float price2 = 899.99;
  24. SmartPhone Apple;
  25. Apple.name = "iPhone12";
  26. Apple.color = "Space Grey";
  27. Apple.price = 999.99;
  28. Apple.storageSpace = 512;
  29. cout << Apple.name << endl;
  30. }