#include <iostream.
h>
#include <conio.h>
void main()
{
clrscr();
int a = 100;
int b = 200;
switch( a )
{
case 100:
cout << "In Outer Switch." << endl;
switch( b )
{
case 200:
cout << "In Inner Switch." <<
endl;
}
}
cout << "Value of a is : " << a << endl;
cout << "Value of b is : " << b << endl;
getch();
}
Output:
In Outer Switch.
In Inner Switch.
Value of a is : 100
Value of b is : 200
include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int a, b, max;
cout << "Enter Two Numbers ::: ";
cin >> a >> b;
max = ( a > b ) ? a : b;
cout << "\n Maximum Value is ::: " << max;
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
char ch;
clrscr();
cout << " Enter the character ::: ";
cin >> ch;
switch( ch )
{
case 'a' :
case 'A' :
case 'e' :
case 'E' :
case 'i' :
case 'I' :
case 'o' :
case 'O' :
case 'u' :
case 'U' :
cout << " It is a Vowel.";
break;
default :
cout << " It is not a Vowel.";
}
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
char op;
int a, b, res;
clrscr();
cout << " Enter two numbers ::: " ;
cin >> a >> b;
cout <<" Enter the operator (+, -, *, /, %) ::: ";
cin >> op;
switch( op )
{
case '+':
res = a + b;
break;
case '-':
res = a - b;
break;
case '*':
res = a * b;
break;
case '/':
res = a / b;
break;
case '%':
res = a % b;
break;
default:
cout << " Wrong operator";
break;
}
cout << "\n" << a << " " << op << " " << b << " = " << res;
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int n;
cout << "\n Enter Number to convert day ( 1 to 7 ) ::: ";
cin >> n;
switch( n )
{
case 1:
cout << "\n Monday";
break;
case 2:
cout << "\n Tuesday";
break;
case 3:
cout << "\n Wednesday";
break;
case 4:
cout << "\n Thursday";
break;
case 5:
cout << "\n Friday";
break;
case 6:
cout << "\n Saturday";
break;
case 7:
cout << "\n Sunday";
break;
default:
cout << "\n Wrong Number.";
break;
}
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
char c;
clrscr();
cout << " Enter a character ::: ";
cin >> c;
if( c >= 65 && c <= 90 )
{
cout << "\n Character " << c << " is in Upper Case.";
}
else if( c >= 97 && c <= 122 )
{
cout << "\n Character " << c << " is in Lower Case.";
}
else if( c >= 48 && c <= 57 )
{
cout << "\n Character " << c << " is a Digit.";
}
else
{
cout << "\n Character " << c << " is a Special
Symbol.";
}
getch();
}
#include <iostream.h>
#include <conio.h>
void main()
{
char c;
clrscr();
cout << " Enter a character ::: ";
cin >> c;
if( c >= 65 && c <= 90 )
{
cout << "\n Character " << c << " is in Upper Case.";
}
else if( c >= 97 && c <= 122 )
{
cout << "\n Character " << c << " is in Lower Case.";
}
else if( c >= 48 && c <= 57 )
{
cout << "\n Character " << c << " is a Digit.";
}
else
{
cout << "\n Character " << c << " is a Special
Symbol.";
}
getch();
}
#include <iostream.h>
#include <conio.h>
float Simp_Int();
void main()
{
clrscr();
float si;
si = Simp_Int();
cout << "\n Simple Interest = " << si;
getch();
}
float Simp_Int()
{
float p, r, t, si;
cout << " Enter Principal, Rate and Time : ";
cin >> p >> r >> t;
si = ( p * r * t ) / 100;
return si;
}
#include <iostream.h>
#include <conio.h>
void cube(int*);
void main()
{
clrscr();
int a = 10;
cube(&a);
cout << "\n a = " << a << endl;
getch();
}
void cube(int *pa)
{
*pa = (*pa) * (*pa) * (*pa);
cout << "\n *pa = " << *pa << endl;
}
#include <iostream.h>
#include <conio.h>
const float PI = 3.1415926;
inline float area( const float r )
{
return ( PI * r * r );
}
main()
{
clrscr();
float radius;
cout << "\n Enter the radius of a circle ::: ";
cin >> radius;
cout << "\n The area of circle is " << area( radius );
getch();
return 0;
}
#include <iostream.h>
#include <conio.h>
float Simp_Int( float, float, float );
float Simp_Int( float, float );
float Simp_Int( float );
float Simp_Int( );
void main()
{
clrscr();
float p, r, t, si;
si = Simp_Int( 2000, 15, 2 );
cout << "\n Simple Interest = " << si;
si = Simp_Int( 2000, 15 );
cout << "\n Simple Interest = " << si;
si = Simp_Int( 2000 );
cout << "\n Simple Interest = " << si;
si = Simp_Int( );
cout << "\n Simple Interest = " << si;
getch();
}
float Simp_Int( float p, float r, float t)
{
float si;
si = ( p * r * t ) / 100;
return si;
}
float Simp_Int( float p, float r )
{
float si;
si = ( p * r * 3 ) / 100;
return si;
}
float Simp_Int( float p )
{
float si;
si = ( p * 10 * 3 ) / 100;
return si;
}
float Simp_Int( )
{
float si;
si = ( 1000 * 10 * 3 ) / 100;
return si;
}
#include <iostream.h>
#include <conio.h>
void AreaCircum(float, float&, float&);
void main()
{
clrscr();
float radius, area, circum;
cout << "\n Enter a Radius : ";
cin >> radius;
AreaCircum( radius, area, circum);
cout << "\n Area of Circle = " << area
<< "\n Circumference of Circle = " << circum;
getch();
}
void AreaCircum(float r, float &ar, float &cir)
{
ar = 3.14 * r * r;
cir = 2 * 3.14 * r;
}
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
struct Book
{
char name[25];
char author[20];
float price;
};
void main()
{
clrscr();
Book b;
cout << " Enter the Name of Book ::: ";
gets( b.name );
cout << " Enter the Author's Name ::: ";
gets( b.author );
cout << " Enter the Price of the book ::: ";
cin >> b.price;
cout << "\n Name of the Book ::: " << b.name;
cout << "\n Author of the Book ::: " << b.author;
cout << "\n Price of the Book ::: " << b.price << "\n";
getch();
}
#include <iostream.h>
#include <conio.h>
enum Suit { clubs, diamonds, hearts, spades };
const int jack = 11;
const int gueen = 12;
const int king = 13;
const int ace = 14;
struct card
{
int number;
Suit suit;
};
void main()
{
clrscr();
card temp, chosen, prize;
int position;
card card1 = { 7, clubs };
cout << "Card 1 is the 7 of clubs\n";
card card2 = { jack, hearts };
cout << "Card 2 is the jack of hearts\n";
card card3 = { ace, spades };
cout << "Card 3 is the ace of spades\n";
prize = card3;
cout << "I'm swapping card 1 and card 3\n";
temp = card3;
card3 = card1;
card1 = temp;
cout << "I'm swapping card 2 and card 3\n";
temp = card3;
card3 = card2;
card2 = temp;
cout << "I'm swapping card 1 and card 2\n";
temp = card2;
card2 = card1;
card1 = temp;
cout << "Now, where (1, 2, or 3) is the ace of spades ? ::: ";
cin >> position;
switch( position )
{
case 1:
chosen = card1;
break;
case 2:
chosen = card2;
break;
case 3:
chosen = card3;
break;
}
if( chosen.number == prize.number && chosen.suit ==
prize.suit )
cout << "That's right! You win!\n";
else
cout << "Sorry. You lose.\n";
getch();
}
#include <iostream.h>
#include <conio.h>
#define PI 3.14
class Circle
{
float radius;
public:
void setRadius( float r );
float getRadius();
inline float area();
};
void Circle :: setRadius( float r )
{
radius = r;
}
float Circle :: getRadius()
{
return radius;
}
inline float Circle :: area()
{
return PI * radius * radius;
}
void main()
{
clrscr();
Circle c1;
c1.setRadius(10);
float a = c1.area();
cout << "\n Radius : " << c1.getRadius();
cout << "\n Area of Circle : " << a;
getch();
}