Guest User

Untitled

a guest
Jul 21st, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3.  
  4. using namespace std;
  5.  
  6. class instrument{
  7. char *nume;
  8. float pret;
  9. public:
  10. instrument(const char*nume, const float pret){
  11. this->pret=pret;
  12. this->nume =new char[strlen(nume)];
  13. strcpy(this->nume,nume);
  14. }
  15. instrument(const instrument &x){
  16. pret=x.pret;
  17. nume=new char[strlen(x.nume)];
  18. strcpy(nume,x.nume);
  19. }
  20. instrument & operator =(const instrument &x){
  21. delete[] nume;
  22. pret=x.pret;
  23. nume=new char[strlen(x.nume)];
  24. strcpy(nume,x.nume);
  25.  
  26. }
  27. virtual void tip(){
  28. cout<<"instrument"<<endl;
  29. }
  30.  
  31. friend ostream & operator <<(ostream & cout, instrument & x){
  32. cout<<"pret: "<< x.pret <<" nume: "<< x.nume<<endl;
  33. return cout;
  34.  
  35. }
  36.  
  37. ~ instrument(){
  38. delete[]nume;
  39. }
  40.  
  41. };
  42. class acordeon:public instrument{
  43. int nr_clape;
  44. public:
  45. acordeon(const char*nume, const float pret, const int nr_clape):instrument(nume,pret){
  46. this->nr_clape=nr_clape;
  47. }
  48. acordeon(acordeon &x):instrument(x){
  49. this->nr_clape=nr_clape;
  50. }
  51. acordeon & operator =(const acordeon &x){
  52. nr_clape=x.nr_clape;
  53. instrument::operator=(x);
  54. }
  55. void tip(){
  56. cout<<"acordeon"<<endl;
  57. }
  58. friend ostream & operator <<(ostream &cout,acordeon & x){
  59. cout<<(instrument&)x;
  60. cout<<"nr.clape: "<<x.nr_clape<<endl;
  61. }
  62.  
  63.  
  64.  
  65. };
  66.  
  67.  
  68. int main(){
  69. instrument *i=new instrument("chitara",12394);
  70. cout<<*i<<endl;
  71. i->tip();
  72. acordeon *a=new acordeon ("sony",2345,21);
  73. cout<<*a<<endl;
  74. a->tip();
  75. i=a;
  76. i->tip();
  77.  
  78. system("pause");
  79. return 0;
  80. }
Add Comment
Please, Sign In to add comment