Jump to content

Recommended Posts

Posted
#include<iostream>

#include<string>

#include <cstring>

#include <cstdlib>

using namespace std;

class persoana

{

	int varsta;

public:

	char *pnume;

	persoana(char *n,int v):varsta(v)

	{

		pnume=new char[strlen("Anonim")+1];

		strcpy(pnume, n);

	}

	int spune_varsta()

	{

		return varsta;

	}

};

int main()

{

	persoana p1("vasilache",45);

	persoana p2=p1;//apel constructor de copiere

	cout<<"\n"<<p1.pnume<<"are"<<p1.spune_varsta()<<"ani";

	cout<<"\n"<<p2.pnume<<"are"<<p2.spune_varsta()<<"ani";

	strcpy(p2.pnume,"Gigi");

	cout<<"\n"<<p1.pnume<<"are"<<p1.spune_varsta()<<"ani";

	cout<<"\n"<<p2.pnume<<"are"<<p2.spune_varsta()<<"ani" << endl;

	system("PAUSE");

	return 0;

}

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.