structur.cpp 947 B

123456789101112131415161718192021222324252627282930313233343536
  1. // structur.cpp -- a simple structure
  2. #include <iostream>
  3. struct inflatable // structure declaration
  4. {
  5. char name[20];
  6. float volume;
  7. double price;
  8. };
  9. int main()
  10. {
  11. using namespace std;
  12. inflatable guest =
  13. {
  14. "Glorious Gloria", // name value
  15. 1.88, // volume value
  16. 29.99 // price value
  17. }; // guest is a structure variable of type inflatable
  18. // It's initialized to the indicated values
  19. inflatable pal =
  20. {
  21. "Audacious Arthur",
  22. 3.12,
  23. 32.99
  24. }; // pal is a second variable of type inflatable
  25. // NOTE: some implementations require using
  26. // static inflatable guest =
  27. cout << "Expand your guest list with " << guest.name;
  28. cout << " and " << pal.name << "!\n";
  29. // pal.name is the name member of the pal variable
  30. cout << "You can have both for $";
  31. cout << guest.price + pal.price << "!\n";
  32. // cin.get();
  33. return 0;
  34. }