BCS-1A

Tuesday, January 17, 2012

Nested Loops


Nested Loops
We have seen the advantages of using various methods of iteration, or looping.
Now let's take a look at what happens when we combine looping procedures. 
     The placing of one loop inside the body of another loop is called nesting.  When you "nest" two loops, the outer loop takes control of the number of complete repetitions of the inner loop.  While all types of loops may be nested, the most commonly nested loops are for loops.

nested loops
    
Let's look at an example of nested loops at work.
We have all seen web page counters that resemble the one shown below ( well, OK, maybe not quite this spastic!!).  Your car's odometer works in a similar manner.
This counter (if it worked properly) and your car's odometer are little more than seven or eight nested for loops, each going from 0 to 9.  The far-right number iterates the fastest, visibly moving from 0 to 9 as you drive your car or increasing by one as people visit a web site.  A for loop which imitates the movement of the far-right number is shown below:
for(num1 = 0; num1 <= 9; num1++)
{
      cout << num1 << endl;
}
     The far-right number, however, is not the only number that is moving.  All of the other numbers are moving also, but at a much slower pace.  For every 10 numbers that move in the column on the right, the adjacent column is incremented by one.  The two nested loops shown below may be used to imitate the movement of the two far-right numbers of a web counter or an odometer:
The number of digits in the web page counter or the odometer determine the number of nested loops needed to imitate the process.
     
When working with nested loops, the outer loop changes only after the inner loop is completely finished(or is interrupted.).
Let's take a look at a trace of two nested loops.  In order to keep the trace manageable, the number of iterations have been shortened.
for(num2 = 0; num2 <= 3;  num2++)
{
      for(num1 = 0; num1 <= 2; num1++)
      {
            cout<< num2<< "   " << num1<< endl;
      }
}
       
MemoryScreen
int num2 int num1
00
1
2
3  end loop
10
1
2
3  end loop
20
1
2
3  end loop
30
1
2
3  end loop
4  end loop
    Remember, in the memory, for loops will register a value one beyond (or the step beyond) the requested ending value in order to disengage the loop.
0   0
0   1
0   2
1   0
1   1
1   2
2   0
2   1
2   2
3   0
3   1
3   2
Are we getting a little loopy?

Saturday, January 14, 2012

The for loop


The for loop
The statements in the for loop repeat continuously for aspecific number of times.  The while and do-while loops repeat until a certain condition is met.  The for loop repeats until a specific count is met.  Use a for loop when the number of repetition is know, or can be supplied by the user.  The coding format is:
for(startExpression; testExpression; countExpression)
{
    block of code;

}
The startExpression is evaluated before the loop begins.  It is acceptable to declare and assign in the startExpression(such as int x = 1;).  This startExpression is evaluated only once at the beginning of the loop.
The testExpression will evaluate to TRUE (nonzero) orFALSE (zero).  While TRUE, the body of the loop repeats.  When the testExpression becomes FALSE, the looping stops and the program continues with the statement immediately following the for loop body in the program code.
The countExpression executes after each trip through the loop.  The count may increase/decrease by an increment of 1 or of some other value. 
Braces are not required if the body of the for loop consists of only ONE statement.  Please indent the body of the loop for readability.
CAREFUL:  When a for loop terminates, the value stored in the computer's memory under the looping variable will be "beyond" the testExpression in the loop.  It must be sufficiently large (or small) to cause a false condition.  Consider:

for (x = 0; x <= 13; x++)
     cout<<"Melody";
When this loop is finished, the value 14 is stored in x.

The following program fragment prints the numbers 1 - 20. 



for:
int ctr;
for(ctr=1;ctr<=20; ctr++)
{
     cout<< ctr <<"\n";
 

Common Error:  If you wish the body of a for loop to be executed, DO NOT put a semicolon after thefor's parentheses.  Doing so will cause the forstatement to execute only the counting portion of the loop, creating the illusion of a timing loop.  The body of the loop will never be executed.

Semicolons are requiredinside the parentheses of thefor loop.  The for loop is theonly statement that requires such semicolon placement.


Friday, January 13, 2012

The do-while loop


The do-while loop
The do-while loop is similar to the while loop, except that the test condition occurs at the end of the loop.  Having the test condition at the end, guarantees that the body of the loop always executes at least one time.  The format of the do-while loop is shown in the box at the right.
The test condition must be enclosed in parentheses andFOLLOWED BY A SEMI-COLON.  Semi-colons also follow each of the statements within the block.  The body of the loop (the block of code) is enclosed in braces and indented for readability.  (The braces are not required if only ONE statement is used in the body of the loop.)
The do-while loop is an exit-condition loop.  This means that the body of the loop is always executed first.  Then, the test condition is evaluated.  If the test condition is TRUE, the program executes the body of the loop again.  If the test condition is FALSE, the loop terminates and program execution continues with the statement following the while.
/*The following program fragment is an input routine that insists that the user type a correct response -- in this case, a small case or capital case 'Y' or 'N'.  The do-while loop guarantees that the body of the loop (the question) will always execute at least one time.*/
char ans;
do
{
       cout<< "Do you want to continue (Y/N)?\n";
       cout<< "You must type a 'Y' or an 'N'.\n";
       cin >> ans;
}

while((ans !='Y')&&(ans !='N')&&(ans !='y')&&(ans !='n'));
/*the loop continues until the user enters the correct response*/
 
FORMAT:
do
{
     block of code;
}
while (test condition);







exit condition loop

 

The while loop


The while loop
The while loop allows programs to repeat a statement or series of statements, over and over, as long as a certain test condition is true.  The format is shown in the box to the right.
The test condition must be enclosed in parentheses.  The block of code is called the body of the loop and is enclosed in braces and indented for readability.  (The braces are not required if the body is composed of only ONE statement.)  Semi-colons follow the statements within the block only.
When a program encounters a while loop, the test condition is evaluated first.  If the condition is TRUE, the program executes the body of the loop.  The program then returns to the test condition and reevaluates.  If the condition is still TRUE, the body executes again.  This cycle of testing and execution continues until the test condition evaluates to 0 or FALSE.  If you want the loop to eventually terminate, something within the body of the loop must affect the test condition.  Otherwise, a disastrous INFINITE LOOP is the result!  ;-(
The while loop is an entry-condition loop.  If the test conditionis FALSE to begin with, the program never executes the body of the loop.
The following program fragment prints and counts the characters of a string array:
apstring name="Corky";
i = 0;            //begin with the first cell of array
while (i< name.length( ))    // loop test condition
{
      cout<< name[ i ] << endl;  //print each character
      i++;                            //increment counter by 1
}
cout << "There are " << i << " characters.\n";
\*This last cout prints when the test condition is false and the loop terminates*\


FORMAT:
while(test condition)
{
     block of code;
}





iteration - doing the same thing again and again.

 

Conditional Operator


Conditional Operator
  You can exchange simple if-else code for a single operator – the conditional operator.  The conditional operator is the only C++ ternary operator (working on three values).  Other operators you have seen are called binary operators (working on two values).
FORMAT: 
conditional Expression ? expression1 :expression2;
  ** if the conditional Expression is trueexpression1executes, otherwise if the conditional Expression is false,expression 2 executes. 
If both the true and false expressions assign values to the same variable, you can improve the efficiency by assigning the variable one time:
(a>b) ? (c=25) : (c=45); 
can be written as:
c = (a>b) ? 25 : 45;
 

 
if (a>b)
{
       c=25;
 }
 else
{
       c=45;
 }

can be replaced with
(a>b) ? (c=25) : (c=45);

The question mark helps the statement read as follows:
"Is a greater than b?  If so, put 25 in c.  Otherwise, put 45 in c."

Increment and Decrement Operators


Increment and Decrement Operators
Adding or subtracting 1 from a variable is a very common programming practice.  Adding 1 to a variable is calledincrementing and subtracting 1 from a variable is calleddecrementing.
  • increment and decrement operators work only with integer variables -- not on floating point variables or literals.
  • the C++ compiler is controlling the execution of the prefix and postfix operators.  You cannot change this order of execution.  For example, the parentheses below will not force an early execution:
    value = (((x--)))* num;   //still decrements x last.
  • one disadvantage of using the increment/decrement operators is that the variable can only be incremented or decremented by the value ONE.  If you need to increment (or decrement) by a larger (or smaller) value, you must use statements like
     m += 2;  or  amount -= 5;
  • be careful when combining increment and decrement operators inside expressions with logical operators.  If in doubt, don't use them together.  For example, do NOT use:
    if (( num1 = = 4 ) || ( num2 != ++j)) (j may not be incremented when (num1 = = 4) is TRUE.)Instead, separate the code to avoid this problem:
    ++j;
    if (( num1 = = 4) || (num2 != j))



All are the same:i = i + 1;
 i += 1;
i++;



Prefix: 
++i;
--i;
increment or decrement occurs 
before the variable's value is used in the remainder of the expression.


Postfix:
i++;
i--;
increment or decrement occurs 
after the variable's value is used in the remainder of the expression.

Student marks(while loop)


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n,
    i;
double sum,
       marks;
cout<<"Enter total number of Students :";
cin >>n;
i=1;
while(i<=n)
{
cout<<"Enter marks of Student "<<i<<":";
cin >>marks;
sum=sum+marks;
i++;          
}
cout<<"The sum is :"<<sum;
    getch();
    return 0;
}

Coulumb's Fource and Gravitational Force(do_while loop)


/*******************************************************
  Name: Coulumb's Fource and Gravitational Force
  Copyright: BCS-1A
  Author: Mohammad Hussnain Imtiaz
  Date: 12/01/12 00:08
  Description: USE OF DO WHILE AND SWITCH
********************************************************/
 // PREPROCESSER DIRECTICE
 #include<iostream>
 #include<conio.h>
 #include<cmath>

 using namespace std ;

 int main ()
 {
     // LOCAL DECLARATION
 double q1=0.0,
        q2=0.0,
        cRadius=0.0,
        F=0.0,
        k=pow(9.0*10,9),
        m1=0.0,
        m2=0.0,
        Fg=0.0,
        G=pow(6.674*10,-11),
        gRadius=0.0;
 int choice=0;
 char choice2 ;
        cout << "Program to calculate Coulumb's Fource & Gravitational Force\n" ;
     do
     {
        cout<< "\n\nPress 1 to calculate Coulumb's Force\n2 to calculate Gravitational Force ? " ;
        cin >> choice;
       
        switch (choice)
        {
        case 1:
        cout << "Enter the value of q1 :" ;
        cin  >> q1;
        cout << "Enter the value of q2 :" ;
        cin  >> q2;
        cout << "Enter   the    Radius :" ;
        cin  >> cRadius;
       
        F = (k * ( (q1*q2)/(pow(cRadius,2 ))));
        cout << "The Coulumb's Force is :" << F ;
        break ;
       
        case 2:
        cout << "Enter the value of m1 :" ;
        cin  >> m1;
        cout << "Enter the value of m2 :" ;
        cin  >> m2;
        cout << "Enter   the    Radius :" ;
        cin  >> gRadius;
       
        Fg = (G * ( (m1*m2)/(pow(gRadius,2 ))));
        cout << "The Gravitational Force is :" << Fg ;
        break ;
       
        default :
        cout << "You enter invalid Selection." ;
        } // end of switch statmant
        cout << "\n\n\nFor the continution of program (y/n)? ";
        cin  >> choice2 ;
        system("CLS");
        }while (choice2 == 'Y' || choice2 == 'y');
          system ("CLS");
 cout << "\n\n\n\n\n\n\n\n\n  "
      << "                    "
      << "Created By:Mohammad Hussnain Imtiaz" ;
 getch();
 return 0;  
 } // end of main function

Calculate AM,GM and HM(for loop)


/***********************************************************
  Name: Calculate AM,GM and HM
 
  Copyright: BCS-1A
 
  Author: Muhammad Hussnain Imtiaz
 
  Date: 27/12/11 16:29
 
  Description: Program To calculat Arithmatic Mean,
                 Geomatric Mean and Harmonic Mean
***********************************************************/
// preprocesser directive
 #include<iostream>
 #include<conio.h>
 #include<cmath>
 using namespace std;
 int main()
 {
     // Local declaration
     double number       =0.0,
            sum          =0.0,
            product      =1.0,
            sumReciprocal=0.0,
            AM=0.0,
            GM=0.0,
            HM=0.0;
     int i=0,
         n=0,
         code;

     cout << "  Program To calculat Arithmatic Mean, Geomatric Mean and Harmonic Mean"
             <<endl<<endl ;
    for (i=1; code != 12345 ; i++)  // 1st for loop, just for lock
{
            cout << "\n                       Enter code :";
            cin  >> code ;
            system ("CLS");
            if (code == 12345) // 1st if loop for lock
               {
     cout << "                How many numbers you want to enter :" ;
     cin  >> n;
     cout<<endl;
     for (i=1; i<=n; i++)
     {
         cout << "                    Enter number " << i << ":";
         cin  >> number;
         sum = sum+number;
         product=product*number;
         sumReciprocal=sumReciprocal+(1.0/number);
     }// end of for loop
 // Counting AM,GM and HM
     AM=sum/n;
     GM=pow(product,1.0/n);
     HM=n/sumReciprocal;
         cout <<endl
              <<endl
              <<endl
              << "                    Arithmatic Mean :" << AM << endl;
         cout << "                    Geomatric  Mean :" << GM << endl;
         cout << "                    Harmonic   Mean :" << HM << endl;
         cout <<endl
              <<endl
              << "                     Press any key" ;
     getch();
               } // end of if
            else
               {
                cout << "          "
                     << "you enter invalid code, press 'Enter' to retry." ;
                getch();
               }
 } // end of for loop (Lock)
   
     system ("CLS");
     cout <<endl
          <<endl
          <<endl
          <<endl
          <<endl
          << "                 Created By:Mohammad Hussnain Imtiaz" ;
            getch ();
            return 0;
 }// end of main function

Monday, January 02, 2012

counting character


/*******************************************
  Name: Counting characters
 
  Copyright: BCS-1A
 
  Author: Muhammad Hussnain Imtiaz
 
  Date: 26/12/11 23:11
 
  Description:
********************************************/

//preprocesser directive
#include<iostream>
#include<conio.h>
using namespace std ;
int main ()
{
    //local declaration
 int counter =0;  
    cout << " Enter # at the end of your paragraph\n        Don't press 'Enter'\n\n" ;
    while ( getche() != '#' )
    {
       counter++ ;
    }
    cout << "\n\n          You press " << counter << " times" ;
    cout << "\n            Press any key" ;
    getch () ;
 system ("CLS");
 cout << "\n\n\n\n\n\n\n\n\n                  Created By:Mohammad Hussnain Imtiaz" ;

    getch ();
    return 0;
}// end of main function

Saturday, December 31, 2011

Greater or Less then in Giver three Numbers


/*****************************************************
  Name: Three number calculator
 
  Copyright: BCS-1A
 
  Author:Muhammad Hussnain Imtiaz
 
  Date: 20/12/11 22:07
 
  Description: To calculate three numbers
*******************************************************/

  // preprocesser directive
 # include <iostream>
 # include <conio.h>

 using namespace std ;

 int main ()
{
// local declaration
float num1 = 0.0 ,
      num2 = 0.0 ,
      num3 = 0.0 ,
      sum  = 0.0 ,
      ;



    cout <<        "                  Welcome             " << endl << endl ;


    cout <<        "      Please Enter First  Number  :   " ;
    cin  >> num1 ;
    cout << endl <<"      Please Enter Second Number  :   " ;
    cin  >> num2 ;
    cout << endl <<"      Please Enter Third  Number  :   " ;
    cin  >> num3 ;
    cout << endl ;
       

    sum = num1 + num2 + num3 ;
   
    cout <<          "           The     sum   is :   " << sum << endl << endl ;
   
   
   
    if ( num1 == num2 && num2 == num3 )
    {
       cout <<       "              All no. are equal         " ;    
    }
   
   
    if ( num1 != num2 && num2 != num3 )
    {
       cout << "          Input numbers are not equle   " << endl ;
    }
   
   
    if ( num1 > num2 && num1 > num3 )
    {
       cout << "               " << num1 << " > " << num2 << " and " << num3 << "\n" ;
    }
   
   
    if ( num2 > num3 && num3 > num1 )
    {
       cout << "               " << num2 << " > " << num1 << " and " << num3 << "\n" ;
    }
   
   
    if ( num3 > num1 && num1 > num2 )
    {
       cout << "               " << num3 << " > " << num1 << " and " << num2 << "\n" ;
    }
   

    if ( num1 < num2 && num1 < num3 )
    {
       cout << "               " << num1 << " < " << num2 << " and " << num3 << "\n" ;
    }

   
    if ( num2 < num3 && num3 < num1 )
    {
       cout << "               " << num2 << " < " << num1 << " and " << num3 << "\n" ;
    }
   

    if ( num3 < num1 && num1 < num2 )
    {
       cout << "               " << num3 << " < " << num1 << " and " << num2 << "\n" ;
    }
   
   
    if ( num1 == num2 && num1 > num3 )
    {
       cout << "First number = Second number but " << num3 << " < First and Second number \n" ;
    }
   

    if ( num2 == num3 && num2 > num1 )
    {
       cout << "Second number = Third number but " << num1 << " < Second and Third number \n" ;
    }
   

    if ( num3 == num1 && num3 > num2 )
    {
       cout <<  "First number = Third number but " << num2 << " < First and Third number \n" ;
    }
   
 
    if ( num1 == num2 && num1 < num3 )
    {
       cout << "First number = Second number but " << num3 << " > First and Second number \n" ;
    }
   

    if ( num2 == num3 && num2 < num1 )
    {
       cout << "Second number = Third number but " << num1 << " > Second and Third number \n" ;
    }
   

    else if ( num3 == num1 && num3 < num2 )
    {
       cout << "First number = Third number but " << num2 << " > First and Third number \n" ;
    }
   

    else
    {
       cout << endl << "        " ;
    }
   
       cout << endl << "                   T h a n k s               " ;
     
    cout << "\n\n\n\n\n\n      Created By : Mohammad Hussnain Imtiaz " ;

 
  getch () ;
  return 0 ;
} // end of main function

Program Using Lock


/***********************************************************
  Name: Calculate AM,GM and HM
 
  Copyright: BCS-1A
 
  Author: Muhammad Hussnain Imtiaz
 
  Date: 27/12/11 16:29
 
  Description: Program To calculat Arithmatic Mean,
                 Geomatric Mean and Harmonic Mean
***********************************************************/
// preprocesser directive
 #include<iostream>
 #include<conio.h>
 #include<cmath>
 using namespace std;
 int main()
 {
     // Local declaration
     double number       =0.0,
            sum          =0.0,
            product      =1.0,
            sumReciprocal=0.0,
            AM=0.0,
            GM=0.0,
            HM=0.0;
     int i=0,
         n=0,
         code;

     cout << "  Program To calculat Arithmatic Mean, Geomatric Mean and Harmonic Mean"
             <<endl<<endl ;
    for (i=1; code != 12345 ; i++)  // 1st for loop, just for lock
{
            cout << "\n                       Enter code :";
            cin  >> code ;
            system ("CLS");
            if (code == 12345) // 1st if loop for lock
               {
     cout << "                How many numbers you want to enter :" ;
     cin  >> n;
     cout<<endl;
     for (i=1; i<=n; i++)
     {
         cout << "                    Enter number " << i << ":";
         cin  >> number;
         sum = sum+number;
         product=product*number;
         sumReciprocal=sumReciprocal+(1.0/number);
     }// end of for loop
 // Counting AM,GM and HM
     AM=sum/n;
     GM=pow(product,1.0/n);
     HM=n/sumReciprocal;
         cout <<endl
              <<endl
              <<endl
              << "                    Arithmatic Mean :" << AM << endl;
         cout << "                    Geomatric  Mean :" << GM << endl;
         cout << "                    Harmonic   Mean :" << HM << endl;
         cout <<endl
              <<endl
              << "                     Press any key" ;
     getch();
               } // end of if
            else
               {
                cout << "          "
                     << "you enter invalid code, press 'Enter' to retry." ;
                getch();
               }
 } // end of for loop (Lock)
   
     system ("CLS");
     cout <<endl
          <<endl
          <<endl
          <<endl
          <<endl
          << "                 Created By:Mohammad Hussnain Imtiaz" ;
            getch ();
            return 0;
 }// end of main function

Thursday, December 29, 2011

More than 2 Numbers Add


/*******************************************************
*  Name: Add more than 2 numbers                       *
*                                                      *
*  Copyright: BCS-1A                                   *
*                                                      *
*  Author: Muhammad Hussnain Imtiaz                    *
*                                                      *
*  Date: 21/12/11 23:07                                *
*                                                      *
*  Description: Program to add more than 2 numbers     *
*******************************************************/

// preprocessor directive
#include<iostream>
#include<conio.h>
using namespace std ;
int main ()
{
    // Local declaration
    int marks =0 ,
        i        ,
        sum   =0 ,
        code  =0 ,
        ;
    double n      =0.0 ,
           average=0.0 ,
           ;
    cout << "          How much numbers you want to enter numbers: " ;
    cin  >> n ;
    cout << endl << endl ;
    for (i=1 ; i<=n ; i++)   // 1st for loop start
    {
    cout << "                     Enter Number " << i << ":" ;
    cin  >> marks ;
    }
        sum = sum+marks ;
    cout << "\n             System add them and their addition is " << sum  ;
        average = sum/n ;
    cout << "\n                    Their Average is " << average ;
    getch();
for (i=1; code != 12345; i++)  // 2nd for loop, just for lock
{
    system ("CLS");
    cout << "\n                  Press exit code :";
    cin  >> code ;
    if (code == 12345)
{  
     system ("CLS");
     cout << "\n\n\n\n\n\n\n\n\n\n\n     "
          << "              Created By:Mohammad Hussnain Imtiaz   " ;
} // End of if
    else
{
     cout << "          you enter invalid code, press 'Enter' to retry." ;
     getch();
}
}// end of for
   
getch () ;  
return 0 ;
} // end of main function

Wednesday, December 28, 2011

Program That judge your Age


#include <iostream>

using namespace std;

int main()                            // Most important part of the program!
{
  int age;                            // Need a variable...
 
  cout<<"Please input your age: ";    // Asks for age
  cin>> age;                          // The input is put in age
  cin.ignore();                       // Throw away enter
  if ( age < 100 )                   // If the age is less than 100
 {  
cout<<"You are pretty young!\n"; // Just to show you it works...
  }
  else if ( age == 100 )             // I use else just to show an example
  {
     cout<<"You are old\n";           // Just to show you it works...
   }
  else
   {
    cout<<"You are really old\n";     // Executed if no other statement is
   }
  cin.get();
}

Bill of Electric Store


/*****************************************************
  Name: To calculate custmer's bill
 
  Copyright: open source
 
  Author: Muhammad Hussnain Imtiaz
 
  Date: 20/12/11 12:55
 
******************************************************/

 # include <iostream>
 # include <conio.h>

 using namespace std ;

 int main ()
 {
 double unitPriceTV               = 400.00 ,
        unitPriceDVDPalyer        = 300.00 ,
        unitPriceRemoteController = 35.20  ,
        unitPriceCDPlayer         = 220.00 ,
        unitPriceTapeRecoder      = 150.00 ,
        sum1                      = 0.0    ,
        sum2                      = 0.0    ,
        ;
       
 int noOfTV              =0 ,
     noOfDVDPalyer       =0 ,
     noOfRemoteController=0 ,
     noOfCDPlayer        =0 ,
     noOfTapeRecoder     =0 ,
     ;
   
     cout << " Please    Enter    The   number   of    TV   : " ;
     cin  >> unitPriceTV     ;
   
     cout << " Please   Enter  The  number  of  DVD Palyer  : " ;
     cin  >> noOfDVDPalyer   ;
   
     cout << " Please Enter The number of Remote Controller : " ;
     cin  >> noOfCDPlayer    ;
   
     cout << " Please  Enter  The  number  of  CD    Player : " ;
     cin  >> noOfCDPlayer    ;
   
     cout << " Please  Enter  The  number  of Tape Recoder  : " ;
     cin  >> noOfTapeRecoder ;
   
     sum1 = (unitPriceTV * noOfTV) + (unitPriceDVDPalyer * noOfDVDPalyer) + (unitPriceRemoteController * noOfRemoteController) + (unitPriceCDPlayer * noOfCDPlayer) + (unitPriceTapeRecoder * noOfTapeRecoder) ;
     cout << " \n       Your bill with out  tax is : " << sum1 << "$";
   
   
     sum2 = (sum1 / 100.00) * 8.25 + sum1 ;
     cout << " \n\n              We add 8.25% sales tax "             ;
     cout << " \n       Your bill including tax is : " << sum2 << "$";
   
   
     cout << " \n\n     .................Thanks................." ;
   
     cout << " \n\n\n\n\n\n\n\n\n\n      Created By : Mohammad Hussnain Imtiaz  " ;
     getch () ;
     return 0 ;
 }

Area of Triangle Calculator


/*****************************************************
  Name: Area of triangle Calculator
 
  Copyright: BCS-1A
 
  Author: Muhammad Hussnain Imtiaz
 
  Date: 21/12/11 23:46
 
  Description: Porgram to calculate area of triangle
******************************************************/

 # include <iostream>
 # include <conio.h>
 # include <cmath>
 using namespace std ;

 int main ()
 {
// local declaration
 double    a=0.0,
           b=0.0,
           c=0.0,
        area=0.0,
           s=0.0,
           ;
           cout << "        Area of Triangle calculater     " << endl << endl ;
           cout << " Enter 'y' to continue and 'n' to exit :" ;
while (getche() != 'n')
{
           system("CLS");
           cout << endl << endl;
           cout << " Please Enter the side-1 of Triangle :" ;
           cin  >> a ;
           cout << " Please Enter the side-2 of Triangle :" ;
           cin  >> b ;
           cout << " Please Enter the side-3 of Triangle :" ;
           cin  >> c ;
if( a+b>c && b+c>a && c+a>b )          
   {
     s=(a+b+c)/2.0 ;
     area=sqrt ((s*(s-a)*(s-b)*(s-c))) ;
           cout << "\n\n\n     The Area of Triangle is: " << area ;          
           if (a==b && b==c)
           {
           cout << "\n\nAll Sides of Triangle are equal in length" ;
           }
           if (a>b && a>c)
           {
           cout << "\n\n  Side-1 is Greater than other sides" ;
           }
           if (b>a && b>c)
           {
           cout << "\n\n  Side-2 is Greater than other sides" ;
           }
           if (c>a && c>b)
           {
           cout << "\n\n  Side-3 is Greater than other sides" ;
           }
           if (a<b && a<c)
           {
           cout << "\n\n     Side-1 is Less than other sides" ;
           }
           if (b<a && b<c)
           {
           cout << "\n\n     Side-2 is Less than other sides" ;
           }
           if (c<a && c<b)
           {
           cout << "\n\n     Side-3 is Less than other sides" ;      
           }
           cout << "\n\n\n  Enter 'y' to continue and 'n' to exit :" ;
   }// End of if
   else
   {
           cout << "\n        Triangle is not Constructed" ;
           cout << "\n\n\n  Enter 'y' to continue and 'n' to exit :" ;
   }//end of else
}// end of while
           system ("CLS");
           cout << "\n\n\n\n\n\n\n\n\n\n\n\n               "
                << "   Created By:Mohammad Hussnain Imtiaz " ;
     getch ();
     return 0;  
 }// end of main function

Greater or Less then in Giver 3 Numbers


/*
   multi purpuse program (which number is < or > then other no. in giver three numbers)
*/

// preprocessor directives
# include <iostream>
# include <conio.h>
using namespace std ;

//start main function here
int main ()
{

    cout << "            Welcome           " << endl << endl ;

    //local diclaration
  double num1 = 0.0 ,   //first integer value
         num2 = 0.0 ,   //second integer value
         num3 = 0.0 ,   //third integer value
        ;
       
        //input three integer numbers
        cout << endl << "     Enter First  No.  :" ;
        cin  >> num1;
       
        cout << endl << "     Enter Second No.  :" ;
        cin  >> num2 ;
       
        cout << endl << "     Enter Third  No.  :" ;
        cin  >> num3 ;
       
        if ( num1 > num2 && num1 > num3 )
    {      
        cout << endl << endl
             << "\""    //   ( \" is used to print " )
             << num1
             << "\""
             << "    Is greater than " << num2 << " and " << num3
             << endl << endl
             << "            THANKS          "
             ;    
    }
   
         else if ( num2 > num1 && num2 > num3 )
    {
        cout << endl << endl
             << "\""
             << num2
             << "\""
             << "  Is greater than " << num1 << " and " << num3
             << endl << endl
             << "            THANKS          "
             ;
    }
   
        else
    {
        cout << endl
             << endl
             << "\""
             << num3
             << "\""  
             << "  Is greater than " << num1 << " and " << num2
             << endl
             << endl
             << "            THANKS          "
             ;
    }
        cout << "\n\n\n\n\n\n\n\nCreated By:Mohammad Hussnain Imtiaz" ;
    getche ();
    return 0;
    }  //end of main function

Result Card


/********************************************************************************
  Name: Result Card

  Copyright: BCS-1A

  Author: Muhammad Hussnain Imtiaz

  Date: 25/12/11 13:01

  Description: result card of seven subjects
*********************************************************************************/

 # include <iostream>
 # include <conio.h>
 # include <string>

 using namespace std ;
 int main()
 {
//   Local declaration
 int rollNo   =0,
     subject1 =0,
     subject2 =0,
     subject3 =0,
     subject4 =0,
     subject5 =0,
     subject6 =0,
     subject7 =0;
 string name ;
 double percentage=0.0,
        sum      = 0.0,
        totalMark= 0.0;

 cout << "Enter your name :" ;
 getline (cin, name);
 cout << "Enter Roll Number :" ;
 cin  >> rollNo ;

 cout << "Enter your 1st subject Maks :" ;
 cin  >> subject1 ;
 cout << "Enter your 2nd subject Maks :" ;
 cin  >> subject2 ;
 cout << "Enter your 3rd subject Maks :" ;
 cin  >> subject3 ;
 cout << "Enter your 4th subject Maks :" ;
 cin  >> subject4 ;
 cout << "Enter your 5th subject Maks :" ;
 cin  >> subject5 ;
 cout << "Enter your 6th subject Maks :" ;
 cin  >> subject6 ;
 cout << "Enter your 7th subject Maks :" ;
 cin  >> subject7 ;
 cout << "\nEnter Total Marks :" ;
 cin  >> totalMark ;

 sum = subject1 + subject2 + subject3 + subject4 + subject5 + subject6 + subject7 ;
 percentage = (sum / totalMark) * 100.0 ;
 system ("CLS") ;
 cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*";

 cout << endl << "  Name :"           << name       ;
 cout << endl << "  Roll No. :"       << rollNo     ;
 cout << endl << "          1st Subject Marks :" << subject1;
 cout << endl << "          2nd Subject Marks :" << subject2;
 cout << endl << "          3rd Subject Marks :" << subject3;
 cout << endl << "          4th Subject Marks :" << subject4;
 cout << endl << "          5th Subject Marks :" << subject5;
 cout << endl << "          6th Subject Marks :" << subject6;
 cout << endl << "          7th Subject Marks :" << subject7;
 cout << endl << " Total Marks :" << totalMark << "        Obtained Marks :" << sum        ;
 cout << endl << " Percentage :"     << percentage ;
 cout << endl ;

 if (percentage>=90.0)
 {
 cout << " Grade :A+" ;          
 }
 else if (percentage>=80.0)
 {
 cout << " Grade :A" ;  
 }
 else if (percentage>=70.0)
 {
 cout << " Grade :B" ;  
 }
 else if (percentage>=60.0)
 {
 cout << " Grade :C" ;  
 }
 else if (percentage>=50.0)
 {
 cout << " Grade :D" ;  
 }
 else if (percentage>=40.0)
 {
 cout << " Grade :E" ;  
 }
 else if (percentage<40.0)
 {
 cout << " Grade :F" ;  
 }
 cout << endl << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*" ;

 cout << "\nPress any key" ;
 getch ();
 system ("CLS");
 cout << "\n\n\n\n\n\n\n\n\n                  Created By:Mohammad Hussnain Imtiaz" ;
 getch () ;
 return 0 ;
 }

Love Percentage


/****************************************************************
  Name: Love Percentage
 
  Copyright: BCS-1A
 
  Author: Muhammad Hussnain Imtiaz
 
  Date: 22/12/11 00:50
 
  Description: just For Fun and Entertainment
*****************************************************************/
 # include <iostream>
 # include <conio.h>
 # include <string>

 using namespace std ;

 int main ()
{
//   Local declaration
   string name1,
          name2;
   double num1 = 0.0 ,
          ans  = 0.0 ;
   int i=0 ;
   cout << "             ......Love Percentage......   " << endl ;
   cout << "              Enter your Name: "    ;
   getline (cin,name1) ;
   cout << "              Enter Your Lover Name: " ;
   getline (cin,name2) ;
   cout << "\n              Enter  your  Lucky  number  \n"
        << "          (Please only use less than 100) : " ;
   cin  >> num1 ;
   cout << endl ;
   if ( num1<=30 )
   {
   ans = num1 * 2.0 ;
   cout << "       *******************************************\n";
   cout << "                    " << name1 << " and " << name2 << endl;  // Space strings are just use for beauty in executed program
   cout << "            Your love Percentage is : " << ans << " % " ;
   cout << "\n       *******************************************";
   }
 
   else if ( num1>30 && num1<=40 )
   {
   ans = num1 * 1.2 ;
   cout << "       *******************************************\n";
   cout << "                    " << name1 << " and " << name2 << endl;
   cout << "            Your Love Percentage is : " << ans << " % " ;
   cout << "\n       *******************************************";
   }
 
   else if ( num1>40 && num1<=50 )
   {
   ans = num1 + 30.0986551 ;
   cout << "       *******************************************\n";
   cout << "                    " << name1 << " and " << name2 << endl;
   cout << "            Your Love Percentage is : " << ans << " % " ;
   cout << "\n       *******************************************";
   }
 
   else if ( num1>50 && num1<=60 )
   {
   ans = num1 * 0.99999 ;
   cout << "       *******************************************\n";
   cout << "                    " << name1 << " and " << name2 << endl;
   cout << "            Your Love Percentage is : " << ans << " % " ;    
   cout << "\n       *******************************************";
   }
 
   else if ( num1>60 && num1<=70 )
   {
   ans = num1 / 1.593443 ;
   cout << "       *******************************************\n";
   cout << "                    " << name1 << " and " << name2 << endl;
   cout << "            Your Love Percentage is : " << ans << " % " ;    
   cout << "\n       *******************************************";
   }
 
   else if ( num1>70 && num1<=80 )
   {
   ans = num1 + 13.0 ;
   cout << "       *******************************************\n";
   cout << "                   " << name1 << " and " << name2 << endl ;
   cout << "            Your Love Percentage is : " << ans << " % " ;
   cout << "\n       *******************************************";
   }
 
   else if ( num1>80 && num1<=90 )
   {
   ans = (num1 / 5.11)*2 ;
   cout << "       *******************************************\n";
   cout << "                    " << name1 << " and " << name2 << endl;
   cout << "            Your Love Percentage is : " << ans << " % " ;    
   cout << "\n       *******************************************";
   }
 
   else if ( num1>90 && num1<=95 )
   {
   ans = num1 / 1.3 ;
   cout << "       *******************************************\n";
   cout << "                    " << name1 << " and " << name2 << endl;
   cout << "            Your Love Percentage is : " << ans << " % " ;
   cout << "\n       *******************************************";
   }
 
   else if ( num1>95 && num1<100 )
   {
   ans = (num1 / 0.999999) ;
   cout << "       *******************************************\n";
   cout << "                    " << name1 << " and " << name2 << endl;
   cout << "            Your Love Percentage is : " << ans << " %\n";
   cout << endl ;
   cout << "                        Shoot him                   "   ;
   cout << "\n       *******************************************";
   }
 
   else if ( num1>99 && num1<101 )
   {
   ans = num1 * 0.0 ;
   cout << "       *******************************************\n";
   cout << "                    " << name1 << " and " << name2 << endl;
   cout << "            Your Love Percentage is : " << ans << " %\n";
   cout << endl ;
   cout << "                  Charachter Dheela                   " ;
   cout << "\n       *******************************************";
   }
 
   else if ( num1>100 )
   {
   cout << "\n           Your lucky number is invalid          " ;  
   }
   if ( ans>=90 )
   {
   cout << "\n\n\n                         WooooooW            " ;  
   }
 
  cout << "\n\n\n\n\n\n\n\n\n             Created By:Mohammad Hussnain Imtiaz" ;  
   getch ( ) ;
   return 0 ;
}

Find Greater or Lesser Number


/*
   multi purpuse program (which number is < or > then other no. in giver three numbers)
*/

// preprocessor directives
# include <iostream>
# include <conio.h>
using namespace std ;

//start main function here
int main ()
{

    cout << "            Welcome           " << endl << endl ;

    //local diclaration
  double num1 = 0.0 ,   //first integer value
         num2 = 0.0 ,   //second integer value
         num3 = 0.0 ,   //third integer value
        ;
       
        //input three integer numbers
        cout << endl << "     Enter First  No.  :" ;
        cin  >> num1;
       
        cout << endl << "     Enter Second No.  :" ;
        cin  >> num2 ;
       
        cout << endl << "     Enter Third  No.  :" ;
        cin  >> num3 ;
       
        if ( num1 > num2 && num1 > num3 )
    {      
        cout << endl << endl
             << "\""    //   ( \" is used to print " )
             << num1
             << "\""
             << "    Is greater than " << num2 << " and " << num3
             << endl << endl
             << "            THANKS          "
             ;    
    }
   
         else if ( num2 > num1 && num2 > num3 )
    {
        cout << endl << endl
             << "\""
             << num2
             << "\""
             << "  Is greater than " << num1 << " and " << num3
             << endl << endl
             << "            THANKS          "
             ;
    }
   
        else
    {
        cout << endl
             << endl
             << "\""
             << num3
             << "\""  
             << "  Is greater than " << num1 << " and " << num2
             << endl
             << endl
             << "            THANKS          "
             ;
    }
        cout << "\n\n\n\n\n\n\n\nCreated By:Mohammad Hussnain Imtiaz" ;
    getche ( );
    return 0;
    }  //end of main function