C++ Tutorials

C++ Program on Dynamic Memory Allocation 0

C++ Program on Dynamic Memory Allocation

Program 1 // Program for Dynamic Memory allocation using new and delete #include<iostream> #define clrscr() system(“cls”) using namespace std; int main() { int *ar,n,i,sum=0; clrscr(); cout<<“\nEnter limit of array”; cin>>n; ar=new int[n]; //dynamic memory...

C++ Program on Template Pointer 0

C++ Program on Template Pointer

Program 1 // Program for tempalte pointer #include<iostream> #define clrscr() system(“cls”) using namespace std; template<class T> void swap(T *a,T *b); int main() { clrscr(); int a=100,b=50; char ch1=’X’,ch2=’Y’; double d1=50.10,d2=30.10; cout<<“\nBefore swaping: “<<a<<” “<<b;...

C++ Program on Templates 0

C++ Program on Templates

Program 1 // Program for class tempalte #include<iostream> #define clrscr() system(“cls”) using namespace std; template<class T,class V> class Test { T n; V n1; public: Test(T m,V m1) { n=m; n1=m1; } void display()...

Relational Operator Overloading in C++ 0

Relational Operator Overloading in C++

Program 1 //Program for Relational operator overloading // How to compare to object #include<iostream> #define clrscr() system(“cls”) using namespace std; class Test { int n; public: Test(int n) { this->n=n; } Test(Test &k) {...

How to Use Read and Write Methods in C++ 0

How to Use Read and Write Methods in C++

Program 1 // read write method (How to store object in file) #include<iostream> #include<fstream> #define clrscr() system(“cls”) using namespace std; class Employee { private : int empid; char name[20]; char dname[20]; int salary; public:...

C++ Program For get vs getline 0

C++ Program For get vs getline

Program 1 // get and getline method #include<iostream> #include<fstream> #define clrscr() system(“cls”) using namespace std; int main() { char name[20]; char college[20]; clrscr(); cout<<“\nEnter your Name:”; cin.getline(name,20); cout<<“\nEnter your College Name:”; cin.getline(college,20); cout<<“\nName: “<<name;...

How to Open File Using Open Method in C++ 0

How to Open File Using Open Method in C++

Program 1 // open file using Open Method for write #include<iostream> #include<fstream> #define clrscr() system(“cls”) using namespace std; int main() { clrscr(); fstream fout; char name[20]; char city[20]; char college[20]; fout.open(“g://cppdata/student.txt”,ios::out); cout<<“Enter Name: “;...