Skip to content

Commit fac1281

Browse files
author
samir176520
committed
update sheet9/problem1.cpp
1 parent 55e74f6 commit fac1281

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
.vscode/c_cpp_properties.json
33
.vscode/settings.json
44
sheet2/problem2
5+
vid2this.cpp
6+
test.cpp
7+
.gitignore
File renamed without changes.

sheet9/problem1.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Base
3434
virtual int fact()
3535
{
3636
int factorial = 1, max_num = max();
37-
for (int i = 2; i < max_num; i++)
37+
for (int i = 2; i <= max_num; i++)
3838
factorial *= i;
3939
return factorial;
4040
}
@@ -79,7 +79,7 @@ class Drive1 : virtual public Base
7979
int fact()
8080
{
8181
int factorial = 1, max_num = max();
82-
for (int i = 2; i < max_num; i++)
82+
for (int i = 2; i <= max_num; i++)
8383
factorial *= i;
8484
return factorial;
8585
}
@@ -96,7 +96,7 @@ class Drive2 : virtual public Base
9696
{
9797
for (int i = 0; i < n; i++)
9898
{
99-
D2[i] = 0;
99+
D2[i] = 1; // multiblication start with one
100100
int temp = (B[i] == 0? 1: B[i]); // condattion in sheet to make multiplicton done
101101

102102
if (B[i] % 2 == 0)
@@ -120,7 +120,7 @@ class Drive2 : virtual public Base
120120
int fact()
121121
{
122122
int factorial = 1, max_num = max();
123-
for (int i = 2; i < max_num; i++)
123+
for (int i = 2; i <= max_num; i++)
124124
factorial *= i;
125125
return factorial;
126126
}
@@ -135,7 +135,7 @@ class Drive : public Drive1, public Drive2
135135
public:
136136
void set()
137137
{
138-
for (int i = 0; i < n; i++)
138+
for (int i = 0; i < n; i += 3)
139139
{
140140
// D (D0 is max element in B, D1 is max element in D1, and D2 is the max element in D2),
141141
D[i] = Base::max();
@@ -155,7 +155,7 @@ class Drive : public Drive1, public Drive2
155155
summation += D[i];
156156

157157
int factorial = 1;
158-
for (int i = 2; i < summation; i++)
158+
for (int i = 2; i <= summation; i++)
159159
factorial *= i;
160160
return factorial;
161161
}
@@ -167,7 +167,7 @@ int main()
167167
Drive2 obj2;
168168
Drive obj;
169169

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} ;
171171

172172

173173
arr[1]->Base::set(); // access the base to intialize first

0 commit comments

Comments
 (0)