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