Monday, December 10, 2007

How to use variable and constant

How to use variable and constant

To use variable and constant

#include

#define GRAMS_PER_POUND 454

const int CENTURY = 2000;

long weight_grams, weight;

int year, age2000;

main()

{ printf("Enter your weight here : ");

scanf("%d", &weight);

printf("Enter your year of birth: ");

scanf("%d", &year);

weight_grams = weight * GRAMS_PER_POUND;

age2000 = CENTURY - year;

printf("\nYour weight in is = %ld", weight);

printf("\nIn 2000 you will be %d years old\n", age2000);

return 0;

}

Result :

How to compare number in C++ using If nested loop

How to compare number in C++ using If nested loop

To compare number in C++ using If nested loop

#include

int first, second;

int main()

{ printf("\nInput an integer value for 1st number : ");

scanf("%d", &first);

printf("\nInput an integer value for 2nd number : ");

scanf("%d", &second);

if (first == second)

printf("first number is equal to second number\n");

if (first > second)

printf("first number is greater than second number\n");

if (first <>

printf("first number is smaller than second number\n");

return 0;

}

Result :

How to differential x+ and ++x, yand --y

How to differential x+ and ++x, yand --y

To differential x+ and ++x, yand --y

#include

int x, y ;

main()

{x= y= 9;

printf("\n%d %d", x--, --y);

printf("\n%d %d", x--, --y);

printf("\n%d %d", x--, --y);

printf("\n%d %d", x--, --y);

printf("\n%d %d\n", x--, --y);

return 0;

}

Result :


How to do some calculation

How to do some calculation

To do some calculation

#include

int main( )

{ int x, y, z;

cout << "Please enter TWO numbers for the calculation :\n";

cout << "1st number is : ";

cin >> x;

cout << "2nd numbers is : ";

cin >> y;

(z = (x*y));

cout << "1st number is " <<>

cout << "\n"<<"So, when 1st number MULTIPLY by 2nd number...it equal to ";

cout<<>

return 0;

}

Result :

How to put an MATRIX in array

How to put an MATRIX in array

To put an MATRIX in array

#include

int main()

{

int x,y,multiarray[4][2] = { {9,7}, {3,2}, {0,6}, {3,3}};

for (x = 0; x<4;>

for (y=0; y<2;>

{

cout << "SomeArray[" <<>

cout <<>

}

return 0;

}

Result :

How to store information into array

How to store information into array

To store information into array

#include

int main()

{ int array[5] , e;

for ( e=0; e<5;>

{ cout << "please key in the value for array numbers [" <<>

cin >> array[e];}

for (e = 0; e<5;>

cout <<" Array number "<

return 0;

}

Result :

How to draw a char with nested for-loop

How to draw a char with nested for-loop

To draw a char with nested for-loop

#include

int main( )

{ int w,length, width;

char plan;

cout << "How long you want to draw ? :";

cin >> length;

cout << "How width you wanted to draw ? : ";

cin >> width;

cout << "Please Enter An SYMBOL for the plan : ";

cin >> plan;

for (int i = 0; i

{ for (w = 0; w

cout <<>

cout << "\n";

}

return 0;

}

Result :

How to display a same word with for-loop

How to display a same word with for-loop

To display a same word with for-loop

#include

int main()

{

int times;

for (times = 0; times <>

cout <<"\n"<< "For loops testing! ";

return 0;

}

Result :

How to display a same word with while-loop

How to display a same word with while-loop

To display a same word with while-loop

#include

main( )

{ int counter = 0;

while(counter <>

{ counter++;

cout << "\n"<<"while-loop testing! ";

}

return 0;

}

Result :

How to display a word using do-while loops

How to display a word using do-while loops

To display a word using do-while loops

#include

int main()

{

int how;

cout << "How many i love you, you want to display? ?: ";

cin >> how;

while (how > 0)

{ cout << "i Love You!\n";

how--;

}

return 0;

}

Result :

How to print character or number due to the number

How to use '||' operator

To use '||' operator

#include

int main()

{ enum weeks { Sun,Mon,Tues,Wed,Thurs,Fri,Sat};

weeks DayOff;

int a;

cout << "What day would you like off (0-6)? :";

cin >> a;

DayOff = weeks(a);

if (DayOff == Sun || DayOff == Sat)

cout << "\n now is weekends\n";

else

cout << "\nI'll put this date as the vacation day.\n";

return 0;

}

Result :

How to print character or number due to the number

How to print character or number due to the number

To print character / number due to the number

#include

int main()

{

for (int i = 32; i<128;>

cout << (char) i;

return 0;

}

Result :

How to use SIZEOF() in header file

How to use SIZEOF() in header file

To use SIZEOF() in #include header file.

#include

int array1[100];

float array2[100];

double array3[100];

main()

{ printf("The size of int = %d bytes", sizeof(int));

printf("\nThe size of short = %d bytes", sizeof(short));

printf("\nThe size of long = %d bytes", sizeof(long));

printf("\nThe size of float = %d bytes", sizeof(float));

printf("\nThe size of double = %d bytes", sizeof(double));

printf("\nThe size of intarray = %d bytes", sizeof(array1));

printf("\nThe size of floatarray = %d bytes",

sizeof(array2));

printf("\nThe size of doublearray = %d bytes\n",

sizeof(array3));

return 0;

}

Result :


How to input data into an array

How to input data into an array

To input data into an array

#include

float fees[5];

int times;

main()

{ for (times = 1; times <>

{ printf("Enter expenses for month %d: ", times);

scanf("%f", &fees[times]);}

for (times = 1; times <>

{ printf("Month %d = $%.2f\n", times, fees[times]);}

return 0; }

Result :


How to declare a menu

How to declare a menu

To declare a menu

include

#include

int get_menu_choice( void );

main()

{

int decision;

decision = get_menu_choice();

cout<<"You chose Menu Option "<

return 0;

}

int get_menu_choice( void )

{ int choice1 = 0;

do

{ cout<<"\n" ;

cout<<"\n"<<" 1. Add a new record " ;

cout<<"\n"<<" 2. Change a record";

cout<<"\n"<<" 3. Delete a record";

cout<<"\n"<<" 4. Quit";

cout<<"\n" ;

cout<<"\nEnter a selection: " ;

scanf("%d", &choice1 );

} while ( choice1 <> 4 );

return choice1;

}

Result :

How to draw a square with "0"

How to draw a square with "0"

To draw a square with "0".

#include

#include

void drawing( int, int);

int main()

{

drawing( 5, 10 );

return 0;

}

void drawing( int length, int column )

{

int w;

for ( ; length > 0; length--)

{

for (w = column; w > 0; w--)

cout<<"0";

printf("\n");

}

}

Result :


How to display multiple Alphabet or None message with user define

How to display multiple Alphabet or None message with user define

To display Multiple alphabet or none message with user define

#include

int main()

{

int numbers;

char alp;

{cout << "How many alphabet you want to display ?: ";

cin >> numbers;

cout<< "\n"<<"and what alphebet you want to display ?: ";

cin>>alp;

}

while (numbers > 0)

{

cout <<<>

numbers--;

}

return 0;

}

Result :


How to define a Mathematic Function

How to define a Mathematic Function

To define a Mathematic Function

typedef unsigned student;

#include

student calculate_student(student class_1, student clas_2);

int main()

{

student class_1_total;

student class_2_total;

student grand_total;

cout << "\nHow student in your First class ? ";

cin >> class_1_total;

cout << "\nHow student in your Second class ";

cin >> class_2_total;

grand_total= calculate_student(class_1_total,class_2_total);

cout << "\nThe There is "<<<">

return 0;

}

student calculate_student(student x, student y)

{

return x + y;

}

Result :


How to reverse a word

How to reverse a word

To reverse a word

#include

#include

int main ( void )

{

int t;

cout<< "Please Enter Your Christian Name here : ";

char name[15];

cin>> name;

for (t =strlen(name)-1; t>=0 ; t--)

cout <<<">

return 0;

}

Result :

How to declare an operator in a for loops

How to declare an operator in a for loops

To declare an operator in a for loops

#include

main ()

{

int w, doubl_e;

cout<< " please Enter An Integer here : " ;

cin>>doubl_e;

for (w =0 ; w<200 w="">

cout <<<">

return 0;

}

Result :

How to use GETLINE( )

How to use GETLINE( )

To use GETLINE( )

#include

main( )

{

const int arr=20;

char name[arr], food[arr];

cout<<" Please Key -in Your Name here :";

cin.getline(name,arr);

cout<<"\n"<<" Please Enter Your Flavour Food : ";

cin.getline(food,arr);

cout<<" i treat you to eat "<<<">

cout<< "(Mr / Ms) "<

return 0;

}

Result :


How to convert pounds to stone

How to convert pounds to stone

To convert pounds to stone

#include

main()

{

int k ,y,pounds = 5;

cout<<" Please enter the pounds to convert to stones : ";

cin>>pounds;

k=pounds/14;

y=pounds%14;

cout<<<">

cout<<" stones "<<<">

}

Result :

How to convert Celsius to Fahrenheit

How to convert Celsius to Fahrenheit

To convert Celsius to Fahrenheit

#include

main ()

{

float fahreheit;

int celsius;

cout<<" Please enter Celsius : " ;

cin>> celsius;

cout<< " The farrehheit is = "<<1.8*celsius+32;

}

Result :


How to declare a function

How to declare a function

To declare a function

#include

int squ (int);

void main ()

{

for (int k=1 ; k<=10; k++)

cout <<>

}

int squ (int u)

{

return u*u;

}

Result :

How to use summation

How to use summation

To use summation

#include

int main ()

{

int summation=0;

for (int num=2; num<=100 ; num += 2 )

summation += num;

cout << " The sum of the following number is : "<<>

return 0;

}

Result :

How to insert to ARRAY

How to insert to ARRAY

To insert to ARRAY

#include

main( )

{

char name[30];

cout<<" Please Enter Your Name : ";

cin >> name;

cout<<"HEllo, " <

return 0;

}

Result :

How to use Get( ) and Put( )

How to use Get( ) and Put( )

To use Get( ) and Put( )

#include

main( )

{ char name[15];

puts("Please Your name here ..... ");

gets(name);

puts("Hello");

puts(name);

puts("How Are You ? ");

return 0;

}

Result :


How to Display A-Z

How to Display A-Z

To Display A-Z

#include

main ()

{int A;

char alp , alpha[26];

for(A=0 , alp='a' ; A<26>

alpha[A] = alp;

for(A=0 ; A<26>

cout<<<"\n";

return 0;

}

Result :

How to DRAW A "0" PIRAMID

How to DRAW A "0" PIRAMID

To DRAW A "0" PIRAMID

#include

#define view '0'

main ()

{ int h,l;

for(h=1 ; h<=5 ; h++)

{ for (l=1 ; l<=5-h ; l++)

cout<<" ";

for (l=1 ; l<=2*h-1 ; l++)

cout<

cout<<"\n";

}

return 0;

}

Result :


How to nested for loop

How to nested for loop

To nested for loop.

#include

main ( )

{int x,y;

for (x=1 ; x<=5 ; x++)

{ cout<<"\n"<<<">

for (y=1 ; y<=6 ; y++)

cout <

return 0;

}

Result :


How to use for loops

How to use for loops

To use for loops

#include

main ()

{

int i,number;

for (i=1 ; i<=5 ; i++)

{

cout<<"Please enter number = ";

cin>>i;

}

//cout<

return 0;

}

Result :

How to illustrate a do-while loop

How to illustrate a do-while loop

To illustrate a do-while loop

#include

main ()

{

int decision;

do

{

cout<<"\n 1 = Boon Eng";

cout<<"\n 2 = Pearly ";

cout<<"\n 3 = Sandy ";

cout<<"\n\n\n Make A choice Today !! Besh :";

cin>> decision;

}while (decision >1 && decision <3);

return 0;

}


How to use CASE switch

How to use CASE switch

To use CASE switch

#include

main( )

{ int car_type, tyle_class;

cout<<" Please Choose A Car ------->> 1 for mercedes and 2 for BMW";

cout<<" \n Please Choose A Car Tyle class ";

cout<<" \n ----- MERCEDES ------";

cout<<"\n 1 for Rally Class 2 for Racer Class & 3 for Normal Class";

cout<<"\n\n ------ BMW ------";

cout <<"\n 1 for Home Class 2 for Country site Class & 3 for Normal Class";

cout<<"\n\n Please selct a car : ";

cin >>car_type;

switch (car_type)

{

case 1 : cout<<"\n Mercedes";

cout<<"\n Select tyle class ";

cin>>tyle_class;

switch (tyle_class)

{ case 1 : cout<<"\n Rally class";

break;

case 2 : cout<<"\n Racer class";

break;

default : cout<<"\n Normal class";

}

break;

case 2 : cout<<"\n BMW ";

cout<<"\n Select tyle ";

cin>>tyle_class;

switch (tyle_class)

{ case 1 : cout<<"\n Home use class";

break;

case 2 : cout<<"\n Country site class";

break;

default : cout<<"\n Normal class";

}

break;

default : cout<<"\n No Such A Car Exist";

}

return 0;

}

Result :

How to illustrate the size of data type

How to illustrate the size of data type

To illustrate the size of data type

#include

main ()

{ cout<<" size of int is "<<>

cout<<" size of double is "<<>

return 0;

}

Result :


How to make a if-else choice

How to make a if-else choice

To make a if-else choice

#include

main ()

{ char name [15] , gender ;

cout << "please enter name\n";

cin >> name;

cout<< "please enter gender (m/f)\n";

cin >> gender;

if (gender == 'm')

cout<< " hello!! mr."<<>

else

cout<< " hello!! ms."<

return 0;

}

Result :


How to work with mathematic operator

How to work with mathematic operator

To work with mathematic operator

#include

main ()

{ int a , b , c ;

cout << "please enter 1st number\n";

cin >> a;

cout<< "please enter 2nd number\n";

cin >> b;

c= a+b;

cout <<"Total is"<< " " <

return 0;

}

Result :


How to display a sentences

How to display a sentences

To display a sentences

BASIC SAMPLE PROGRAM

#include

main ()

{ cout<<"HELLO WORLD";

return 0;

}

Result :


How to start a NEW c++ project

How to start a NEW c++ project

To start a NEW c++ project.

  1. The #include (BEGIN WITH HEADER FILES/FILE).

  2. Comments

  3. The main() function

  4. The return statement

  5. The exit() function

  6. The void data type

  7. Translating a C program into an executable file

  8. Run

How to work with basic header files

How to work with basic header files

To work with basic header files.

Header File

Purpose Of Use

conio.h

Screen – handing function

ctype.h

Character – handing function (ANSI C)

float.h

Define Implementation dependant floating point

iomanip.h

Define I/O manipulator

iostream.h

Defines I/O stream class (C++)

math.h

Various definitions used by math library.

stdio.h

Declaration for standard I/O stream

string.h

String handling

time.h

System time function

How to use return statement

How to use return statement

To use return statement.

Declaration :

Return expression;

How to use sizeof operator

How to use sizeof operator

To use sizeof operator

Declaration :

Sizeof (int)

Sizeof (char)

Sizeof (long)

Sizeof ( long double)

How to configure test color

How to configure test color

To configure test color

Declaration :

Setcolor ( )

How to draw a circle

How to draw a circle

To draw a circle

Declaration :

void for circle ( int xaxis , int yaxis , int radius )

int xaxis , yaxis ; // center of the circle

int radius ; // radius of the circle

center

radius


How to draw a bar

How to draw a bar

To draw a bar

Declaration :

Int far bar (int left , int top , int right , int bottom )

Int left , top ; // top left corner

Int right , bottom ; // bottom right corner

Example :

if (working_day == ‘30’)

allowance = 1000;

else

monthly_bonus =30;

Example :

if ( salary == "10000")

if ( house== "bangalow")

if ( car = " Ferrari")

cout<<"\nVery rich";

else

cout<<"Rich";

else

cout<<"Comfortable life";

else

cout<<" YOU GOT NOTHING FOR YOUR LIFE;

left , top

right , bottom

How to draw a line

How to draw a line

To draw a line

Declaration :

void far line (int xaxis_1 , int yaxis_1 , int xaxis_2 , int yaxis_2)

int xaxis_1 , yaxis_1, // ( First coordinate)

int xaxis_2 , yaxis_2, // ( Second coordinate)

( xaxis_1 , yaxis_1 )

( xaxis_2 , yaxis_2 )

How to work with escape sequences

How to work with escape sequences

To work with escape sequences

Code

Meaning Of Code

\a

Audible bell

\b

Backspace

\f

Formfeed

\n

Newline

\r

Carriage return

\t

Horizontal tab

\\

Backslash character

\’

Single quote character

\"

Double quote character

\0

Null ASCII 0

How to use factorial

How to use factorial

To use factorial

Declaration :

Factorial_number = factorial (n)

How to use rand()

How to use rand()

To use rand()

Declaration :

number = rand();

How to work with array

How to work with array

To work with array

Structure :

[ array 0 ]

[ array 1 ]

[ array 2 ]

[ array 3 ]

Declaration :

type variable_name [array_size]

How to define a function

How to define a function

To define a function

Declaration :

type_of_function function_name ( parameter – list)

{ variable declare at here

&ldots;

&ldots;

&ldots;

return expression

}

How to Declare OR ( || ) operator

How to Declare OR ( || ) operator

To Declare OR ( || ) operator

Declaration :

3==3 | | 3==6 // true because 1st impression is true

3>2 | | 3>10 // true because 1st impression is true

3>10 | | 3<15>nd impression is true

3<15>1 // true because both are true

3>8 | | 3<1>

How to declare AND (&&) operator

How to declare AND (&&) operator

To declare AND (&&) operator

Declaration :

10 ==10 && 4==4 // ß it’s true because both statement is true

12==12 && 10==11 // ß it’s false because there is at least 1

statement is wrong

How to define and NOT (!) operator

How to define and NOT (!) operator

To define and NOT (!) operator

Declaration :

If ( !(w>15)) // if (w= 15) is clearer

How to define an goto statement

How to define an goto statement

To define an goto statement

Declaration :

goto label_x_or_y;

How to use for construct

How to use for construct

To use for construct

Declaration :

for (initialization ; expression_of_statement ; increment )

statement

How to use do-while construct

How to use do-while construct

To use do-while construct

Declaration :

do

statement here

while (expression here);

How to use while construct

How to use while construct

To use while construct.

Declaration :

while (expression) statement

How to use nested switch construct

How to use nested switch construct

To use nested switch construct.

Declaration :

switch (selection)

{ case 1 : statement sequence

switch (nes_swi)

{ case 1 : statement sequence

break;

case 2 : statement sequence

break;

}

case 2 : statement sequence

switch (nes_swi_2)

{ case 1 : statement sequence

break;

case 2 : statement sequence

break;

}

How to use switch construct

How to use switch construct

To use switch construct.

Declaration :

switch ( selection )

{ case 1: statement sequence

break;

case 2: statement sequence

break;

case 3: statement sequence

break;

default : error selection statement

}


How to use if-else nested construct

How to use if-else nested construct

To use if-else nested construct.

Declaration :

If (expression_a )

If (expression_b)

If (expressionc)

Statement_a;

else

Statement_b;

else

Statement_c;

else

Statement_d;

How to use if-else construct

How to use if-else construct

To use if-else construct.

Declaration :

if ( Expression ) statement

How to work with MATHEMATIC OPERATOR

How to work with MATHEMATIC OPERATOR

To work with MATHEMATIC OPERATOR.

OPERATOR IN C++

ACTION /MEANING

-

Subtraction

+

Addition

*

Multiplication

/

Division

%

Modulus Division

--

Decrement

++

Increment

<

Less than

<=

Less than or equal

>

Greater than

>=

Greater then or equal

==

Equal

!=

Not equal

&&

AND

||

OR

!

NOT

How to DECLARE VARIABLE

How to DECLARE VARIABLE

To DECLARE VARIABLE.

int a , b , c ;

short small_figure ;

long long_integer ;

char besh ;

float total_sale , total_dis ;

How to work with the BASIC DATA TYPE

How to work with the BASIC DATA TYPE

To work with the BASIC DATA TYPE.

DATA TYPE

C++ KEYWORD

BITS

RANGE

character

char

8

0 to 255

floating point

float

32

Approximately 6 digit of precision

double floating point

double

64

Approximately 12 digit of precision

integer

int

16

-32768 to 32767

short integer

short

8

-128 to 127

long integer

long

32

-4294967296 to

4294967295

unsigned integer

unsigned

16

0 to 65535

How to RUN the project

How to RUN the project

To RUN the project.

- Click on the RUN in the DEBUG menu.

How to COMPILE the project

How to COMPILE the project

To COMPILE the project.

- Click on the COMPILE in the PROJECT menu .


How to PRINT the Turbo C project

How to PRINT the Turbo C project

To PRINT the project

- Click on the PRINT in the file menu and click "OK" to finish.

How to SAVE a Turbo C project

How to SAVE a Turbo C project

To SAVE a project after done.

- Click on the SAVE in the FILE menu and name the project with (.cpp)

extension at the end of filename. Click "OK" to finish.

How to OPEN a *.cpp project

How to OPEN a *.cpp project

To OPEN a *.cpp project.

- Click on the OPEN in the FILE menu and browse the hard drive / floppy drive

and Click the filename and click "OK" to finish.