Showing posts with label Lecture 16 - 18. Show all posts
Showing posts with label Lecture 16 - 18. Show all posts
0

C++ Lecture: 18

Unknown Sunday, 5 August 2012 ,
Lecture 18
Conditional Statements (Decision Making)
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
  int num;
  cout<<"Enter a number less than 10 : ";
  cin>>num;
  if (num <= 10)
      cout <<"What an obedient servant you are! ";
  getch();
  return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
      Run program Ctrl+F10
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
  int num;
  cout<<"Enter a number 1 to 5 : ";
  cin>>num;
 
  if (num < 1)
      cout <<"Your number less then one ";
  if (num == 1)
      cout <<"Your number is \" One \" ";
  if (num == 2)
      cout <<"Your number is \" Two \" ";   
  if (num == 3)
      cout <<"Your number is \" Three \" ";
  if (num == 4)
      cout <<"Your number is \" Four \" ";
  if (num == 5)
      cout <<"Your number is \" Five \" ";    
  if (num > 5)
      cout <<"Your number large of five  ";    
     
  getch();
  return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
      Run program Ctrl+F10
0

C++ Lecture: 17

Unknown ,
Lecture 17
Conditional Statements (Decision Making)
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
  int age1, age2;
  age1 = 12;
  age2 = 10;
  if (age1 > age2)
      cout <<"Student 1 is older than student 2";
  getch();
  return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
      Run program Ctrl+F10
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
  int age1, age2;
  cout<<"Please enter Ali age : ";
  cin>>age1;
  cout<<"Please enter Shahid age : ";
  cin>>age2;
  if (age1 > age2)
      cout <<"Ali is older than Shahid";
  getch();
  return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
      Run program Ctrl+F10
0

C++ Lecture: 16

Unknown ,
Lecture 16
Escape Sequences:
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
   cout<<"Newline : \n  ";
   cout<<"Tab : \t  "<<endl;
   cout<<"Backspace : \b   "<<endl;
   cout<<"Carriage return : \r "<<endl;
   cout<<"Formfeed : \f "<<endl;
   cout<<"Single quote : \' "<<endl;
   cout<<"Double quote : \" "<<endl;
   cout<<"Backslash : \\ "<<endl;
  getch();
  return 0;
}

Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Printing Graphics Characters:
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
   cout<<"Hex value:";
   cout<<"ASCII code run 0: \x0"<<endl;
   cout<<"ASCII code run 1: \x1"<<endl;
   cout<<"ASCII code run 2: \x2"<<endl;
   cout<<"ASCII code run 3: \x3"<<endl;
   cout<<"ASCII code run 4: \x4"<<endl;
   cout<<"ASCII code run 5: \x5"<<endl;
   cout<<"ASCII code run 6: \x6"<<endl;
   cout<<"ASCII code run 7: \x7"<<endl;
   cout<<"ASCII code run 8: \x8"<<endl;
   cout<<"ASCII code run 9: \x9"<<endl;
   cout<<"ASCII code run A: \xA"<<endl;
   cout<<"ASCII code run B: \xB"<<endl;
   cout<<"ASCII code run C: \xC"<<endl;
   cout<<"ASCII code run D: \xD"<<endl;
   cout<<"ASCII code run E: \xE"<<endl;
   cout<<"ASCII code run F: \xF"<<endl;
   cout<<".................";
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10

Decimal to binary code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
  int a=2;
  cout<<"The decimal value is : "<<a;
  cout<<"\nThe binary value is : ";
  cout<<a%2;
  a=a/2;
  cout<<a%2;
 
  getch();
  return 0;
}
Code view in dev compiler:

Compile the program Ctrl+F9

      Run program Ctrl+F10
 
Copyright 2010 Learn Dev C++