@@ -34,7 +34,7 @@ class Base
34
34
virtual int fact ()
35
35
{
36
36
int factorial = 1 , max_num = max ();
37
- for (int i = 2 ; i < max_num; i++)
37
+ for (int i = 2 ; i <= max_num; i++)
38
38
factorial *= i;
39
39
return factorial;
40
40
}
@@ -79,7 +79,7 @@ class Drive1 : virtual public Base
79
79
int fact ()
80
80
{
81
81
int factorial = 1 , max_num = max ();
82
- for (int i = 2 ; i < max_num; i++)
82
+ for (int i = 2 ; i <= max_num; i++)
83
83
factorial *= i;
84
84
return factorial;
85
85
}
@@ -96,7 +96,7 @@ class Drive2 : virtual public Base
96
96
{
97
97
for (int i = 0 ; i < n; i++)
98
98
{
99
- D2[i] = 0 ;
99
+ D2[i] = 1 ; // multiblication start with one
100
100
int temp = (B[i] == 0 ? 1 : B[i]); // condattion in sheet to make multiplicton done
101
101
102
102
if (B[i] % 2 == 0 )
@@ -120,7 +120,7 @@ class Drive2 : virtual public Base
120
120
int fact ()
121
121
{
122
122
int factorial = 1 , max_num = max ();
123
- for (int i = 2 ; i < max_num; i++)
123
+ for (int i = 2 ; i <= max_num; i++)
124
124
factorial *= i;
125
125
return factorial;
126
126
}
@@ -135,7 +135,7 @@ class Drive : public Drive1, public Drive2
135
135
public:
136
136
void set ()
137
137
{
138
- for (int i = 0 ; i < n; i++ )
138
+ for (int i = 0 ; i < n; i += 3 )
139
139
{
140
140
// D (D0 is max element in B, D1 is max element in D1, and D2 is the max element in D2),
141
141
D[i] = Base::max ();
@@ -155,7 +155,7 @@ class Drive : public Drive1, public Drive2
155
155
summation += D[i];
156
156
157
157
int factorial = 1 ;
158
- for (int i = 2 ; i < summation; i++)
158
+ for (int i = 2 ; i <= summation; i++)
159
159
factorial *= i;
160
160
return factorial;
161
161
}
@@ -167,7 +167,7 @@ int main()
167
167
Drive2 obj2;
168
168
Drive obj;
169
169
170
- Base *arr[3 ] = {&obj, &obj1, &obj2} ; // one pure virtual function "virtual void read() = 0;" in Base and i cannot do this
170
+ Base *arr[3 ] = {&obj, &obj1, &obj2} ;
171
171
172
172
173
173
arr[1 ]->Base ::set (); // access the base to intialize first
0 commit comments