this Pointer in C++
Program 1 #include<iostream> using namespace std; class Test { private: int n; // instance variable public: Test(int n) // local variable { this->n=n; } void display() { cout<<this->n; } }; int main() { system(“cls”);...
Program 1 #include<iostream> using namespace std; class Test { private: int n; // instance variable public: Test(int n) // local variable { this->n=n; } void display() { cout<<this->n; } }; int main() { system(“cls”);...
Program 1 // Bank Application #include<iostream> using namespace std; class Bank { private: int accno; string name; int balance; public: Bank() { balance=0; } void create_account(); void deposit_amount(); void withd_amount(); void display(); }; void...
Problem 1 // Method overloading #include<iostream> using namespace std; class AreaCalculator { public: //area of square int area(int side); // area of circle double area(double r); // area of rectangle int area(int l ,int...
Program 1 // Default Constructor , Overloading #include<iostream> using namespace std; class Test { public: Test(int x) // 01 parameter { cout<<x; } Test() { } void display(); }; void Test::display() { cout<<“Hello Friends”;...
Program 1 // Constructor in CPP #include<iostream> using namespace std; class Test { private: int a,b,c; public: Test(int x,int y) // parameterized constructor { a=x; b=y; cout<<“\nI am constructor\n”; } void add(); }; void...
Program 1 // Ranged based for loop #include<iostream> #include <vector> #include <map> using namespace std; int main() { system(“cls”); int nums[] = {1, 2, 3}; for (int &x : nums) { x =x*2; }...
Program 1 // Class and Object #include<iostream> using namespace std; class Student { private: int rno; string name; string course; double cgpa; public: void getData(); void putData(); }; void Student::getData() { cout<<“\nEnter Roll No:...
Program 1 /* Recursion in cpp direct int main() { display(); } void display() { —- — display(); } indirect display() { xyz(); } xyz() { display(); } */ #include<iostream> using namespace std; int...
Program 1 /* Storage classes auto static register extern ——————————————- static Memory type: RAM default value:0 scope: local */ #include<iostream> using namespace std; void display(); int a=100; int main() { int a=500; system(“cls”); cout<<a<<endl;...
Program 1 // Function in CPP #include<iostream> using namespace std; int swap(int *a,int *b); int main() { system(“cls”); int a,b; cout<<“Enter two number”; cin>>a>>b; cout<<“\nBefore swaping: “<<a<<” “<<b; swap(&a,&b); //local cout<<“\nAfter swaping: “<<a<<” “<<b;...