Pages

Friday, July 19, 2013

Write a program that Print Least Significant Digit in C++

This program print the first digit of an integer read from the keyboard

Souce Code:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  #include <iostream.h>
  #include <conio.h>
  using namespace std;
  // Prototype Declarations
  
  int firstDigit (int num);
  int main ()
  {
     cout << " Enter an integer: ";
     int number;
     cin  >> number;
     int  digit = firstDigit (number);
     cout << " Least Significant digit is: "<< digit << endl;    
     getch();
      return 0;
                 }// main
   /* ============= firstDigit =================
      This function extracts the least significant 
      digit of an integer   
      pre  num contains an integer
      post Returned least significant digit        */              
      int firstDigit (int num)
      {
          return (num % 10);

                            } // firstDigit

Output:


 Enter an integer: 345
 Least Significant digit is: 5

Write a program that Read a Number and Square in C++

This program read a number and print its Square

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    #include <iostream.h>
    #include <conio.h>
    using namespace std;
    
    // Prototype Declarations
    int  getNum   (void);
    int  sqr      (int x);
    void printOne (int x);
    
    int main()
    {
        // Get a number and square it
        int a = getNum ();
        // Square the number just read
        int b = sqr (a);
        // Now print it
        printOne (b);
        // Done. Return to operating system.
        return 0;
                 }//main
        /*   ============= getNum ===============
         Read number from keyboard and return it.
         Pre   nothing 
         Post  number read and returned         */
         int getNum (void)
         {
           cout << " Enter a number to be a squared: ";
           int     numIn;
           cin  >> numIn;  
           return  numIn;
             } //getNum
        /*   =============== sqr ====================
         Return the square of the parameter.
         Pre  x contains number to be squared
         Post squared value returned          */     
         int sqr (int x)
         {
             return (x * x);
             }// sqr
         /*  ============= printOne =================
          print one integer value
          Pre  x contains number to be printed
          Post squared value printed.            */
         
         void printOne (int x)
         { 
              cout << " The value is: " << x << endl;
         getch();
         return;
              } // printOne

OutPut:

 Enter a number to be a squared: 76
 The value is: 5776

Write a program of Void function with a Parameter in C++

This program demonstrates that one function can be called multiple times

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    #include <iostream.h>
    #include <conio.h>
    // Prototype Declarations
       void printOne (int x);
    int main()
    {
      // First call
      int a = 5;
      printOne (a);
      
      // Second Call
      a = 33;
      printOne (a);
      
      // Done. return to operation system.
     return 0;   
        }// main
/*========= printOne ===============
 print one integer value.
       pre x contains number to be printed 
       post value in x printed     */
    void printOne (int x)
    {
         cout << x << endl;
         getch();
         return ;
         } //printOne  

Results:

5
33

Write a program that Sample Program with Subfunction in C++

This program demonstrates funtion calls by calling a small funtion to multiply two numbers

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
      #include <iostream>
      using namespace std;
      #include <conio.h>
      // Prototype Declarations
      int multiply (int num1, int num2);
      
      int main ()
      {
          int multiplier;
          int multiplicand;
       cout << " Enter two integers: \n";   
       cin  >> multiplier >> multiplicand;
          int Product = multiply (multiplier, multiplicand);
       cout << " Product of " <<  multiplier << " & " << multiplicand
       << " is " << Product ;
       getch();
       return 0;
                } // main
       /* ============ Multiply ==============
       Multiply two numbers and return product.
          pre num1 & num2 contains values to be multiplied
          post product retured            */
       
       int multiply (int num1, int num2)
       {
           return (num1 * num2);
                                }//multiply     

OutPut:

Enter two integers: 17  21
Product of 17 & 21 is 357



Tuesday, July 16, 2013

One Click SMS app for Android Cell

 Assalam-O-Alikum

       Today, I've a app for you. One Click SMS

SMS Lover`s App which can also be used as private 
and Network packages SMS Diary and draft messages. 
Smart Phone users need to takes too many clicks to 
send one message again and again and you don`t often 
remember network provider packages activation code and 
messages. So, in this App you just need to save message 
with recipient number and tag. To send message you just 
open the App and click on tag to send the message ... 
Its Simple that was never before.

How it works?
1. Open Menu
2. Click on Add Icon
3. Enter Recipient Message, Number 
   and a Tag text (to remember your message)
4. Click Save
Now each time you open the App,
 you just need 1 click on the tag
  and your message will be send.

Write a program that Demonstrates Numeric Manipulator in C++

This program Demonstrates the use of the Numeric manipulator

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
    #include <iostream.h>
    #include <conio.h>
    #include <iomanip>
    using namespace std;
    int main()
    { 
        int d123 = 123;
  
        cout << "Value in decimal :\t";
        cout << setw(5) << d123 << setw(5) << d123 << endl;
        cout << "Value in hexadecimal: \t" ;
        cout << hex;
        cout << setw(5) << d123 << setw(5) << d123 << endl;
        cout << "Value in octal: \t";
        cout << oct;
        cout << setw(5) << d123 << setw(5) << d123 << endl;  
        cout << "Value in decimal: \t";
        cout << dec;
        cout << setw(5) << d123 << setw(5) << d123 << endl;
        getch ();
        //return 0;
                   } //main

Result:

Value in decimal :    123  123
Value in hexadecimal:    7b   7b
Value in octal:    173  173
Value in decimal:    123  123

Write a program that Demostrates set width manipulator in C++

Demostrates the use of the set width manipulator

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
   #include <iostream.h>
   #include <conio.h>
   #include <iomanip.h>
   using namespace std;

   int main()
   {  
    int   d123 =  123;
    float f123 = 1.23;
    char  chA  = 'A';
    
    cout << "Demostrates the use of the set width manipulator"     << endl;      
    cout << "0...0....1....1"  << endl;
    cout << "1...5....0....5"  << endl;   
    cout << d123 << f123 << chA << "\t          | no width " <<endl;
    cout << setw(1) << d123   << setw(1) << f123  
    << setw(1)  << chA   
    << "\t         | width too small" <<endl ;
    cout << setw(5) << d123   << setw(5) << f123  << setw(5)  << chA   << "\t         | width 5 space to each" <<endl;
     getch();
     return 0;
              }//main

Result:

Demostrates the use of the set width manipulator"     
0...0....1....1
1...5....0....5
1231.23A             | no width 
1231.23A             | width too small
  123 1.23   A       | width 5 space to each

Write a program of Printing Different types with cout in C++

This program denostrates the use of the insertion operator with several different types

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
   #include <iostream.h>
   #include <conio.h>
   //using namespace std;

   int main()
   {   
    // Statments 
    
    cout << "24"                   << endl;      // Print an integer.
    cout << "12.3"                 << endl;      //Print a float.
    cout << "A"                    << endl;      //Print a character.
    cout <<  "Assalam O Alikum!!!" << endl;      //print a string.
    getch();
    return 0;
             } // main

Result:


24
12.3
A
Assalam O Alikum!!!

Write a program of Division with two variable in C++

This program read two integer number from the keyboard and print their division

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
    #include <iostream.h>
    #include <conio.h>
    int main()
    {
    float X, Y, R;
    cout << " Enter two integer: \n";
    cin  >> X >> Y;
    R = X / Y ;
    cout<< "\t"<< X << " / " << Y << " = " << R <<endl;
    getch();
    return 0;
    }

Result:

 Enter two integer: 
225
25
 225 / 25 =  9
 

Monday, July 08, 2013

Write a program of Evaluating Expressions in C++

Evaluating two complex Expressions

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
   #include <iostream.h>
   #include <conio.h>
   int main()
   { 
    int a = 3;
    int b = 4;
    int c = 5;
    int x, y;
    cout << " Initial values of the variable:\n"; 
    cout << "a = " << a << "    b = " << b << "     c = " << c << endl << endl ;
     x = a * 4 + b / 2 - c * b; // Expressions without side effects
     cout << " Value of   a * 4 + b / 2 - c * b    is  : " << x << endl;

    y = --a * (3 + b) / 2 - c++ * b; // Expressions with side effects
    cout << " Value of --a * (3 + b0 / 2 - c++ * b is : " << y << endl;

    cout << "\n Values of the variables are now :\n";
    cout << "a = " << a << "    b = " << b << "     c = " << c << endl ;
    getch ();
    return 0;
               }// main

Output:

 Initial values of the variable:
 a = 3    b = 4    c = 5

 Value of   a * 4 + b / 2 - c * b    is  : -6
 Value of --a * (3 + b0 / 2 - c++ * b is : -13

 Values of the variables are now :
 a = 2    b = 4    c = 5

Write a program of Demonstrate Prefix (unary) Increment in C++



Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
   #include <iostream.h>
   #include <conio.h>
   #include <iomanip.h>
   int main ()
   {
      int a = 4;
    cout << "value of a     : " << setw(2) <<   a << endl;   
    cout << "value of ++a   : " << setw(2) << ++a << endl;   
    cout << "new value of a : " << setw(2) <<   a << endl;   
   getch ();
   return 0;    
              }// main

Output:

value of a     : 4
value of a     : 5
new value of a : 5

Write a program of Demonstrate Postfix Increment in C++


Source Code:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
   #include <iostream.h>
   #include <conio.h>
   #include <iomanip.h>
   int main ()
   {
      int a = 4;
    cout << "value of a     : " << setw(2) << a   << endl;   
    cout << "value of a++   : " << setw(2) << a++ << endl;   
    cout << "new value of a : " << setw(2) << a   << endl;   
   
   getch ();
   return 0;    
              }// main

Output:

value of a     : 4
value of a     : 4
new value of a : 5

Write a program of Precedence in C++


Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
   #include <iostream.h>
   #include <conio.h>
   int main()
   {
    int a = 10;
    int b = 20; 
    int c = 30;
    cout << "a *  b + c   is: " << a *  b + c  << endl;
    cout << "a * (b + c)  is: " << a * (b + c) << endl;
    getch();
    return 0;   
               } // main

Output:

a *  b + c  is: 230
a * (b + c) is: 500


Write a program of Implicit type Conversion in C++


Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
      #include <iostream.h>
      #include <conio.h>
      int main()
      {
        char  aChar = 'A';
        int  printChar;
        int  intNum = 200;
      double fltNum = 245.3;
      
      cout << " aChar contains   : " << aChar << endl;  
      printChar = aChar ;
      cout << "  aChar numeric   : " << printChar << endl;
      cout << " intNum contains  : " << intNum << endl;    
      cout << " fltNum contains  : " << fltNum << endl;
      
      intNum = intNum + aChar; // aChar converted to int
      fltNum = fltNum + aChar; // aChar converted to float
      cout << "\n After addition...\n";
      cout << "  aChar numeric   : " << printChar << endl;
      cout << " intNum contains  : " << intNum << endl;    
      cout << " fltNum contains  : " << fltNum << endl;
       getch ();
       return 0;          
              }// main

Output:

 aChar contains   : A
 aChar numeric   : 65
 intNum contains  : 200
 fltNum contains  : 245.3

 After addition...
 aChar numeric   : 65
 intNum contains  : 265
 fltNum contains  : 310.3

Write a program of Explicit Casts in C++

Demonstrate Casting of Numric Types

Source Code:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
   #include <iostream.h>
   #include <conio.h>
   int main ()
   {
       int intNum1   = 100;
       int intNum2   =  45;
       double fltNum3;
       fltNum3 = static_cast<double> (intNum1 / intNum2);
       cout << "<double> (intNum1 / intNum2)   : " << fltNum3 << endl << endl;
       
       fltNum3 = static_cast<double> (intNum1) / intNum2;
       cout << "<double> (intNum1) / intNum2   : " << fltNum3 << endl;
       getch ();
       return 0;
              }// main

Output:

<double> (intNum1 / intNum2)   : 2
<double> (intNum1) / intNum2   : 2.22222

Write a program that Calculate Quotient and Remainder in C++

Calculate and Print Quotient and Remainder

Source Code:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
   #include <iostream.h>
   #include <conio.h>
   int main()
   {
    int intNum1 ;
    int intNum2 ;
    int intCalc ;
    
    cout << "Enter two integral numbers : ";
    cin  >> intNum1 >> intNum2;
    intCalc = intNum1 / intNum2;
    cout << intNum1 << " / " << intNum2 << " is " << intCalc;
    
    intCalc = intNum1 % intNum2;
    cout << " with a reminder of : " << intCalc << endl;
     getch ();
     return 0;
              } // main

Output:

Enter two integral numbers : 13 2
13 / 2 is 6 with a reminder of : 1

Write a program that Print Rightmost Digit of Integer

Print Rightmost Digit of an Integer

Source Code:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
   #include <iostream.h>
   #include <conio.h>
   int main()
   {
       int intNum;
       cout << " Enter an integral numbers : ";
       cin  >> intNum;
       
       int oneDigit = intNum % 10 ;
       cout << "\nThe right digit is : " << oneDigit << endl; 
       getch();
       return 0;
              } // main

Output:


Enter an integral numbers : 185

The right digit is : 5

Write a program that calculate Average of Four Numbers in C++

Calculate average of four numbers and print the numbers and their deviation from the Average

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
   #include <iostream.h>
   #include <iomanip.h>
   #include <conio.h>
   
   int main ()
   {  
     cout << "\nEnter the First number  : ";
     int num1;
     cin  >> num1 ;
     cout << "\nEnter the Second number : ";
     int num2;
     cin  >> num2 ;
     cout << "\nEnter the Third number  : ";
     int num3;
     cin  >> num3 ;
     cout << "\nEnter the Fourth number : ";
     int num4;
     cin  >> num4 ;
            int sum =  num1 + num2 + num3 + num4;
      float average = sum /4.0 ;
     cout << fixed ;
     cout << showpoint;
     cout << setprecision (2);
     cout << "\n ******** Average is " << average << " ******** \n";
     cout << "\n First  no : " << num1 << " -- Deviation : " << setw(8) << (num1 - average) ;  
     cout << "\n Second no : " << num2 << " -- Deviation : " << setw(8) << (num2 - average) ;
     cout << "\n Third  no : " << num3 << " -- Deviation : " << setw(8) << (num3 - average) ;
     cout << "\n Fourth no : " << num4 << " -- Deviation : " << setw(8) << (num4 - average) ;
       getch();
       return 0;
              }//main

Output:

Enter the first number  : 24

Enter the second number : 56
 
Enter the third number  : 46

Enter the fourth number : 24

******** Average is 37.50 ********

 First  no : 24 -- Deviation :        -13.50
 Second no : 56 -- Deviation :         18.50
 Third  no : 46 -- Deviation :          8.50 
 Fourth no : 24 -- Deviation :        -13.50

Write a program that convert radians to degrees in C++

This program prompts the user to enter an angle in radians and converts it into degrees.

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
   #include <iostream.h>
   #include <conio.h>
   const int cDegreeFactor = 57.295779;
   
   int main()
   {
       cout << " Enter the angle in radians: ";
        double radians;
       cin  >> radians;
       double degrees = radians * cDegreeFactor;
       cout << " " <<radians << " Radians is " << degrees << " Degrees\n";   
    getch ();
    return 0;   
           }// main

Output:

 Enter the angle in radians: 1.578947
 1.578947 Radians is 90 Degrees

Write a program to convert temperature Fahrenheit to Celsius in C++

This program shows how to change a temperature in Farenheit to Celsius
Celsius =  (100 / 180) * (Farenheit - 32)

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
   #include <iostream.h>
   #include <iomanip.h>
   #include <conio.h>
            const float cConversionFactor = 100.0 / 180.0 ;     
   int main()
   {
   cout << " Enter the Temperature in Farenheit : ";         
   float fareh;
   cin  >> fareh;
   float cel = cConversionFactor * ( fareh - 32 );
   cout << fixed;
   cout << showpoint;
   cout << setprecision(1);
   cout << " Farenheit Temperature : " << fareh << endl;
   cout << " Celsius Temperature   : " << cel   << endl;
        getch ();
        return 0;
               }// Main 

Output:

 Enter the Temperature in Farenheit : 98.6
 Farenheit Temperature : 98.6
 Celsius Temperature   : 37.0

Write a program that calculate Sales Total in C++

Calculate the total sale given the unit price , quantity, discount and tax rate

Source Code:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
   #include <iostream.h>
   #include <iomanip.h>
   #include <conio.h>
      const float cTaxRate = 8.50;
   int main ()
   {
     cout << "\n Enter number of items sold:          ";
     int quantity;
     cin  >> quantity;
     cout << " Enter  the unit price:               ";
     float unitPrice;
     cin  >> unitPrice;
     cout << " Enter the Discount Rate (Percent):   ";
     float discountRate;
     cin  >> discountRate;
     
     float subTotal   = quantity     * unitPrice;
     float discountAm = subTotal     * discountRate / 100.0;
     float subTaxable = subTotal     - discountAm;
     float taxAm      = subTaxable   * cTaxRate / 100.0; 
     float total      = subTaxable   + taxAm;
     
     cout << fixed;
     cout << setprecision(2);
     cout << showpoint;
     
     cout << "\n Quantity sold:       " << setw(6) << quantity   << endl;
     cout << " Unit Price of items  " << setw(9) << unitPrice  << endl;
     cout << "             -------------\n";
     cout << "Subtotal :             " << setw(9) << subTotal   << endl;
     cout << "Discount :            -" << setw(9) << discountAm << endl;
     cout << "Discounted Total:      " << setw(9) << subTaxable << endl;
     cout << "Sales Tax :           +" << setw(9) <<    taxAm   << endl;
     cout << "Total sale :           " << setw(9) <<    total   << endl;
       getch();
       return 0;
                } // main

Output:


 Enter number of items sold:          34
 Enter  the unit price:               12.89 
 Enter the Discount Rate (Percent):    7      
 Quantity sold:           34
 Unit Price of items      12.89  
             -------------
Subtotal :                 438.26  
Discount :            -       30.68 
Discounted Total:            407.58
Sales Tax :           +       34.64
Total sale :                 442.23

Write a program that calculate Student Score in C++

Calculate a Student's average score for a course with 4 quizzes, 2 midterms
   and a final. The quizzes are weighted 30%, the midterm 40% and the final 30%

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
   #include <iostream.h>
   #include <iomanip.h>
   #include <conio.h>
   
 const int cQuizWeight    =  30;
 const int cMidtermWeight =  40;
 const int cFinalWeight   =  30;
 const float cQuizMax     = 400.00;
 const float cMidtermMax  = 200.00;
 const float cFinalMax    = 100.00;
 int main ()
  {
   cout << "  =========== QUIZZES ============ \n";
   cout << " Enter the score for the First  quiz: ";
      int  quiz1;
   cin  >> quiz1;
   cout << " Enter the score for the Second quiz: ";
      int  quiz2;
   cin  >> quiz2;
   cout << " Enter the score for the Third  quiz: ";
      int  quiz3;
   cin  >> quiz3;
   cout << " Enter the score for the Fourth quiz: ";
      int  quiz4;
   cin  >> quiz4;       
       
   cout << "\n  =========== MIDTERM ============ \n";
   cout << " Enter the score for the First  midterm: ";
     int  midterm1;
   cin  >> midterm1;      
   cout << " Enter the score for the Second midterm: ";
     int  midterm2;
   cin  >> midterm2;
   cout << "\n  ===========  FINAL  ============ \n";
   cout << " Enter the score for the Final: ";
          int  final;
   cin  >> final;
   cout << endl ;
       
   int totalQuiz       = quiz1 + quiz2 + quiz3 + quiz4 ;
   int totalMidterm    = midterm1 + midterm2 ;
       
   float quizPercent   = static_cast<float>
       (totalQuiz * cQuizWeight) / cQuizMax;
   float midtermPercent= static_cast<float> 
       (totalMidterm * cMidtermWeight) / cMidtermMax;
   float finalPercent  = static_cast<float>
       (final * cFinalWeight) / cFinalMax;
   float totalPercent  = quizPercent + midtermPercent + finalPercent;
       
       cout << fixed;
       cout << showpoint;
       cout << setprecision(1);
       
   cout << " First  Quiz            " << setw(3) << quiz1          << endl;
   cout << " Second Quiz            " << setw(3) << quiz2          << endl;
   cout << " Third  Quiz            " << setw(3) << quiz3          << endl;
   cout << " Fourth Quiz            " << setw(3) << quiz4          << endl;
   cout << " Total  Quiz            " << setw(3) << totalQuiz      << endl << endl;
       
   cout << " First  Midterm         " << setw(3) << midterm1      << endl;
   cout << " Second Midterm         " << setw(3) << midterm2      << endl;
   cout << " Total  Midterm         " << setw(3) << totalMidterm  << endl << endl;
       
   cout << " Final     " << setw(3) << final        << endl << endl;
   cout << " Quiz      " << setw(6) <<    quizPercent  << "%\n";
   cout << " Midterm   " << setw(6) << midtermPercent  << "%\n";
   cout << " Final     " << setw(6) <<   finalPercent  << "%\n";
   cout << " ------------------\n";
   cout << " Total     " << setw(6) <<   totalPercent  << "%\n";
                
       getch();
       return 0;
                } // main

Output:

  =========== QUIZZES ============ 
 Enter the score for the First  quiz: 98
 Enter the score for the Second quiz: 89 
 Enter the score for the Third  quiz:  78
 Enter the score for the Fourth quiz:  79

  =========== MIDTERM ============ 
 Enter the score for the First  midterm: 90
 Enter the score for the Second midterm: 100

  ===========  FINAL  ============ 
 Enter the score for the Final: 92 

 First  Quiz            98
 Second Quiz            89
 Third  Quiz            78
 Fourth Quiz            79
 Total  Quiz           344

 First  Midterm         90
 Second Midterm        100
 Total  Midterm        190

 Final   92

 Quiz      25.8%
 Midterm   38.0%
 Final     27.6%
  ------------------
 Total     91.4% 


Saturday, July 06, 2013

Write a program of Demonstrate Postfix Increment in C++

Demonstrate Postfix Increment

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
   #include <iostream.h>
   #include <conio.h>
   #include <iomanip.h>
   int main ()
   {
      int a = 4;
    cout << "value of a     : " << setw(2) << a   << endl;   
    cout << "value of a++   : " << setw(2) << a++ << endl;   
    cout << "new value of a : " << setw(2) << a   << endl;   
       
       
   getch ();
   return 0;    
              }// main

Output:

value of a     : 4
value of a     : 4
new value of a : 5

Write a program that calculate compound assignment in C++

Demonstrate the example of Compound Assignment

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    #include <iostream.h>
    #include <conio.h>
    int main()
    {  
    int x = 10;
    int y =  5;
    cout << "Demonstrate tha example of Compound Assignment\n";
    cout << "\tEnter two integer values?\n";
    cout << " x: " << x << "     | " << "y: " << y <<"     |"<<" ( x *=y): " << (x *=y) ;
    cout << "   | x is now:"<< x << "\n";
    x=10;
    cout << " x: " << x << "     | " << "y: " << y <<"     | "<<" (x /=y): " << (x /=y) ;
    cout << "   | x is now:"<< x << "\n";
    x=10;
    cout << " x: " << x << "     | "<<"y: " << y <<"     | "<<" (x %=y): " << (x %=y) ;
    cout << "   | x is now:"<< x << "\n";
    getch();
    return 0;
            }//main

Output:

Demonstrate tha example of Compound Assignment
 Enter two Integer Values?
 x: 10   | y: 5 | (x *=y): 50 | x is now: 50
 x: 10   | y: 5 | (x /=y): 2  | x is now: 2
 x: 10   | y: 5 | (x *=y): 0  | x is now: 0

Write a program of Binary Expression in C++

This program demonstrates Binary Expression

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
    #include <iostream.h>
    #include <conio.h>
    int main()
    {   
    int a, b;
    cout <<  "WeLcOmE tO tHe PrOgRaM oF demonstrates binary Expression.!!!!\n";
    cout <<  "\tEnter two Integer Values?\n";
    cin  >>  a >> b;
    cout << a <<" + " << b << " = " << a + b << endl;  
    cout << a <<" - " << b << " = " << a - b << endl;
    cout << a <<" * " << b << " = " << a * b << endl;
    cout << a <<" / " << b << " = " << a / b << endl;
    cout << a <<" % " << b << " = " << a % b << endl;
    cout << "HoPe YoU EnJoY the Demanstration\n";
    getch();
    return 0;
             }// main 

Output:

WeLcOmE tO tHe PrOgRaM oF demonstrates binary Expression.!!!!
 Enter two Integer Values?
84
73
84 + 73 = 157
84 - 73 = 11
84 * 73 = 6132
84 / 73 = 1
84 % 73 = 11 
HoPe YoU EnJoY the Demanstration


Write a program of use the operator (size of) in C++

Use the operator (size of)

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
    #include <iostream>
    #include <conio.h>
    using namespace std;
    int main()
    {
   cout << "Size of char : " << sizeof(char) << endl;
   cout << "Size of int : " << sizeof(int) << endl;
   cout << "Size of short int : " << sizeof(short int) << endl;
   cout << "Size of long int : " << sizeof(long int) << endl;
   cout << "Size of float : " << sizeof(float) << endl;
   cout << "Size of double : " << sizeof(double) << endl;
   getch ();
   return 0;
                 }//main

Output:

Size of char : 1
Size of int : 4
Size of short int : 2
Size of long int : 4
Size of float : 4
Size of double : 8


Friday, July 05, 2013

Write a program that Area of a Trapezoid in C++

Write a program to find the  Area of a trapezoid?
Area of a trapezoid =(1/2)* (a+b)* h;
                           h = vertical height

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
       #include <iostream.h>
       #include <conio.h>
       int main()
       {   
           float A, a, b, h;
           cout << "Area of a trapezoid Formula: A =(1/2)* (a+b)* h\n";
           cout << "\tEnter the value of a?\n";
           cin  >> a ;
           cout << "\tEnter the value of b?\n";
           cin  >> b ;
           cout << "\tEnter the value of h?\n";
           cin  >> h;
           a = a + b;
           h = h * a;
           A = h * 0.5;
           cout << " \tArea of a trapezoid = " << A << " m^2 " << endl; 
           getch();
           return 0;
                  } // end main

Output:

       Area of a trapezoid Formula: A =(1/2)* (a+b)* h                  
       Enter the value of a?
46
       Enter the value of b?
52
       Enter the value of h?
3
       Area of a trapezoid = 147 m^2

Write a program to find Area of a Triangle in C++

Area of a Triangle Formula: A = (1/2) * b * h

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
    #include <iostream.h>
    #include <conio.h>
    int main()
    { 
     float b, h, c, A;   
     cout << " Area of a Triangle Formula: A = (1/2) * b * h\n";   
     cout << " Enter the value of b <base>?\n";
     cin  >> b;
     cout << " Enter the value of h <height>?\n";
     cin  >> h;
       b  = b * h;
       A  = b * 0.5;
     cout << " Area of a Triangle = " << A << " m^2 "<< endl;     
     getch();
     return 0;
            } // end main

Output:

 Area of a Triangle Formula: A = (1/2) * b * h
 Enter the value of b <base>?
4
 Enter the value of h <height>?
7
 Area of a Triangle = 14 m^2

Write a program to find Area of a Circle in C++

Area of a Circle Formula: pi * r ^ 2

Source Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    #include <iostream.h>
    #include <conio.h>
    int main()
    {   
    float A, r, r2, pi;
    cout << "Area of a Circle Formula: pi * r ^ 2\n";
    cout << "Enter the value of r?\n";
    cin  >> r;
     pi   = 3.1415;
     r2   = r * r;
     A    = r2 * pi;
    cout << "\tArea of a Circle = " << A << " m^2 "<< endl;
    getch();
    return 0;
           }//end main

Output:

Area of a Circle Formula: pi * r ^ 2
Enter the value of r?
4
 Area of a Circle = 50.246 m^2