Posts

Showing posts with the label Basic consept of cpp
--------------------------------------------------------------- MYHEADER.H void function(char a[]) { cout << a; } save - C:\TURBOC3\INCLUDE  --------------------------------------------------------------- //P-14 : Create own header file #include <iostream.h> #include <conio.h> #include <myheader.h> void main() { clrscr(); function("This is "); function("Simple Header file"); getch(); }
 //P-13 : Inline function //A function which expand in a line is called inline function #include <iostream.h> #include <conio.h> inline void display() { cout << "Welcome to Inline function"; } void main() { clrscr(); display(); ghetch(); }
 //P-12: Function overloading #include <iostream.h> #include <conio.h> void show() { cout << "Function show() without argument" << endl; } void show(int a) { cout << "\nFunction show() with one argument" << endl; cout << "Number : " << a << endl; } void show(int n, char nm[]) { cout << "\nFunction show with two argument" << endl; cout << "Number : " << n << endl; cout << "String : " << nm << endl; } void main() { clrscr(); show(); show(65); show(36,"Welcome to function overloading"); getch(); }
 //P-11: Default Argument #include <iostream.h> #include <conio.h> void print(int no, float n = 3.65) { cout << " NUMBER : " << no << endl; cout << " NUMBER : " << n << endl; } void main() { clrscr(); print(10, 26.5); print(2); //Default Argument getch(); }
 //P-10 : constant - variable value is never change #include <iostream.h> #include <conio.h> void main() { const int n = 10; // this value is never change clrscr(); cout << "Number : " << n; getch(); }
 //P-9: constant argument #include <iostream.h> #include <conio.h> void display(int n) { cout << "Number :" << n; } void main() { clrscr(); display(365); getch(); }
 //P-8 Type casting or Type conversion #include <iostream.h> #include <conio.h> void main() { int a, b; float c; clrscr(); cout << "Enter value A = "; cin >> a; cout << "Enter value B = "; cin >> b; c = (float)a / b; cout << "Division = " << c; getch(); }
 // P-7 : Refernce variable  -alias (another) name of variable #include <iostream.h> #include <conio.h> void main() { int no = 10; int &ref = no; clrscr(); cout << "Refernce Variable : " << ref; getch(); }
 //P-6: scope resolution operator :: #include <iostream.h> #include <conio.h> int n = 100; void main() { int n = 50; clrscr(); { int n = 25; cout << "\nblock -1" << endl; cout << "N = " << n << endl; cout << "::N = " << ::n << endl; } { int n = 10; cout << "\nblock -2" << endl; cout << "N = " << n << endl; cout << "::N = " << ::n << endl; } cout << "\nmain function" << endl; cout << "N = " << n << endl; cout << "::N = " << ::n << endl; getch(); }
 //P-5 : cascading of extraction operator or get from operator #include <iostream.h> #include <conio.h> void main() { int a, b, c; clrscr(); cout << "Enter value of A, B, C, : "; cin >> a >> b >> c; cout << "A = " << a << endl; cout << "B = " << b << endl; cout << "C = " << c << endl; getch(); }
 // P-4 : cin object of istream class - iostream.h header file // << - extraxtion operator or get from operator #include <iostream.h> #include <conio.h> void main() { int no; clrscr(); cout << "Enter any value : "; cin >> no; cout << "Number = " << no; getch(); }
 //P-2: bitwise operator left shift operator #include <iostream.h> #include <conio.h> void main() { clrscr(); cout << 5 << "\t" << 3;       //insertion put to operator cout << endl << (5 << 2);    // left  shift operator means (5 * 2 * 2) getch(); }
 //P-1: cout object of ostream class - istream.h header file // << - insertion operator or put to opertator #include <iostream.h> #include <conio.h> void main() { clrscr(); cout << "Welcome to CPP Programming"; getch(); }