Advertisement
wendy890711

0429小測驗<繼承>

Apr 29th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include<iostream>
  3. using namespace std;
  4. #include <string>
  5.  
  6.  
  7. class CPublication
  8. {
  9. public:
  10. CPublication(int i, int j, string k){ page = i; price = j; title = k; };
  11.  
  12. void show()
  13. {
  14. cout << "page=" << page << endl;
  15. cout << "price=" << price << endl;
  16. cout << "title:" << title << endl;
  17. }
  18. int getpage(){ return page; }
  19. int getprice(){ return price; }
  20. string gettitle(){ return title; }
  21. private:
  22. int page, price;
  23. string title;
  24. };
  25.  
  26. class CBook :public CPublication
  27. {
  28. public:
  29. CBook(int i, int j, string k, string x, string y) :CPublication(i, j, k){ Author = x; ISBN = y; };
  30.  
  31. void show()
  32. {
  33. cout << "title:" << gettitle() << endl;
  34. cout << "page=" << getpage() << endl;
  35. cout << "price=" << getprice() << endl;
  36. cout << "Author:" << Author << endl;
  37. cout << "ISBN:" << ISBN << endl;
  38. }
  39. private:
  40. string Author, ISBN;
  41. };
  42.  
  43. void main()
  44. {
  45. CBook b1(15, 60, "我是書", "家儀", "DSFDSFSDF");
  46. CBook b2(50, 600, "我是很貴的書", "家儀", "SDADSFSDF");
  47. b1.show();
  48. b2.show();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement