0
#include<iostream.h>
#include<conio.h>

class  citizen
{
private:
      const char name[25];
      char nationality[25];

public:
	citizen()   //first constructor with no parameter
		{


	 name="Farhan";
	 nationality="PAkistani";
		}
	     citizen(char a, char b)//second constructor
		{
		name=a;
		nationality=b;
		}

      ~citizen()   // destructor
		{
		cout<<"\n Destructor called";
		}

     void display()
		{
		cout<<name;
		cout<<"\n"<<nationality;
		}
};


void main()
{
clrscr();
citizen a;

}

The output should be the following
Farhan
Pakistani

Mark
australian


Whare
Farhan
pakistani
are the initialized agaubst tge constructor with no parameter

Mark
Australian
are the initialized vaues against the constructor with to parameter mark
australian

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by needhelp//
0

You never call the constructor that takes parameters with "mark" "australian".

You never call the display() method

Does it even compile?

main returns int not void returning void is undefined behaviour.

-3
#
this'll work out...:icon_cool:

void main()
#
{
#
clrscr();
#
citizen a;
a.display();
citizen b("mark","australian");
b.display();
#
 
#
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.