--------------------------------------------------------------- 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(); }
Posts
Showing posts from October, 2020
- Get link
- X
- Other Apps
//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(); }
- Get link
- X
- Other Apps
//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(); }
- Get link
- X
- Other Apps
/************************************************************************************* J_3_P_5 Write a meaningful C++ program, which shows the use of user-defined to basic type data conversion. **************************************************************************************/ #include <iostream.h> #include <conio.h> class date { int day, month, year; public: void getdata() { cout << "Enter day = "; cin >> day; cout << "Enter month = "; cin >> month; cout << "Enter year = "; cin >> year; } operator int() { int totalday; totalday = year * 365 + month * 30 + day; return totalday; } }; void main() { int totalday; clrscr(); date obj; obj.getdata(); totalday = obj; cout << "\n\tTotal Day = " << totalday; getch(); }
- Get link
- X
- Other Apps
//P-2 Templates #include <iostream.h> #include <conio.h> template < class GT > GT sum( GT no1, GT no2 ) { GT ans; ans = no1 + no2; return ans; } void main() { clrscr(); cout << endl << " sum (10, 5) = " << sum (10,5); cout << endl << " sum (2.25f, 3.45f) = " << sum (2.25f, 3.45f); cout << endl << " sum (200000L, 500000L) = " << sum (200000L, 500000L); getch(); }
- Get link
- X
- Other Apps
// Return by refernce #include <iostream.h> #include <conio.h> void main() { int a, b; int &refa = a; int &refb = b; clrscr(); int & max( int &, int &); cout << "Enter value a : "; cin >> a; cout << "Enter value b : "; cin >> b; cout << "Before calling function : " << endl; cout << "A = " << a << endl; cout << "B = " << b << endl; max(refa, refb) = -1; cout << "After calling function :" << endl; cout << "A = " << a << endl; cout << "B = " << b << endl; getch(); } int & max( int &ref1, int &ref2) { if(ref1 > ref2) { return ref1; } else { return ref2; } }
- Get link
- X
- Other Apps
// P-2 File Handling #include <iostream.h> #include <conio.h> #include <fstream.h> class stud { int id; char name[20]; public: void getdata() { cout << "Enter Stud ID :" ; cin >> id; cout << "Enter Student NAME : "; cin >> name; } }; void main() { stud s; clrscr(); ofstream file("stud.txt"); char op; do { s.getdata(); file.write((char *)&s,sizeof(s)); cout << endl << " one row created " << endl; cout << endl << " add any student [Y/N]"; cin >> op; }while( op == 'Y' || op == 'y'); file.close(); }
- Get link
- X
- Other Apps
//Destructor #include <iostream.h> #include <conio.h> class Test { static int count; public: Test() { count++; cout << endl << "object " << count << "created"; } ~Test() { cout << endl << "object" << count << "destroyed"; count--; } }; int Test :: count = 0; void main() { clrscr(); Test obj1; { cout << endl << "within block 1:"; Test obj2; } { cout << endl << "within block 2: "; Test obj2; } getch(); }
- Get link
- X
- Other Apps
//call by refernce #include <iostream.h> #include <conio.h> void main() { int a, b; int &refa = a; int &refb = b; void swap (int &, int &); clrscr(); cout << "Enter value a : "; cin >> a; cout << "Enter value b : "; cin >> b; cout << "Before swaping value : " << endl; cout << "A = " << a << endl; cout << "B = " << b << endl; swap(refa, refb); cout << "After swaping value :" << endl; cout << "A = " << a << endl; cout << "B = " << b << endl; getch(); } void swap(int &ref1, int &ref2) { int c; c = ref1; ref1 = ref2; ref2 = c; }
- Get link
- X
- Other Apps
//Program - 5 overload unary -- (minus minus) operator using friend function. #include <iostream.h> #include <conio.h> class test { int a, b; public: test() //default constructor { cout << "Enter value for A = "; cin >> a; cout << "Enter vslue for B = "; cin >> b; } void show() { cout << endl << "A = " << a; cout << endl << "B = " << b; } friend void operator -- (test &) }; void operator -- (test &ref) { -- ref.a; -- ref.b; } void main() { clrscr(); test obj; //calls Default Constructo --obj; //call opertor --() friend function obj.show(); getch(); }
- Get link
- X
- Other Apps
//Program - 4 Overload Binary Operator + (plus) using member function #include <iostream.h> #include <conio.h> class calculate { int a, b; public: void getdata() { cout << "Enter value a = "; cin >> a; cout << "Ente value b = "; cin >> b; } void print() { cout << endl << "A = " << a; cout << endl << "B = " << b; } calculate operator+(calculate ob2) { calculate temp; temp.a = a + ob2.a; temp.b = b + ob2.b; return temp; } }; void main() { clrscr(); calculate obj1, obj2, obj3; obj1.getdata(); obj2.getdata(); obj3 = obj1 + obj2; //calls operator+() fuction obj3.print(); getch(); }
- Get link
- X
- Other Apps
//Program - 3 -overload Unary operator ~ (bitwise one's complement) using friend function #include <iostream.h> #include <conio.h> class Test { int a, b; public : Test() { cout << " Enter Value a = "; cin >> a; cout << " Enter value b = "; cin >> b; } void show() { cout << endl << "A = " << a; cout << endl << "B = " << b; } friend void operator~(Test &); }; void operator~(Test &ref) { ref.a = ~ref.a; ref.b = ~ref.b; } void main() { clrscr(); Test obj; obj.show(); ~obj; obj.show(); getch(); }
- Get link
- X
- Other Apps
//Program - 2 : Overload Unary -(minus) operator using member function #include <iostream.h> #include <conio.h> class Number { int a; public : Number() { cout << "Enter value a = "; cin >> a; } void show() { cout << endl << " A = "<< a; } void operator-() { a = - a; } }; void main() { clrscr(); Number obj; // calls Default constructor obj.show(); -obj; //calls operator-() function obj.show(); getch(); }
- Get link
- X
- Other Apps
//Program - 1 overload unary operator using member function program - 1 #include <iostream.h> #include <conio.h> class Number { int a, b; public : Number() //Deafualt Constructor { cout << " Enter value of a : "; cin >> a; cout << " Enter value of b : "; cin >> b; } void display() { cout << endl << "A = " << a; cout << endl << "B = " << b; } void operator++() { ++a; ++b; } }; void main() { clrscr(); Number obj; //calls Deafault constructor obj.display(); ++obj; //calls operator++() function cout << endl << "After ++obj : "; obj.display(); getch(); }
- Get link
- X
- Other Apps
/******************* EDITOR VISUAL STUDIO CODE **********************/ J_3_P_11 /******************************************************************************************* Define the following classes. Class Data members Derived from Account name, no, actype (C for current & none S for saving Current Chequeno, balance Account Saving Balance Account Also include appropriate constructors and other member functions for performing various activities like to accept deposits of ten customers. To update balance of any customers and to display the information of all the customers, Write a C++ program, which implements these classes *********************************************************************************************/ #include <iostream> #include <conio.h> using namespace std; class account { public: int accno; char accname[20], actype[3]; public: int getd() ...
- Get link
- X
- Other Apps
/******************* EDITOR VISUAL STUDIO CODE **********************/ J_3_P_3 /********************************************************************************* Create a class vector that has arr[3] as data member and void getd() & void putd() as member functions. Overload >> and << operators to get and display value through object-name & these operators. **********************************************************************************/ #include <iostream> #include <conio.h> #include <stdlib.h> using namespace std; class vector { public: int arr[3]; public: int getd() { cin >> *this; // call operator>>() function return 0; } int putd() { cout << *this; //call operator<<() function ...
- Get link
- X
- Other Apps
<!-- JS event : onblur Execute a JavaScript when a user leaves an input field: The onblur event occurs when an object loses focus. --> Enter Name <input type = text id = "f" onblur = myfunction();> <script> function myfunction() { var x = document.getElementById("f"); x.value = x.value.toUpperCase(); } </script>
- Get link
- X
- Other Apps
<!-- javaScript variables can hold many data types: numbers, strings, arrays, objects and more: --> <script type="text/javascript"> var n = 10; // n is number datatype document.write(n,"<br>"); </script> <script type="text/javascript"> //strings datatype var s = "Rohit"; // s is strings datatype document.write(s,"<br>"); </script> <!--arrays datatype--> <p id = "demo"></p> <script> var a = ["Bumrah", 'arrsys', 123, 12.12]; document.getElementById("demo").innerHTML = a[0]; </script> <!--object datatype --> <script type="text/javascript"> var x = {firstname:"milan", secondname:"bakotra"};//x is object document.write(x.firstname," ",x.secondname, "<br>");//firstname and second name is properties </script>
- Get link
- X
- Other Apps
/* j_3_p_9 Create a class Father that has height & color as data member. Create a class Mother that has color & eyeColor as data member. Create a class child that will inherits the Father & Mother class. (Multiple) */ #include <iostream.h> #include <conio.h> class father { public: int h; char fclr[10]; }; class mother { public: char mclr[10], eyeclr[10]; }; class child : virtual public father, virtual public mother { void father() { cout << "Enter Father Height : "; cin >> h; cout << "Enter Father color : "; cin >> fclr; } void mother() { cout << "En...
- Get link
- X
- Other Apps
/* j_3_P_10 Create a class Stud that has Rollno as data member and getdno & putdno as member functions. Create a class Exam that has sub1, sub2 & sub3 as data member and getdmarks & putmarks as member functions. Exam class will inherits Stud class. Create a class Sports that has score as data member and getscore & putdscore as member functions. Sports will inherits Stud. Create a class Result that will inherits Sports and Exam class. Create object of Result class then get and display data members. */ #include <iostream.h> #include <conio.h> class stud { int rno; public: void getdno() { cout << "Enter roll no. : "; cin >> rno; } void putdno() ...
- Get link
- X
- Other Apps
/* j_3_p_7 Create a class A that has height as private data member & member functions to get & display it. Create a class B that has width as data member & member functions to get & display it. B class will inherits the A class. Create a class C that inherits the B class. Create object of C class and then access functions of A & B class. (Multilevel) */ #include <iostream.h> #include <conio.h> class A { private: int height; public: void get() { cout << "Enter Height : "; cin >> height; } void display() { cout <...
- Get link
- X
- Other Apps
/* jurnal_3 program_8 Create a class a class BASE. Create two classes Derived1 & Derived2 that inherits the BASE class. Create objects of Derived1 & Derived2 & access member functions of BASE class and own. (Hierarchical) */ #include <iostream.h> #include <conio.h> class BASE { public: void show() { cout << "THIS IS BASE CLASS" << endl; } }; class Derived1 : public BASE {}; class Derived2 : public BASE {}; void main() { clrscr(); Derived1 obj1; Derived2 obj2; obj1.show(); obj2.show(); getch(); }
- Get link
- X
- Other Apps
/* journal_ttu3 program_6 Create a Class Shape that has height & length as private data member, getd & putd as member functions. Create class Rect that inherits Shape class. Create an object of Rect class & access the member functions of Shape class. (Single) */ #include <iostream.h> #include <conio.h> class shape { private: int height, length; public: void getd() { cout << "Enter Height : "; cin >> height; cout << "Enter Length : "; cin >> length; } void putd() ...
- Get link
- X
- Other Apps
//j_3_p_4 //comparision of two string #include <iostream.h> #include <conio.h> #include <string.h> class string { char str[20]; public: void get() { cout << "Enter string: " ; cin.getline(str, 20); } int operator > (string); int operator < (string); friend operator == (string, string) }; int string :: operator > (string ob2) { if(strcmp(str, ob2.str) > 0) { return 1; } else { return 0; ...
- Get link
- X
- Other Apps
/* j_3_4 Write a C++ program that overloads the + operator and appropriate (suitable) relational operator to perform the following operations: a) Concatenation of two strings. b) Comparison of two strings. */ #include <iostream.h> #include <conio.h> #include <string.h> class string { char str1[10]; public: void get() { cout << "Enter string = "; cin.getline(str1, 10); } string operator+(string s) { string obj; strcat(str1,s.str1); strcpy(obj.str1, str1); ...
- Get link
- X
- Other Apps
/* j_3_p_2 Create a Class Space that has x, y, z as data members and function to accept and display the data member. Overload unary – operator to convert sign of the data member. (Through member function & friend function) */ #include <iostream.h> #include <conio.h> class space { int x, y, z; public: void get() { cout << "Enter value x = "; cin >> x; cout << "Enter value y = "; cin >> y; cout << "Enter value z = "; cin >> z; } ...
- Get link
- X
- Other Apps
/* J_3_P_1 Write a C++ program, which shows the use of arithmetic operators overloading for two objects of the same class. (Addition, subtraction, multiplication and division of two objects). */ #include <iostream.h> #include <conio.h> class math { int a, b, s, m, d; public: void get() { cout << "Enter value a = "; cin >> a; } math operator+(math obj2) { math add; add.b = a + obj2.a; return add; ...
- Get link
- X
- Other Apps
/* Multiple Inheritance B C | | ----A---- */ #include <iostream.h> #include <conio.h> class B { public: int b; }; class C { public : int c; }; class A : public B, public C { public : int a; }; void main() { clrscr(); A obj; obj.a = 10; obj.b = 20; obj.c = 30; cout << endl << obj.a; cout << endl << obj.b; cout << endl << obj.c; getch(); }
- Get link
- X
- Other Apps
// Hybrid inheritance /* A | B __|__ | | C D */ #include <iostream.h> #include <conio.h> class A { public: int a; }; class B : public A { public: int b; }; class C : public B { public: int c; }; class D : public B { public: int d; }; void main() { clrscr(); C obj; D obj1; obj.a = 10; obj.b = 20; obj.c = 30; obj1.a = 200; ...
- Get link
- X
- Other Apps
/* Hybrid inheritance A B |_____| | C | D */ #include <iostream.h> #include <conio.h> class A { public: void showA() { cout << "class A -> showA() function called" << endl; } }; class B { public: void showB() { cout << "class B -> showB() function called" << endl; } }; class C : public B, public A { public: void showC() ...
- Get link
- X
- Other Apps
/*Hybrid Inheritance (virtual base classA) ____A____ | | | B---D---C */ #include <iostream.h> #include <conio.h> class A { public: void printA() { cout << "Class A -> printA function called" << endl; } }; class B :virtual public A { public: void printB() { cout << "Class B -> printB function called" << endl; } }; class C : virtual public A { public: void printC() ...
- Get link
- X
- Other Apps
//Multiple inheritance #include <iostream.h> #include <conio.h> class student { int a; char name[10]; public: void getdata() { cout << "Enter name : "; cin.getline(name, 10); cout << "Enter roll no : "; cin >> a; } void display() { cout << endl << "Name is : " << name; cout << endl << "Roll no is :" << a; ...
- Get link
- X
- Other Apps
/* Multilevel Inhetritance b c | | ----- | A */ #include <iostream.h> #include <conio.h> class B { public: void showB() { cout << "class B -> showB function called " << endl; } }; class C { public: void showC() { cout << "class C -> showC function called " << endl; } }; class A : public B, public C { public: void showA() { ...
- Get link
- X
- Other Apps
//Multilevel inheritance // A -> B -> C #include <iostream.h> #include <conio.h> class A { protected: void showA() { cout << endl << "class A -> showA function called"; } }; class B : public A { protected: void showB() { cout << endl << "class B -> showB function called"; } }; class C : B { protected: void showC() { cout << endl << "class C -> showC function called"; ...
- Get link
- X
- Other Apps
//multilevel inheritance // A -> B -> C #include <iostream.h> #include <conio.h> class A { public: void showA() { cout << endl << "class A -> showA function called"; } }; class B : public A { public: void showB() { cout << endl << "class B -> showB function called"; } }; class C : public B { public: void showC() { cout << endl << "class C -> showC function called"; ...