Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. class GoodIntrf {
  2. public:
  3. virtual char GetName (int id) = 0;
  4. };
  5.  
  6. #include "GoodIntrf.h"
  7. class Fruit : public GoodIntrf
  8. {
  9. public:
  10. char* getName(int id) {
  11. if (id == 1) return "Apple";
  12. if (id == 2) return "Orange";
  13. else return "Unknown type";
  14. }
  15. };
  16.  
  17. #include "GoodIntrf.h"
  18. class Vegetable : public GoodIntrf
  19. {
  20. public:
  21. char* getName(int id) {
  22. if (id == 1) return "Potato";
  23. if (id == 2) return "Tomato";
  24. else return "Unknown type";
  25. }
  26. };
  27.  
  28. #include <iostream>
  29. #include <string>
  30. #include "Fruit.h"
  31. #include "Vegetable.h"
  32. #include "GoodIntrf.h"
  33. class Storage : public GoodIntrf
  34. {
  35. public:
  36. char GetName(int id) {
  37. return id;
  38. }
  39. };
  40. int main(int argc, char** argv) {
  41. Storage a = Storage();
  42. std::cout << a.GetName(1) << std::endl;
  43. std::cout << a.GetName(2) << std::endl;
  44. Storage a = Storage();
  45. std::cout << a.GetName(1) << std::endl;
  46. std::cout << a.GetName(2) << std::endl;
  47. system("pause");
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement