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


नवीनतम संदेश 2

2022-07-04 13:36:33 C++ Parameterized Constructor

In C++, a constructor with parameters is known as a parameterized constructor. This is the preferred method to initialize member data.
8 viewsAɱαɳ Vҽɾɱα, 10:36
ओपन / कमेंट
2022-07-04 13:36:19 Here, when the wall1 object is created, the Wall() constructor is called. This sets the length variable of the object to 5.5.

Note: If we have not defined a constructor in our class, then the C++ compiler will automatically create a default constructor with an empty code and no parameters.
8 viewsAɱαɳ Vҽɾɱα, 10:36
ओपन / कमेंट
2022-07-04 13:36:05 Output

Creating a Wall
Length = 5.5
8 viewsAɱαɳ Vҽɾɱα, 10:36
ओपन / कमेंट
2022-07-04 13:36:00 // C++ program to demonstrate the use of default constructor

#include
using namespace std;

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

public:
// default constructor to initialize variable
Wall() {
length = 5.5;
cout << "Creating a wall." << endl;
cout << "Length = " << length << endl;
}
};

int main() {
Wall wall1;
return 0;
}
8 viewsAɱαɳ Vҽɾɱα, 10:36
ओपन / कमेंट
2022-07-04 13:35:55 Example 1: C++ Default Constructor
8 viewsAɱαɳ Vҽɾɱα, 10:35
ओपन / कमेंट
2022-07-04 13:35:49 C++ Default Constructor
A constructor with no parameters is known as a default constructor. In the example above, Wall() is a default constructor.
8 viewsAɱαɳ Vҽɾɱα, 10:35
ओपन / कमेंट
2022-07-04 13:35:36 C++ Constructors

In this tutorial, we will learn about the C++ constructor and its type with the help examples.

A constructor is a special type of member function that is called automatically when an object is created.

In C++, a constructor has the same name as that of the class and it does not have a return type. For example,

class Wall {
public:
// create a constructor
Wall() {
// code
}
};

Here, the function Wall() is a constructor of the class Wall. Notice that the constructor

has the same name as the class,
does not have a return type, and
is public
8 viewsAɱαɳ Vҽɾɱα, 10:35
ओपन / कमेंट
2022-07-04 13:31:02 The above example is nearly identical to the first example, except that the class variables are now private.

Since the variables are now private, we cannot access them directly from main(). Hence, using the following code would be invalid:

// invalid code
obj.length = 42.5;
obj.breadth = 30.8;
obj.height = 19.2;

Instead, we use the public function initData() to initialize the private variables via the function parameters double len, double brth, and double hgt.
7 viewsAɱαɳ Vҽɾɱα, 10:31
ओपन / कमेंट
2022-07-04 13:30:37 // Program to illustrate the working of
// public and private in C++ Class

#include
using namespace std;

class Room {

private:
double length;
double breadth;
double height;

public:

// function to initialize private variables
void initData(double len, double brth, double hgt) {
length = len;
breadth = brth;
height = hgt;
}

double calculateArea() {
return length * breadth;
}

double calculateVolume() {
return length * breadth * height;
}
};

int main() {

// create object of Room class
Room room1;

// pass the values of private variables as arguments
room1.initData(42.5, 30.8, 19.2);

cout << "Area of Room = " << room1.calculateArea() << endl;
cout << "Volume of Room = " << room1.calculateVolume() << endl;

return 0;
}
7 viewsAɱαɳ Vҽɾɱα, 10:30
ओपन / कमेंट
2022-07-04 13:30:32 Example 2: Using public and private in C++ Class
6 viewsAɱαɳ Vҽɾɱα, 10:30
ओपन / कमेंट