C++ Tutorials

Destructors in C++ 0

Destructors in C++

Program 1 // Destructor in C++ #include<iostream> #include<conio.h> using namespace std; class Test { int a,b; public: Test(int a,int b) //constructor { this->a=a; this->b=b; cout<<“\nI am constructor\n”; } void maxData() { if(a>b) cout<<“\nFirst no...

Dynamic Memory Allocation in C++ Part – 3 0

Dynamic Memory Allocation in C++ Part – 3

Program 1 // Dynamic memory in CPP #include <iostream> #include <cstring> // for strcpy using namespace std; class Student { private: char* name; int* marks; int numSubjects; public: // Constructor Student(const char* studentName, int...

Dynamic Memory Allocation in C++ Part – 1 0

Dynamic Memory Allocation in C++ Part – 1

Program 1 // Dynamic memory allocation in C++ #include<iostream> using namespace std; int main() { system(“cls”); int *ar,n,sum=0; cout<<“Enter the limit: “<<endl; cin>>n; ar=new int[n]; /// allocation of dynamic memory cout<<“Enter elements in array:...

Template Pointers in C++ 0

Template Pointers in C++

Program 1 // template pointers in C++ #include<iostream> using namespace std; template<typename T> void myswap(T *a, T *b); int main() { system(“cls”); int a=500,b=200; char ch1=’X’,ch2=’Y’; cout<<” \n Before swaping: “<<a << ” “<<b;...

Templates in C++ Part – 2 0

Templates in C++ Part – 2

Program 1 // function template in C++ #include<iostream> using namespace std; template<typename T> bool searchData(T ar[],T s,int limit) { for(int i=0;i<limit;i++) { if(ar[i]==s) return true; } return false; } int main() { system(“cls”); int...

Templates in C++ Part – 1 0

Templates in C++ Part – 1

Program 1 // template in C++ #include<iostream> using namespace std; template<class T> class Test { T n; //string n public: Test(T m) //string m { n=m; } void show() { cout<<“Value is: “<<n<<endl; }...

Preprocessor Directives in C++ Part – 2 0

Preprocessor Directives in C++ Part – 2

Program 1 // Preprocessor #include <iostream> using namespace std; #define factorial(n){\ int f=1;\ while(n!=0)\ {\ f=f*n;\ n–;\ }\ cout<<“factorial is : “<<f;\ } int main() { system(“cls”); int n; cout<<“Enter a number: “; cin>>n;...

C++ Project – ATM Management System 0

C++ Project – ATM Management System

Program 1 // ATM Bank Application #include <iostream> #include <string.h> #include <cstdlib> // for system(“cls”) #include <conio.h> // for getch() using namespace std; class ATM { private: int acno; string name; int amount; public:...