Program of Copy Constructor

 #include<iostream>

#include<conio.h>

using namespace std;

class Box

{

private:

    float l,b,h;

public:

    Box(float le, float br, float he)

   {

   l=le;

   b=br;

   h=he;

   }

   Box(Box &b2)

   {

       l=b2.l;

       b=b2.b;

       h=b2.h;

   }

   void DisplayMembers()

   {

       cout<<"\nLength:"<<l;

       cout<<"\nBreadth:"<<b;

       cout<<"\nHeight:"<<h;

   }

float getVolume()

{

    return l*b*h;

}

};

int main()

{

float vol;

Box b1(10.5,5.5,6.5);

Box b2(b1);

cout<<"___________For the First Object b1_______________:";

b1.DisplayMembers();

vol=b1.getVolume();

cout<<"\nThe Volume of Box is:"<<vol;

cout<<"\n___________For the second Object b2_______________:";

b2.DisplayMembers();

vol=b2.getVolume();

cout<<"\nThe Volume of Box is:"<<vol;

getch();

return 0;

};

                          Output of copy constructor


OUTPUT


 

No comments:

Post a Comment

Write a C program that: 1. Accepts the total purchase amount, customer type, and season from the user. 2. Uses nested if-else statements to calculate and display the final amount after applying the discount.

Here is a C Program for Customer and Day Based Shop Management Program  #include <stdio.h> int main () {     char name [ 20 ];     ...

Contact form

Name

Email *

Message *

loading...