CPP Structs

Structs are blueprints in CPP. Like classes, CPP structs are used to create instance of a class, but are preferred only for lightweight objects which are not intended to any future modifications. The lightweight objects include, Rectangle, color, Point etc. A CPP class uses Call by Value method for calling while, CPP structs uses Call … Read more

Categories CPP

CPP static

There are a list of words already defined in CPP library, same as in C. These reserved words are called as CPP Keywords. Every keyword is defined to serve a specific purpose. CPP static is one such keyword, which is used as a storage class to represent the scope of a variable within the program. … Read more

Categories CPP

CPP this Pointer

In CPP library, this is a pre-defined keyword which is used to refer to the current instance of a class. Usage of CPP this Pointer: to pass current object as a parameter to another method. to refer current class instance variable. to declare indexers. Example: #include <iostream.h> using namespace std;   class Student { public: … Read more

Categories CPP

CPP program to print Fibonacci Triangle

The below program is to print the Fibonacci Triangle in CPP using loop. Code: #include <iostream.h> using namespace std;   int main() { int a,b,i,c,j; for(i=1; i<=5; i++) { a=0; b=2; cout<<b<<"\t"; for(j=1; j<i; j++) { c=a+b; cout<<c<<"\t"; a=b; b=c; } cout<<"\n"; } return 0; }#include <iostream.h> using namespace std; int main() { int a,b,i,c,j; … Read more

Categories CPP

CPP program to print Number Triangle

The below program is to print the Number Triangle in CPP using loop. Code: #include <iostream.h> using namespace std;   int main() { int i,j,k,l; for(i=1;i<=5;i++) { for(j=1;j<=5-i;j++) { cout<<" "; } for(k=1;k<=i;k++) { cout<<k; } for(l=i-1;l>=1;l–) { cout<<l; } cout<<"\n"; } return 0; }#include <iostream.h> using namespace std; int main() { int i,j,k,l; for(i=1;i<=5;i++) … Read more

Categories CPP

CPP program to print Alphabet Triangle

The below program is to print the Alphabet Triangle in CPP using loop. Code: #include <iostream.h> using namespace std;   int main() { char ch=’a’; int i, j, k, l; for(i=1;i<=5;i++) { for(j=5;j>=i;j–) cout<< " "; for(k=1;k<=i;k++) cout << ch++; ch–; for(l=1;l<i;l++) cout<<–ch; cout<< "\n"; ch=’a’; } return 0; }#include <iostream.h> using namespace std; int … Read more

Categories CPP

CPP program to print Numbers in form of Characters

The below program is to print the word representation of a number in CPP using loop. Code: #include <iostream.h> using namespace std;   int main() { int num,x; int tot = 0;   cout << "Enter the number: "; cin >> num;   while(num>0) { x = num%10; tot = tot*10 + x; num = … Read more

Categories CPP

CPP program to convert a decimal number into a binary number

Decimal System: A number system with base 10 i.e, numbers from 0-9 are used to represent a decimal number system. Binary System: A number system with base 2 i.e, only binary numbers 0 and 1 are used to represent a binary number system. Code: #include <iostream.h> using namespace std;   int main() { int arr[20]; … Read more

Categories CPP

CPP program to print Matrix Multiplication

The below program is to print multiplication of two matrices. The CPP cout object is used to output the result on the screen. Code: #include <iostream.h> using namespace std;   int main() { int a[2][3] = { {2, 5, 5}, {4, 0, 6} }; int b[3][2] = { {4, 5}, {4, 8}, {3, 9} }; … Read more

Categories CPP

CPP program to swap two numbers

The below program is to swap two numbers with and without using third variable. The CPP cout object is used to output the result on the screen. Swapping two numbers simply means interchanging the values of two numeric variables. Before Swapping, A = n1 B = n2 After Swapping, A = n2 B = n1 … Read more

Categories CPP