Method
Method
get()
class Employee {
private:
int id;
float salary;
public:
void setId(int i) { id = i; }
void setSalary(float s) { salary = s; }
int main() {
Employee e;
[Link](101);
[Link](50000);
class Bank {
private:
double balance;
public:
void setBalance(double b) { balance = b; }
double getBalance() { return balance; }
};
int main() {
Bank b;
[Link](1000.75);
class Rectangle {
private:
int length, width;
public:
void setValues(int l, int w) {
length = l;
width = w;
}
int getArea() {
return length * width;
}
};
int main() {
Rectangle r;
[Link](5, 4);
class Car {
private:
int speed;
public:
void setSpeed(int s) { speed = s; }
int getSpeed() { return speed; }
};
int main() {
Car c;
[Link](120);
class Book {
private:
float price;
public:
void setPrice(float p) { price = p; }
float getPrice() { return price; }
};
int main() {
Book b;
[Link](299.99);
class Temperature {
private:
float temp;
public:
void setTemp(float t) { temp = t; }
float getTemp() { return temp; }
};
int main() {
Temperature t;
[Link](36.5);
class Circle {
private:
int radius;
public:
void setRadius(int r) { radius = r; }
int getRadius() { return radius; }
};
int main() {
Circle c;
[Link](7);
class Marks {
private:
int marks;
public:
void setMarks(int m) { marks = m; }
int getMarks() { return marks; }
};
int main() {
Marks m;
[Link](90);
class Product {
private:
float price;
public:
void setPrice(float p) { price = p; }
float getPrice() { return price; }
};
int main() {
Product p;
[Link](150.5);
class Demo {
public:
int x;
// 1. Default Constructor
Demo() {
x = 0;
cout << "Default Constructor called. x = " << x << endl;
}
// 2. Parameterized Constructor
Demo(int a) {
x = a;
cout << "Parameterized Constructor called. x = " << x << endl;
}
// 3. Copy Constructor
Demo(const Demo &obj) {
x = obj.x;
cout << "Copy Constructor called. x = " << x << endl;
}
};
int main() {
// Default constructor
Demo obj1;
// Parameterized constructor
Demo obj2(10);
// Copy constructor
Demo obj3 = obj2;
return 0;
}