C++ Tutorials

Function Overloading in C++ 0

Function Overloading in C++

Program 1 // Program for function overloading #include<iostream> #define clrscr() system(“cls”) using namespace std; double area(double ); double area(double,double); int main() { clrscr(); cout<<“\nArea of circle: “<<area(12.44); cout<<“\nArea of Rectangle: “<<area(12.4,6.8); return 0; }...

Pyramid Patterns in C++ with Examples 0

Pyramid Patterns in C++ with Examples

Program 1 // Star Pyramid Program #include<iostream> #define clrscr() system(“cls”) using namespace std; int main() { int n,m; int i,j,k; cout<<“\n Enter the limit of row”; cin>>n; m=n; for(i=1;i<=n;i++) { for(j=1;j<=m-1;j++) { cout<<” “;...

C++ Program on Exception Handling 0

C++ Program on Exception Handling

Program 1 #include<iostream> #include<stdexcept> using namespace std; int main() { int a,b,c; cout<<“Enter two number”; cin>>a>>b; try { if(b==0) throw(runtime_error(“Can not devide by Zero”)); c=a/b; cout<<c; } catch(const std::exception &e) { std::cerr << e.what()...

Constructor for Multiple Object in C++ 0

Constructor for Multiple Object in C++

Program 1 // Test Constructor for multiple Object #include<iostream> #define clrscr() system(“cls”) using namespace std; class Test { int n; public: Test() { cout<<” I am constructor\n”; n=10; } void incr() { ++n; }...

Multiple if else Statement in C++ 0

Multiple if else Statement in C++

Program 1 // Program for Nested if else #include<iostream> #define clrscr() system(“cls”) using namespace std; int main() { int a,b,c; cout<<“Enter three number”; cin>>a>>b>>c; if(a>b && a>c) cout<<“Grater number is “<<a; else if(b>c) cout<<“Grater...

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...