05-02-2011, 06:45 PM
describe the highlighted code//header files #include #include using namespace
class citizen
{
//hidden part
private:
char* name; //for citizen's name
char* nationality; //for nationality
//interface
public:
//paramterless constructor
citizen()
{
name = "Farhan" ;
nationality = "pakistani";
}
//parameterized constructor
citizen(char* name1, char* nationality1)
{
name = name1;
nationality = nationality1;
}
//copy constructor
citizen(const citizen &other)
{
//for string lengths
int length1, length2;
length1 = strlen(other. name);
length2 = strlen(other. nationality);
//allocating new memory space
name = new char[length1 + 1];
nationality = new char[length2 + 1];
//copying strings
strcpy( name, other.name );
strcpy( nationality, other.nationality );
/for displaying name and nationality
void display()
{
cout< cout<<"_________________"<}
//destructor
~citizen(){}
};};
//main function
int main()
{
//object declarations
citizen c1;
citizen c2("Mark", "Australian");
citizen c3(c2);
//display function calls
c1.display();
c2.display();
c3.display();
//Hault the system untill press a key
system("PAUSE");
}
class citizen
{
//hidden part
private:
char* name; //for citizen's name
char* nationality; //for nationality
//interface
public:
//paramterless constructor
citizen()
{
name = "Farhan" ;
nationality = "pakistani";
}
//parameterized constructor
citizen(char* name1, char* nationality1)
{
name = name1;
nationality = nationality1;
}
//copy constructor
citizen(const citizen &other)
{
//for string lengths
int length1, length2;
length1 = strlen(other. name);
length2 = strlen(other. nationality);
//allocating new memory space
name = new char[length1 + 1];
nationality = new char[length2 + 1];
//copying strings
strcpy( name, other.name );
strcpy( nationality, other.nationality );
/for displaying name and nationality
void display()
{
cout< cout<<"_________________"<}
//destructor
~citizen(){}
};};
//main function
int main()
{
//object declarations
citizen c1;
citizen c2("Mark", "Australian");
citizen c3(c2);
//display function calls
c1.display();
c2.display();
c3.display();
//Hault the system untill press a key
system("PAUSE");
}
