Skip to content

Commit 3c7be74

Browse files
committed
add: cpp-programming-questions 13_virtual_abstract 05
1 parent 4e3aa7e commit 3c7be74

File tree

1 file changed

+2
-106
lines changed

1 file changed

+2
-106
lines changed

13_virtual_function_and_abstract_class/05_bank.cpp

Lines changed: 2 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -8,118 +8,14 @@
88
// // use namespace
99
using namespace std;
1010

11-
// // define class Mobile
12-
class Car
11+
// // define class Bank
12+
class Bank
1313
{
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-
}
11714
};
11815

11916
// // Main Function Start
12017
int main()
12118
{
122-
12319

12420
cout << endl; // Add new line
12521
getch();

0 commit comments

Comments
 (0)