Get Mystery Box with random crypto!

C

टेलीग्राम चैनल का लोगो cplusplusstation — C  C
टेलीग्राम चैनल का लोगो cplusplusstation — C
चैनल का पता: @cplusplusstation
श्रेणियाँ: शिक्षा
भाषा: हिंदी
ग्राहकों: 65
चैनल से विवरण

C theory and programs
Owner :- @MistarAV
Instagram :- https://www.instagram.com/mistarav
Visit :- http://Codeskiduniya.blogspot.com

Ratings & Reviews

2.67

3 reviews

Reviews can be left only by registered users. All reviews are moderated by admins.

5 stars

0

4 stars

1

3 stars

0

2 stars

2

1 stars

0


नवीनतम संदेश

2022-07-04 13:39:01 In main(), we then create two objects wall1 and wall2 and then copy the contents of wall1 to wall2:

// copy contents of wall1 to wall2
Wall wall2 = wall1;

Here, the wall2 object calls its copy constructor by passing the address of the wall1 object as its argument i.e. &obj = &wall1.

Note: A constructor is primarily used to initialize objects. They are also used to run a default code when an object is created.
15 viewsAɱαɳ Vҽɾɱα, 10:39
ओपन / कमेंट
2022-07-04 13:38:00 In this program, we have used a copy constructor to copy the contents of one object of the Wall class to another. The code of the copy constructor is:

Wall(Wall &obj) {
length = obj.length;
height = obj.height;
}

Notice that the parameter of this constructor has the address of an object of the Wall class.

We then assign the values of the variables of the obj object to the corresponding variables of the object calling the copy constructor. This is how the contents of the object are copied.
15 viewsAɱαɳ Vҽɾɱα, 10:38
ओपन / कमेंट
2022-07-04 13:37:47 Output

Area of Wall 1: 90.3
Area of Wall 2: 90.3
12 viewsAɱαɳ Vҽɾɱα, 10:37
ओपन / कमेंट
2022-07-04 13:37:44 #include
using namespace std;

// declare a class
class Wall {
private:
double length;
double height;

public:

// initialize variables with parameterized constructor
Wall(double len, double hgt) {
length = len;
height = hgt;
}

// copy constructor with a Wall object as parameter
// copies data of the obj parameter
Wall(Wall &obj) {
length = obj.length;
height = obj.height;
}

double calculateArea() {
return length * height;
}
};

int main() {
// create an object of Wall class
Wall wall1(10.5, 8.6);

// copy contents of wall1 to wall2
Wall wall2 = wall1;

// print areas of wall1 and wall2
cout << "Area of Wall 1: " << wall1.calculateArea() << endl;
cout << "Area of Wall 2: " << wall2.calculateArea();

return 0;
}
11 viewsAɱαɳ Vҽɾɱα, 10:37
ओपन / कमेंट
2022-07-04 13:37:39 Example 3: C++ Copy Constructor
8 viewsAɱαɳ Vҽɾɱα, 10:37
ओपन / कमेंट
2022-07-04 13:37:34 C++ Copy Constructor
The copy constructor in C++ is used to copy data of one object to another.
8 viewsAɱαɳ Vҽɾɱα, 10:37
ओपन / कमेंट
2022-07-04 13:37:13 Here, we have created a parameterized constructor Wall() that has 2 parameters: double len and double hgt. The values contained in these parameters are used to initialize the member variables length and height.

When we create an object of the Wall class, we pass the values for the member variables as arguments. The code for this is:

Wall wall1(10.5, 8.6);
Wall wall2(8.5, 6.3);

With the member variables thus initialized, we can now calculate the area of the wall with the calculateArea() function.
8 viewsAɱαɳ Vҽɾɱα, 10:37
ओपन / कमेंट
2022-07-04 13:36:51 Output

Area of Wall 1: 90.3
Area of Wall 2: 53.55
8 viewsAɱαɳ Vҽɾɱα, 10:36
ओपन / कमेंट
2022-07-04 13:36:47 // C++ program to calculate the area of a wall

#include
using namespace std;

// declare a class
class Wall {
private:
double length;
double height;

public:
// parameterized constructor to initialize variables
Wall(double len, double hgt) {
length = len;
height = hgt;
}

double calculateArea() {
return length * height;
}
};

int main() {
// create object and initialize data members
Wall wall1(10.5, 8.6);
Wall wall2(8.5, 6.3);

cout << "Area of Wall 1: " << wall1.calculateArea() << endl;
cout << "Area of Wall 2: " << wall2.calculateArea();

return 0;
}
8 viewsAɱαɳ Vҽɾɱα, 10:36
ओपन / कमेंट
2022-07-04 13:36:41 Example 2: C++ Parameterized Constructor
8 viewsAɱαɳ Vҽɾɱα, 10:36
ओपन / कमेंट