Skip to main content

Posts

C++

C++  is a general-purpose programming language created by Bjarne Stroustrup as an extension of the C programming language, or "C with Classes". The language has expanded significantly over time, and modern C++ now has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.  It is almost always implemented as a compiled language, and many vendors provide C++ compilers, including the Free Software Foundation, LLVM, Microsoft, Intel, Oracle, and IBM, so it is available on many platforms.                C++ was designed with an orientation toward system programming and embedded, resource-constrained software and large systems, with performance, efficiency, and flexibility of use as its design highlights.            C++ has also been found useful in many other contexts, with key strengths being software infrastructure and resource-constrained applic...
Recent posts

//Function:-Arthmatic Operation

//Function Arthmatic Operation #include <iostream> using namespace std; //Function Declaring int add(int a , int b);//Function Prototype is declared before main() int sub(int a, int b); int _div(int a, int b);//'int' is return type of the Function int multi(int a, int b); int modulos(int a, int b); int main() { int rs1,rs2,rs3,rs4,rs5; //Taking New Variable For Storing Value of  rs1 = add(30,20); //Calling the Function and Storing. cout<<"the addition of a+b is:"<<rs1<<endl;   rs2 = sub(30,20);         cout<<"the subtraction of a-b is:"<<rs2<<endl; //"cout" use for print line.   rs3 = _div(30,20);         cout<<"the division of a/b is:"<<rs3<<endl; //"endl" use for linebreak.   rs4 = multi(30,20);         cout<<"the multiplication of a*b is:"<<rs4<<endl;  rs5 = modulos(30,20);         cout<...

//Switch Case (String)

  Switch String:- In Switch String we use words and numbers in "duble quotes". CODE 👇 #include<iostream> using namespace std; int main() { String  ch = "one"; //which case you want to execute 'Enter' case value. int a = 30; //variable def int b = 20;  int c; switch(ch) { case "one" : //the case label must end with colon(:) { //Addition c = a + b; cout<<"the value of a+b is"<<c<<endl; //"cout" use for print line. break; //It's necessary to use break after each block. } case "two" : //case label must be unique.         {         //Subtract                 c = a - b;                 cout<<"the value of a-b is"<<c<<endl; //"endl" use for linebreak.          break; //if you don't use it, then all cases executed. } case "three" :         {  ...

//Switch Case (Integer)

 //Switch Integers:-                                              In Switch Integer we use Numbers(integers) CODE 👇 #include<iostream> using namespace std; int main() { int _int = '5'; //which case you want to execute 'Enter' case value. int a = 30; //variable def int b = 20;  int c;  switch(_int)  { case '1': //the case label must end with colon(:) { //Addition c = a + b; cout<<"the value of a+b is:"<<c<<endl; //"cout" use for print line. break; //It's necessary to use break after each block. } case '2': //case label must be unique.         {         //Subtract                 c = a - b;                 cout<<"the value of a-b is:"<<c<<endl; //"endl" use for linebreak....

//Switch Case (Character)

 //Switch Case(Character):-                                                         In switch char we use character for ex. + ,-, *, /, %, @ CODE 👇 #include<iostream> using namespace std; int main() { char ch = '+'; //which case you want to execute 'Enter' case value. int a = 30; //variable def int b = 20;  int c; switch(ch) { case '+': //the case label must end with colon(:) { //Addition c = a + b; cout<<"the value of a+b is"<<c<<endl; //"cout" use for print line. break; //It's necessary to use break after each block. } case '-': //case label must be unique.         {         //Subtract                 c = a - b;                 cout<<"the...

//Do While

  //Do While CODE 👇 #include <iostream> using namespace std; int main() { int a = 10; //variable def //do loop do // the loop excutes once before the condition tested. { cout<<"the value of a is:"<<a<<endl; c //"endl" use for linebreak. //"cout" use for print line. a++;                                  // a++ for this condition 'a <= 20'. value increase upto 20. }while(a <= 20);                      //(a=10 <= 20) the condition is True; therefore execute conditional code.                                          //the condition is true; then control jumps to back 'do', and the loop again ececutes unitl then condition is false. return 0; } 👉 Execute 👈 //Output /* the value of a is:10 the v...

//While Loop

 //While Loop CODE 👇 //Print number from 10 to 20. #include <iostream> using namespace std; int main() { int a = 10; //int use for integer value. while(a <= 20) / /(a=10 <= 20) the condition is True; therefore excute conditional code.               //when condition is true then excute conditional code; otherwise loop body skipped. { //the body of while loop cout<<"the value of a is:"<<a<<endl; //"endl" use for linebreak. //"cout" use for print line. a++; // a++ for this condition 'a <= 20'. value increase upto 20.   } return 0; } 👉 Execute 👈 //Output /* the value of a is:10 the value of a is:11 the value of a is:12 the value of a is:13 the value of a is:14 the value of a is:15 the value of a is:16 the value of a is:17 the value of a is:18 the value of a is:19 the value of a is:20 */                             ...

//If-Else-If Example:- Grade

 //if-else-if Example:- Grade CODE 👇 #include<iostream> using namespace std; int main() //Main Function { int sub1 = 81; int sub2 = 79; int sub3 = 87; int sub4 = 83; //int use for integer value. int sub5 = 85; int per; int per2; per = sub1 + sub2 + sub3 + sub4 + sub5; per2 = per / 5; cout<<"Persentage:"<<per2<<endl; if(per2 >= 90) { cout<<"Grade A"<<endl; //These statements would execute if the condition is true } else if(per2 >= 80) { cout<<"Grade B"<<endl; //'cout' use for print line  } else if(per2 >= 70)         {         cout<<"Grade C"<<endl; //"endl" use for linebreak.           } else if (per2 >= 60)         {         cout<<"Grade D"<<endl;         } else if (per2 >= 40)         {     ...

//For Loop

  //For Loop: For loop statement:  //Initialization:-the control-variable is done first, using assignment statement such as a=10 or count=0.                      //Test Condition:- If condition is 'True', the body of loop is ececuted. Otherwise the the loop is terminted.                     //Increment/Decrement:- here is 'Increment' then, the control variable is incremented and this value again tested.                    //this process continues till the value of the control variable fails to satisfy the test-condition.      CODE: 👇 #include <iostream> using namespace std; int main() { int a; //Variable def for(a = 10; a <= 20; a++ ) // (a=10 is initialization statement);(a<=20 is test condition statement);(a++ is increment statement)             ...

//Break and Continue Statement

 //Break and Continue Statement #include<iostream> using namespace std; int main() { int a = 10; //variable def while(a <= 20) { if(a==15) //(a==15)when... //block of code to be executed if the condition is True. { a++;  cout<<"in if statement of a is:"<<a<<endl; //"endl" use for linebreak.  continue;                            //  Continue:-when the loop iterate for the first time the value of i=10, the if statement result will be false, so the else condition 2 is                                    implemented.                      //loop iterates again now i=15; if condition result will be 'True' and the code stop in between and strat new iterate unitl the end condition met.        ...

//Relational(Comparison) Operator

  //Relational(Comparison) Operator #include <iostream> using namespace std; int main() { int a = 21; int b = 10; //int use for integer value. //equal to     if( a == b) // (a=21 == b=10) is False; Therefore a is not equal to b.                //the two given values are equal to each other then result will be True, Otherwise it returns False. { cout <<"a is equal to b" << endl; //"cout" use for print line. } else { cout <<"a is not equal to b" << endl; //"endl" use for linebreak. } //not equal to     if( a != b) // (a=21 != b=10) is True; Therefore a is not equal to b.                // '!'not is True statement consider False and False statement consider to True.     {     cout <<"a is not equal to b" << endl;      }     else     {     cout <<"a is equal...

//Logical Operator

  //Logical Operator #include <iostream> using namespace std; int main() { int a = 50; int b = 30; //int use for integer value. //Logical AND //we use also  Logical NOT if (!((a > b) && (a != b))) // !(a=50 > b=30) is False && (a=50 != b=30) is True; Therefore this statement is False.                            // when both statement are True then result will be True. { cout<<"First statement is true"<<endl; //"cout" use for print line.  } else //when if condition false then else condition executed { cout<<"First statement is false"<<endl; //"endl" use for linebreak. } // Logical OR if ((a < b) || (a != b)) // (a=50 < b=30) is False || (a=50 != b=30) is True; therefore this statement is True.                         //if one(or both) statement is True then result will be True, Otherwis...

// Birwise Operator

  // Birwise Operator #include<iostream> using namespace std; int main() { int a = 50;  //110010 in binary. int b = 30; //11110 in binary. int c = 0; / /int use for integer value. int d = 0; int e = 0; int f = 0; int g = 0; int h = 0; //Bitwise AND  c = a & b; // 110010 & 11110 = 10010 i.e means is '18'. cout<<"the value of AND is:"<<c<<endl; //Bitwise OR d = a | b; // 110010 | 11110 = 111110 i.e means is '62'. cout<<"the value of OR is:"<<d<<endl; //Bitwise Exclusive XOR e = a ^ b; // 110010 ^ 11110 = 101100 i.e means is '44'. cout<<"the value of Exclusive OR is:"<<e<<endl; //Bitwise Complement of a f = ~a; //-(50+1)= i.e means is '-51'. cout<<"the value of Complement is:"<<f<<endl; //Bitwise Shift Left g = a << 2; //50=110010 << 2 :- 11001000 i.e means is '200'. //Shift with 2 zero to left side. cout<<...

//Assignment Operator

//Assignment Operators #include<iostream> using namespace std; int main() { int a = 21; int c = 10; //int use for integer value. //Add AND c += a; //c = c + a; 10 + 21 = 31; cout<<"the addition is :"<<c<<endl; //"cout" use for print line. //Subtract AND c -= a; //c = c - a; 31 - 21 = 10;     cout<<"the substraction is :"<<c<<endl; //"endl" use for linebreak.  //Multiply AND c *= a; //c = c * a; 10 * 21 = 210;     cout<<"the multiplication is :"<<c<<endl; //Divison AND c /= a; // c = c /a; 210/10 = 10;     cout<<"the division is :"<<c<<endl; //Mod AND c %= a; // c = c % a; 10 % 10 =10;     cout<<"the modulus is :"<<c<<endl;   return 0; } //Output:- /* the value of c is :31    the value of c is :10    the value of c is :210    the value of c is :10    the value of c is :10 */ ...

//Arthmatic Operator

//Arthmatic Operator #include <iostream> using namespace std; int main() //'int' datatype  use when which kind of value return in code . { int a = 21; //int use for integer value. int b = 10; int c; //Addition c = a + b; cout<<"line 1 - value of c is :" <<c<< endl;  //"cout" use for print line.  //Subtraction c = a - b; cout<<"line 2 - value of c is :" <<c<< endl; //"endl" use for linebreak.  //Multiplication c = a * b; cout<<"line 3 - value of c is :" <<c<< endl; //Division c = a / b; cout<<"line 4 - value of c is :" <<c<< endl; //Modulus c = a % b; cout<<"line 5  - value of c is :" <<c<< endl; return 0; } //Output /*    the value of c is :31 the value of c is :11 the value of c is :210 the value of c is :2.1 the value of c is :1     */ //Here You Can Execute The Pro...