fork download
  1. // Attached: Lab_9
  2. // ===========================================================
  3. // File: Lab9_Combined.cpp
  4. // ===========================================================
  5. // Programmer: Elaine Torrez
  6. // Class: CMPR 121
  7. // ===========================================================
  8.  
  9. #include <iostream>
  10. #include <string>
  11. using namespace std;
  12.  
  13. // ===========================================================
  14. // Abstract Base Class: Art
  15. // ===========================================================
  16. class Art
  17. {
  18. protected:
  19. string id;
  20. string title;
  21. string artist;
  22. string genre;
  23. int year;
  24. double price;
  25.  
  26. public:
  27. Art(string i, string t, string a, string g, int y, double p)
  28. {
  29. id = i;
  30. title = t;
  31. artist = a;
  32. genre = g;
  33. year = y;
  34. price = p;
  35. }
  36.  
  37. virtual ~Art()
  38. {
  39. }
  40.  
  41. virtual void showArt() = 0;
  42. };
  43.  
  44. // ===========================================================
  45. // Derived Class: Painting
  46. // ===========================================================
  47. class Painting : public Art
  48. {
  49. private:
  50. string paintMedium;
  51.  
  52. public:
  53. Painting(string i, string t, string a, string g, int y, double p, string pm)
  54. : Art(i, t, a, g, y, p)
  55. {
  56. paintMedium = pm;
  57. }
  58.  
  59. ~Painting()
  60. {
  61. }
  62.  
  63. void showArt()
  64. {
  65. cout << "ID: " << id << endl;
  66. cout << "Title: " << title << endl;
  67. cout << "Artist: " << artist << endl;
  68. cout << "Paint Medium: " << paintMedium << endl;
  69. cout << "Genre: " << genre << endl;
  70. cout << "Year: " << year << endl;
  71. cout << "Price: $" << price << endl;
  72. }
  73. };
  74.  
  75. // ===========================================================
  76. // Derived Class: Sculpture
  77. // ===========================================================
  78. class Sculpture : public Art
  79. {
  80. private:
  81. string material;
  82.  
  83. public:
  84. Sculpture(string i, string t, string a, string g, int y, double p, string m)
  85. : Art(i, t, a, g, y, p)
  86. {
  87. material = m;
  88. }
  89.  
  90. ~Sculpture()
  91. {
  92. }
  93.  
  94. void showArt()
  95. {
  96. cout << "ID: " << id << endl;
  97. cout << "Title: " << title << endl;
  98. cout << "Artist: " << artist << endl;
  99. cout << "Material: " << material << endl;
  100. cout << "Genre: " << genre << endl;
  101. cout << "Year: " << year << endl;
  102. cout << "Price: $" << price << endl;
  103. }
  104. };
  105.  
  106. // ===========================================================
  107. // Function Prototype
  108. // ===========================================================
  109. void displayArt(Art &art);
  110.  
  111. // ===========================================================
  112. // displayArt Function
  113. // ===========================================================
  114. void displayArt(Art &art)
  115. {
  116. art.showArt();
  117. }
  118.  
  119. // ===========================================================
  120. // main
  121. // ===========================================================
  122. int main()
  123. {
  124. Painting a1("12345", "The Kiss", "Gustav Klimt", "Symbolist", 1908, 2500, "Oil");
  125. Sculpture a2("54321", "The Thinker", "Rodin", "Impressionism", 1880, 2000, "Bronze");
  126.  
  127. cout << "==========================" << endl;
  128. displayArt(a1);
  129. displayArt(a2);
  130. cout << "=====================================" << endl;
  131.  
  132. return 0;
  133. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
==========================
ID: 12345
Title: The Kiss
Artist: Gustav Klimt
Paint Medium: Oil
Genre: Symbolist
Year: 1908
Price: $2500
ID: 54321
Title: The Thinker
Artist: Rodin
Material: Bronze
Genre: Impressionism
Year: 1880
Price: $2000
=====================================