/************************************************************************************* 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(); }
Posts
Showing posts with the label cpp journal_3 program
- 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
/* 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; ...