C++ Practical
Class Design Snippet-3
Question : Write a Program to define the classes PERSON, GAME and STUDENT & to access the essential data using multiple inheritance?
Answer:
Blog provides NCERT solutions, CBSE, NTSE, Olympiad study material, model test papers, important Questions and Answers asked in CBSE examinations. References to Educational Sites and resources.
void main() { char word [] = "Board Examination"; cout << setw(20) << word; }
void main() { char TEXT[] = "something"; cout << "Remaining SMS chars: " << 160 - strlen(TEXT) << endl; }
void main() { int number; cin >> number; if (abs(number) == number) cout << "positive" << endl; }
class Book { char title[20]; char author[20]; int no_of_pages; public: void read( ); void show( ); }; class TextBook : private Book { int no_of_chapters, no_of_assignments; protected: int standard; public: void readtextbook( ); void showtextbook( ); }; class PhysicsBook : public TextBook { char topic[20]; public: void readphysicsbook( ); void showphysicsbook( ); };
Type | Charge |
'E' | 16*Distance |
'A' | 22*Distance |
'L' | 30*Distance |
const int BUFFSIZE = 40; class Tourist { // private data members int carNum; char origin[BUFFSIZE]; char destination[BUFFSIZE]; char carType; int distance; int charges; public: // member functions // constructor Tourist() { carType = 'E'; charges = 250; } // calculate charges void CalcCharges() { if (Type == 'E') { charges = 16*distance; } else if (Type == 'A') { charges = 22*distance; } else if (Type == 'C') { charges = 30*distance; } }; // enter values void Tourist::Enter() { cout << "Enter CarNo, Origin, Destination, Type, Distance:"; cin >> carNum; gets(origin); gets(destination); cin >> carType >> Distance; CalcCharges(); } // show/display details void Show() { cout << "Car No: " << carNum << "\nOrigin: " << origing << "\nDestination: " << destination << "\nType: " << carType << "\nDistance: " << distance << "\nCharges: " << charges << endl; } };
Please turn off the ad blocker. This is only way that we can earn some penny. Please support us by trun off the ad blocker.
Thank you!!