Posts

Showing posts from March, 2024

Control Structures, If Else and Switch Case Statements in C++

  #include <iostream> using namespace std ; int main () {     int age ;     cout << "Tell me your age" << endl ;     cin >> age ;     //  Selection control structure : If else-if else ladder     if (( age < 18 ) && ( age > 0 ))     {         cout << "You can not come to my party" << endl ;     }     else if ( age == 18 )     {         cout << "You are a kid and you will get a kid pass to the party" << endl ;     }     else if ( age < 1 )     {         cout << "You are not yet born" << endl ;     }     else     {         cout << "You can come to the party" << endl ;     }     //  Selection control structure : Switch case statements ...

Constants, Manipulators and Operator Precedence in C++

  #include <iostream> #include <iomanip> using namespace std ; int main () {     // int a = 34;     // cout<<"The value of a is : "<<a<<endl;     // a = 42;     // cout<<"The value of a is : "<<a<<endl;     // cout<<endl;     //  Constants in C++     // const int b = 22;   //Since const, We can't change the value of b here     // cout<<"The value of b is : "<<b<<endl;     // b = 78;  //You will get an Error because b is constant     // cout<<"The value of b is : "<<b<<endl;     // Manipulators in C++     int a = 3 , b = 78 , c = 2387 ;     cout << "The value of a without setw is : " << a << endl ;     cout << "The value of b without setw is : " << b << endl ;     cout << "The valu...

Reference Variables and Typecasting in C++

  #include <iostream> using namespace std ; int c = 45 ; int main () {     // *****************Build in Data types******************     int a , b , c ;     cout << "Enter the value of a : " << endl ;     cin >> a ;     cout << "Enter the value of b : " << endl ;     cin >> b ;     c = a + b ;     cout << "The Sum is : " << c << endl ;     //  To take the value of Global variable, scope resolution operator :: is used     //  5as shown below :     cout << "The Global value is : " << :: c << endl ;     //************ Float, double and long double Literals ****************     float d = 34.4 ;     long double e = 34.4 ;     cout << "The value of d is : " << d << endl << "The value of e is : " << e <...

Header Files and Operators in C++

  //1. System header files : It comes with the compiler #include <iostream> using namespace std ; //  There are two types of header files : //1. System header files : It comes with the compiler //2. User defined header files : It is written by the programmer //  #include "this.h" --> This will produce an error if this.h is not present // in the current directory. int main () {     int a = 4 , b = 5 , c = 123 , d = 40 ;     cout << "Hello World \n " ;     cout << "Operators in C++ :" << endl ;     cout << "Following are the types of operators in C++" << endl ;     //  Arithmetic operators     cout << "The value of a + b is " << a + b << " \n " ;     cout << "The value of a - b is " << a - b << endl ;     cout << "The value of a * b is " << a * b << " \n " ;     cout << "...

Basic Input & Output with C++

#include <iostream> using namespace std ; int main () {     //"<<" is called Insertion operator     //">>" is called Extraction operator     int num1 , num2 ;     cout << "Enter the value of Number 1 : \n " ;     cin >> num1 ;     cout << "Enter the value of Number 2 : \n " ;     cin >> num2 ;     cout << "Sum of numbers is : " << num1 + num2 ;     return 0 ; } //OUTPUT: // Enter the value of Number 1 : // 60 // Enter the value of Number 2 : // 40 // Sum of numbers is : 100