Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string.h>
- using namespace std;
- class instrument{
- char *nume;
- float pret;
- public:
- instrument(const char*nume, const float pret){
- this->pret=pret;
- this->nume =new char[strlen(nume)];
- strcpy(this->nume,nume);
- }
- instrument(const instrument &x){
- pret=x.pret;
- nume=new char[strlen(x.nume)];
- strcpy(nume,x.nume);
- }
- instrument & operator =(const instrument &x){
- delete[] nume;
- pret=x.pret;
- nume=new char[strlen(x.nume)];
- strcpy(nume,x.nume);
- }
- virtual void tip(){
- cout<<"instrument"<<endl;
- }
- friend ostream & operator <<(ostream & cout, instrument & x){
- cout<<"pret: "<< x.pret <<" nume: "<< x.nume<<endl;
- return cout;
- }
- ~ instrument(){
- delete[]nume;
- }
- };
- class acordeon:public instrument{
- int nr_clape;
- public:
- acordeon(const char*nume, const float pret, const int nr_clape):instrument(nume,pret){
- this->nr_clape=nr_clape;
- }
- acordeon(acordeon &x):instrument(x){
- this->nr_clape=nr_clape;
- }
- acordeon & operator =(const acordeon &x){
- nr_clape=x.nr_clape;
- instrument::operator=(x);
- }
- void tip(){
- cout<<"acordeon"<<endl;
- }
- friend ostream & operator <<(ostream &cout,acordeon & x){
- cout<<(instrument&)x;
- cout<<"nr.clape: "<<x.nr_clape<<endl;
- }
- };
- int main(){
- instrument *i=new instrument("chitara",12394);
- cout<<*i<<endl;
- i->tip();
- acordeon *a=new acordeon ("sony",2345,21);
- cout<<*a<<endl;
- a->tip();
- i=a;
- i->tip();
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment