163. Write a program to demonstrate parameterized constructor?

#include<iostream.h> #include<conio.h> class demo {                 int x; public:                 demo(int y)                                 {                                 x=y;                                 display();                                 }                 void display()                                 {                                 cout<<"X = "<<x<<endl;                                 } }; void main()                 {                 clrscr();                 demo d(50);                 getch(); }

Advertisements

162. Write a program to call the member function using constructor?

#include<iostream.h> #include<conio.h> class demo {                 int x; public:                 demo()                                 {                                 x=30;                                 display();                                 }                 void display()                                 {                                 cout<<"X = "<<x<<endl;                                 } }; void main()                 {                 clrscr();                 demo d;                 getch(); }

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: