|
8 | 8 | // // use namespace |
9 | 9 | using namespace std; |
10 | 10 |
|
11 | | -// // define class Mobile |
12 | | -class Car |
| 11 | +// // define class Bank |
| 12 | +class Bank |
13 | 13 | { |
14 | | -public: |
15 | | - // // static member variable |
16 | | - static const int MAX_CHARS_IN_MODEL = 51; |
17 | | - |
18 | | -private: |
19 | | - char *model; |
20 | | - |
21 | | -public: |
22 | | - // // constructors |
23 | | - Car() |
24 | | - { |
25 | | - model = new char[1]; |
26 | | - model[0] = '\0'; // // terminate with null char |
27 | | - cout << "\nDefault Constructor of Class Car"; |
28 | | - } |
29 | | - |
30 | | - Car(const char *model) |
31 | | - { |
32 | | - int length = strlen(model); |
33 | | - |
34 | | - this->model = new char[length > MAX_CHARS_IN_MODEL - 1 ? MAX_CHARS_IN_MODEL : length + 1]; |
35 | | - |
36 | | - if (length > MAX_CHARS_IN_MODEL - 1) |
37 | | - { |
38 | | - strncpy(this->model, model, MAX_CHARS_IN_MODEL - 1); |
39 | | - this->model[MAX_CHARS_IN_MODEL - 1] = 0; // // terminate with null character |
40 | | - } |
41 | | - else |
42 | | - { |
43 | | - strcpy(this->model, model); |
44 | | - } |
45 | | - |
46 | | - cout << "\nParametrized Constructor of Class Car"; |
47 | | - } |
48 | | - |
49 | | - // // instance member function to set model |
50 | | - void setModel(const char *model) |
51 | | - { |
52 | | - int length = strlen(model); |
53 | | - |
54 | | - this->model = new char[length > MAX_CHARS_IN_MODEL - 1 ? MAX_CHARS_IN_MODEL : length + 1]; |
55 | | - |
56 | | - if (length > MAX_CHARS_IN_MODEL - 1) |
57 | | - { |
58 | | - strncpy(this->model, model, MAX_CHARS_IN_MODEL - 1); |
59 | | - this->model[MAX_CHARS_IN_MODEL - 1] = 0; // // terminate with null character |
60 | | - } |
61 | | - else |
62 | | - { |
63 | | - strcpy(this->model, model); |
64 | | - } |
65 | | - } |
66 | | - |
67 | | - // // instance member function to get model |
68 | | - const char *getModel() const |
69 | | - { |
70 | | - return model; |
71 | | - } |
72 | | - |
73 | | - // // destructor |
74 | | - ~Car() |
75 | | - { |
76 | | - delete[] model; |
77 | | - } |
78 | | -}; |
79 | | - |
80 | | -// // define class SportsCar by Inheriting class Car |
81 | | -class SportsCar : public Car |
82 | | -{ |
83 | | -private: |
84 | | - int sensorCount; |
85 | | - |
86 | | -public: |
87 | | - // // constructors |
88 | | - SportsCar() : Car() |
89 | | - { |
90 | | - sensorCount = 0; |
91 | | - cout << "\nDefault Constructor of Class Student"; |
92 | | - } |
93 | | - |
94 | | - SportsCar(const char *model, int sensorCount) : Car(model) |
95 | | - { |
96 | | - if (sensorCount < 0) // if sensorCount is negative, then make it positive |
97 | | - sensorCount = -sensorCount; |
98 | | - |
99 | | - this->sensorCount = sensorCount; |
100 | | - cout << "\nParametrized Constructor of Class SportsCar"; |
101 | | - } |
102 | | - |
103 | | - // // instance member function to set sensorCount |
104 | | - void setSensorCount(int sensorCount) |
105 | | - { |
106 | | - if (sensorCount < 0) // if sensorCount is negative, then make it positive |
107 | | - sensorCount = -sensorCount; |
108 | | - |
109 | | - this->sensorCount = sensorCount; |
110 | | - } |
111 | | - |
112 | | - // // instance member function to get sensorCount |
113 | | - int getSensorCount() const |
114 | | - { |
115 | | - return sensorCount; |
116 | | - } |
117 | 14 | }; |
118 | 15 |
|
119 | 16 | // // Main Function Start |
120 | 17 | int main() |
121 | 18 | { |
122 | | - |
123 | 19 |
|
124 | 20 | cout << endl; // Add new line |
125 | 21 | getch(); |
|
0 commit comments