Monday 31 December 2012

Lecture 142


                                                Lecture 142

Procedures and Functions
Code:
#include <iostream>
#include <conio.h>
using namespace std;
void Twobeep(void);    // Prototype for Twobeep();
main ()
  Twobeep();
  cout<<"Type any character\n";      
  getch();
  Twobeep();
  return 0;
}
void Twobeep()
{
  cout<<"\x7";    
  for(int i=0;i<100000;i++)
      ;     // Null Statement
  cout<<"\n";         
    
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Lecture 141


                                                Lecture 141

Procedures and Functions
Code:
#include <iostream>
#include <conio.h>
using namespace std;
void Line(void);    // Prototype for Line();
main ()
  Line();
  cout<<"\xDB TITUS ANDRONICUS \xDB\n";      
  Line();
  getch();
  return 0;
}
void Line()
{
  for(int i=0;i<20;i++)
      cout<<"\xDB";
  cout<<"\n";         
    
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Saturday 22 September 2012

Lecture 140

                                                Lecture 140

// Loop GoTo
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
    int n;
    char ch;
    cout<<"Two table\n";
    n=1;
      Loop1: //Label
          ch=n;
          cout<<"\n2  X "<<n<<" = "<<2*n;
          n++;
         if(n==11) 
             goto Loop2;
         goto Loop1;
   Loop2:        
  getch();
  return 0;
}
Output:


Tuesday 11 September 2012

Lecture 139


                                                Lecture 139

// Loop GoTo
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
    int n;
    char ch;
    cout<<"An ASCII Table Program: \n";
    n=1;
      Loop1: //Label
          ch=n;
          cout<<n<<" = "<<ch<<"\t\t";
          n++;
         if(n==256) 
             goto Loop2;
         goto Loop1;
   Loop2:        
  getch();
  return 0;
}
Output:

Monday 27 August 2012

Lecture 138


                                                Lecture 138
// Loop GoTo
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
      int count,total;
      count=0,total=0;
      Loop1: //Label
         total=total+count;
         cout<<"Count: "<<count<<"  Total: "<<total<<endl;        
         count++;
         if(count==10) 
             goto Loop2;
         goto Loop1;
   Loop2:        
  getch();
  return 0;
}

Output:

Friday 10 August 2012

Lecture: 137


                                                Lecture 137
// Loop GoTo
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
      int i;
      i=1;
      cout<<"Odd number: ";     
      Loop1: //Label
         cout<<i<<" ";
         i+=2;
         if(i>=10) 
             goto Loop2;
         goto Loop1;
   Loop2:        
  getch();
  return 0;
}
    
Output:


Code:
// Loop GoTo
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
      int i;
      i=1;
      cout<<"Odd number: ";     
      Loop1: //Label
         cout<<i<<" ";
         i+=2;
         if(i==10) 
             goto Loop2;
         goto Loop1;
   Loop2:        
  getch();
  return 0;
}

Output:

Thursday 9 August 2012

Lecture: 136


                                                Lecture 136

// Loop GoTo
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
      int i;
      i=0;
      cout<<"Even number: ";     
      Loop1: //Label
         if(i==10) 
             goto Loop2;
         cout<<i<<" ";
         i+=2;
         goto Loop1;
   Loop2:        
  getch();
  return 0;
}
    
Output:

Monday 6 August 2012

Lecture 135


                                                Lecture 135

// Loop GoTo
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
      int i;
      i=0;
      cout<<"0 to 9 number: ";     
      Loop1: //Label
         if(i==10) 
             goto Loop2;
         cout<<i<<" ";
         i+=1;
         goto Loop1;
   Loop2:        
  getch();
  return 0;
}

Output:

Lecture: 134


                                                Lecture 134

// Loop GoTo
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
      int i;
      Goto1: //Label
         if(i==10)  goto Goto2;
         cout<<i;
         i++;
         goto Goto1;
   Goto2:        
  getch();
  return 0;
}

Output:

Sunday 5 August 2012

Lecture 133


                                                Lecture 133

// Loop do while
//Print diagonal line in the screen
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
        int x,y;
        y=1;
        do
           {
              x=1; 
              do{
                 if(x==y)
                     cout<<"\xDB";
                 else if(x==2*y)
                     cout<<"\xB1";
                 else   
                     cout<<" ";
                 x++;
                 }while(x<24);     
               cout<<endl;                        
               y++;
           }while(y<24);

  getch();
  return 0;
}
Output:

Lecture 132

                                                Lecture 132

// Loop do while
//Print diagonal line in the screen
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
        int x,y;
        y=1;
        do
           {
              x=1; 
              do{
                 if(x==y)
                     cout<<"\xDB";
                 else if(x==24-y)
                     cout<<"\xDB";
                 else   
                     cout<<"\xB0";
                 x++;   
                }while(x<24);  
               cout<<endl;                       
               y++;
           }while(y<24);

  getch();
  return 0;
}
Output:

Saturday 4 August 2012

Lecture 131


                                                Lecture 131

// Loop do while
//Print diagonal line in the screen
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
        int x,y;
        y=1;
        do
           {
              x=1; 
              do{
                 if(x==y)
                     cout<<"\xDB";
                 else
                     cout<<"\xB0";
                 x++;   
                 }while(x<24);  
               cout<<endl;                       
               y++;
           }while(y<24);

  getch();
  return 0;
}

Output:

Friday 3 August 2012

Lecture 130


                                                Lecture 130

// Loop do while
//Draws a checkerboard on the screen
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
        int x,y;
        y=1;
        do
           {
              x=1; 
              do
              {
                 if((x+y)%2==0)
                     cout<<"\xDB\xDB";
                 else
                     cout<<"  ";
                x++;
              }while(x<9);     
               cout<<endl;                       
               y++;
           }while(y<9);

  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Thursday 2 August 2012

Lecture 129


                                                Lecture 129
// Loop do while
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   int charcnt=0;
   int wordcnt=0;
   char ch;
   cout<<"Type in a phrase: \n";
   do
   {
       charcnt++;
       if(ch==' ')
              wordcnt++;
   }while((ch=getche()) != '\r');   
   cout<<"\nCharacter count is :"<<charcnt;
   cout<<"\nWord count is : "<<wordcnt;
  getch();
  return 0;
}


Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Wednesday 1 August 2012

Lecture 128


                                                Lecture 128

// Loop do while
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   char name[10]="Shahid";
   int i; 
   cout<<"Name:  ";
   i=0;
   do
   {
       cout<<name[i];
       i++;
   }while(name[i] != '\0');   
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Tuesday 31 July 2012

Lecture: 127


                                                Lecture 127

// Loop do while
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   char ch;
   int count=0; 
   cout<<"Type ina phrase : \n";
   do
   {
       cout<<ch;
       count++;
   }while((ch=getch()) != '\r');   
    cout<<" \n\nCharacter count is : "<<count;
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Monday 30 July 2012

Lecture: 126


                                                Lecture 126
// Loop do while
//Break for loop
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   int i; 
   i=1;
   do
   {
       if(i==5) break;         
    cout<<i<<" ";
    i++;
   }while(i<10);        
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Sunday 29 July 2012

Lecture: 125


                                                Lecture 125


// Loop do while
//Nested for loop
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   int row,col; 
   row=1;
   do
   {
       col=1; 
       do
       {
            cout<<"Outer = " << row <<" Inner = "<<col<<endl;     
            col++;
       }while(col<3);//inner loop    
    cout<<endl;
    row++;
   }while(row<3);//outer loop        
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Saturday 28 July 2012

Lecture: 124


                                                Lecture 124

// Loop do while
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
  system("CLS");//Clear screen
  int F=1,i=1,j;
  cout<<"Enter the factorial number: ";
  cin>>j;
  i=1;
   do{
       F=F*i;
       i++;
     }while(i<=j);
   cout<<"Factorial of "<<j<<" = "<<F;
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Friday 27 July 2012

Lecture 123


                                                Lecture 123
// Loop do while
//Nested for loop
//fills square area on screen
#include <iostream>
#include <conio.h>
#include <windows.h>
HANDLE wHnd;
using namespace std;
 main ()
{  
  system("CLS");//Clear screen
  int row,col; 
  row=1;
   do
   {
       col=1;
       do
       {
          cout<<"\xdb";     
          col++;
       }while(col<70);//inner loop     
    cout<<endl;
    row++;
   }while(row<22);//outer loop        
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Thursday 26 July 2012

Lecture: 122


                                                Lecture 122

// Loop do while
//Nested for loop
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   int row,col; 
   row=1;
   do
   {
       col=1; 
       do{
             cout<<col*row<<"\xb3";     
             col++;
         }while(col<13);//inner loop   
    cout<<endl;
    row++;
   }while(row<13);//outer loop        
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Wednesday 25 July 2012

Lecture: 121


                                                Lecture 121

// Loop do while
//Drawing a Graphics Character
#include <iostream>
#include <conio.h>
using namespace std;
 main ()
{  
   int n; 
   char ch[5]="\xD9";
   n=1;
   do{
        cout<<"\t"<<ch;
        n++;
     }while(n<40);
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10