Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
describe the highlighted code//header files #include #include using namespace
#1
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");
}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to check include library in Dev C++ Vuhelper 0 3,341 06-09-2012, 06:18 PM
Last Post: Vuhelper
  how can i mail you the snapshot of compiled files.in C++ 2012 Vuhelper 0 2,873 05-31-2012, 01:32 AM
Last Post: Vuhelper
  ASCII code is binary numbers of 0 and 1 in C++ 2012 Vuhelper 0 2,281 01-04-2012, 10:41 PM
Last Post: Vuhelper
  int x[10]; x[0]= 1; x[1]=2; if following code is executable in C++ 2012 Vuhelper 0 1,936 01-04-2012, 10:17 PM
Last Post: Vuhelper
  array project code c++ 2011 Vuhelper 0 1,277 12-10-2011, 06:32 PM
Last Post: Vuhelper
  factorial in C++ code 2011 Vuhelper 0 955 12-10-2011, 06:31 PM
Last Post: Vuhelper
  ASCII to char conversion code in C++ 2011 Vuhelper 0 1,725 11-05-2011, 05:01 PM
Last Post: Vuhelper
  In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31, from C:\Do sana.pari 2 3,554 11-02-2011, 03:02 AM
Last Post: baig66
  C++ with loop code 2011-12 Vuhelper 0 981 09-18-2011, 07:09 PM
Last Post: Vuhelper
  Revised Student Record Code written in C++ 2011-12 Vuhelper 0 1,478 09-04-2011, 07:18 AM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)