--------------------------------------------------------------- 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() { cout << "\tEnter Account Name : "; cin >>
- 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 return 0; } friend ostream &operator<<(ostream &out, vector &v) { int i; for (i = 0; i < 3; i++) { out <<
- 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
//pointer to object #include <iostream.h> #include <conio.h> class employee { int code; char name[10]; float salary; public: void get() { cout << " Enter code : "; cin >> code; cout << " Enter name : "; cin >> name; cout << " Enter salary : "; cin >> salary; } void display() { cout << "Employe code : " << code << endl; cout << "Employe name : " << name << endl; cout << "Employe salary : " << salary << endl; } }; void main() { clrscr(); employee *ptr; ptr = new employee; ptr->get(); ptr->display(); getch(); }
- Get link
- X
- Other Apps
//this pointer #include <iostream.h> #include <conio.h> class emp { int code; public: emp(int code) { this->code = code; } void display() { show(); cout <<"EMP CODE = " << code << endl; } void show() { cout << "\n\t show function called\n"; } }; void main() { clrscr(); emp obj(23); obj.display(); getch(); }
- 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 << "Enter Mother color : "; cin >> mclr; cout << "Enter Mother eye color : "; cin >> eyeclr; } void print() { cout << "Father Height is " << h << endl; cout << "Fathe
- 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() { cout << "Roll No. is : " << rno; } }; class exam : virtual public stud { int sub1, sub2, sub3; public: void getmarks() { cout << "Enter
- 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 << endl << "Height is : " << height; } }; class B : public A { public: int width; public: void getB() { cout << "Enter width : "; cin >> width; } void displayB() { cout << endl <&l
- 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() { cout << "Height is : " << height << endl; cout << "Length is : " << length; } }; class rect : public shape { }; void main() { clrscr(); rect obj; obj.getd(); obj.putd(); getch(); }
- 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; } } int string :: operator < (string ob2) { if(strcmp(str, ob2.str) < 0) { return 1; } else { return 0; } } int operator == (string ob1, string ob2) { if(strcmp(ob1.str, ob2.str) == 0) { return 1; } else { return 0; } } void main() { clrscr(); string obj1, obj2, obj3; obj1.get(); obj2.get(); if(obj1 > obj2) { cout <&l
- 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); return obj; } void display() { cout << "\n\t String :" << str1; } }; void main() { clrscr(); string obj1, obj2, obj3; obj1.get(); obj2.get(); obj3 = obj1 + obj2; obj3.display(); getch(); }
- 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; } void put() { cout << "\tx = " << x << endl; cout << "\ty = " << y << endl; cout << "\tz = " << z << endl; } /* void operator-() { x = -x; y = -y; z = -z; } */ frien
- 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; } math operator - (math obj2) { math sub; sub.s = a - obj2.a; return sub; } math operator * (math obj2) { math mul; mul.m = a * obj2.a; return mul; } math operator / (math obj2) { math div; div.d = a / obj2.a; return div; } void diplay() {
- Get link
- X
- Other Apps
// class to class #include <iostream.h> #include <conio.h> class cube { int cu; public: void display() { cout << " Cube = " << cu; } void setdata(int n) { cu = n; } }; class get { int no; public: void getdata() { cout << "Enter No. = "; cin >> no; } operator cube() { cube n; n.setdata(no * no * no); return n; } }; void main() { clrscr(); cube obj; get obj2; obj2.getdata(); obj = obj2; obj.display(); getch(); }
- Get link
- X
- Other Apps
// basic to class #include <iostream.h> #include <conio.h> class date { int a, b; public: date() //default constructor { a = 0; } date (int n) //obj =x; parametrized constructor { a=n; cout << " A = " << a; } }; void main() { int x = 2; clrscr(); date obj; // default constructor call obj = x; // convert basic to class getch(); }
- Get link
- X
- Other Apps
// class to basic #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
//Basic to class #include <iostream.h> #include <conio.h> class date { int day, month, year; public: date() { day = month = year = 0; } date(int tal_day) { year = tal_day / 365; tal_day = tal_day % 365; month = tal_day / 30; day = tal_day % 30; } void display() { cout << endl << "year = " << year; cout << endl << "month = " << month; cout << endl << "day = " << day; } }; void main() { int tal_day; clrscr(); cout << "Enter Total Days = "; cin >> tal_day; date obj; obj = tal_day; obj.display(); getch(); }
- Get link
- X
- Other Apps
//constructor in inheritance #include <iostream.h> #include <conio.h> #include <string.h> class parent { int no; public: parent(int n) { no = n; } void dsply() { cout << "No is : " << no << endl; } }; class child : public parent { char str[10]; public: child(int n, char st[]) : parent(n) { strcpy(str, st); } void show() { dsply(); cout << " string is " << str; } }; void main() { clrscr(); child obj(12, "Welcome"); obj.show(); getch(); }
- 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; obj1.b = 300; obj1.d = 400; cout << endl << obj.a; cout << endl << obj.b; cout << endl << obj.c; cout << endl << obj1.a; cout << endl << obj1.b; cout << endl << obj1.d; getch(); }
- 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() { cout << "class C -> showC() function called" << endl; } }; class D : public C; { public: void showD() { cout << "class D -> showD() function called" << endl; } }; void main() { clrscr(); D obj; obj.showA(); obj.showB(); obj.showC(); obj.showD(); getch(); }
- 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() { cout << "Class C -> printC function called" << endl; } }; class D : public B, public C { public: void printD() { cout << "Class D -> printD function called" << endl; } }; void main() { clrscr(); D obj; obj.printA(); obj.printB(); obj.printC(); obj.printD(); getch(); }
- 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; } }; class marks { int m1, m2, m3; public: void getmark() { cout << endl << "Marks M1 :"; cin >> m1; cout << endl << "Marks M2 :"; cin >> m2; cout << endl << "Marks M3 :"; cin >> m3; } void dispmark() { cout << endl &l
- Get link
- X
- Other Apps
//Hierarchical Inheritance /* A | --------- | | B C */ #include <iostream.h> #include <conio.h> class A { protected: int a; }; class B : public A { protected: int b; public: void getB() { cout << "Enter value A :"; cin >> a; cout << "Enter value B :"; cin >> b; } void showB() { cout << endl << "Value A is :" << a; cout << endl << "Value B is :" << b << endl; } }; class C : A { protected: int c; public: void getC() { cout << endl << "Enter value A : "; cin >> a; cout << "Enter value C : "; cin >> c; } void showC() { cout <
- 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() { cout << "class A -> showA function called " << endl; } }; void main() { clrscr(); A obj; obj.showA(); obj.showB(); obj.showC(); getch(); }
- 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"; } public: void show() { showA(); showB(); showC(); } }; void main() { clrscr(); C obj; obj.show(); getch(); }
- 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"; } }; void main() { clrscr(); C obj; obj.showA(); obj.showB(); obj.showC(); getch(); }