Skip to content

Commit 9ff301d

Browse files
author
samir176520
committed
update
1 parent c3ba744 commit 9ff301d

File tree

2 files changed

+134
-2
lines changed

2 files changed

+134
-2
lines changed

sheet6/problem2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ int main()
9595

9696
cout << "\nStudent Data:\n";
9797
for (int i = 0; i < 3; i++)
98-
{
9998
students[i].printStudentData();
100-
}
99+
100+
//system("pause");
101101
return 0;
102102
}

sheet6/problem3.cpp

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#include <iostream>
2+
#include <cmath>
3+
#include <string>
4+
using namespace std;
5+
6+
class Data1
7+
{
8+
protected: // we are just growed <3
9+
string S1;
10+
double D1[20];
11+
int a, n;
12+
public:
13+
void readData1()
14+
{
15+
cout << "Enter S1 (string): ";
16+
cin >> S1;
17+
cout << "Enter n (number of elements): ";
18+
cin >> n;
19+
cout << "Enter elements of D1: ";
20+
for (int i = 0; i < n; i++)
21+
cin >> D1[i];
22+
23+
cout << "Enter a (integer): ";
24+
cin >> a;
25+
}
26+
27+
double sum1()
28+
{
29+
double sum = 0;
30+
for (int i = 0; i < n; i++)
31+
for (int j = 0; j <= i; j++)
32+
{
33+
if (/*type casting*/int(D1[j] + 0.5) % a == 0)
34+
sum += pow(D1[j], 2*(j + 1));
35+
else
36+
sum += pow(D1[j], j + 1);
37+
}
38+
return sum;
39+
}
40+
41+
void display1()
42+
{
43+
cout << "string is " << S1 << endl;
44+
cout << "constant is " << a << endl;
45+
46+
cout << "elemnts of D1:"<< endl;
47+
for (int i = 0 ;i < n; i++) // just for style
48+
{
49+
cout << D1[i];
50+
cout << ((i + 1) % 5 == 0 && i != 0? "\n": " ");
51+
}
52+
}
53+
};
54+
55+
class Data2
56+
{
57+
protected:
58+
string S2;
59+
double D2[20];
60+
int m, b;
61+
public:
62+
void readData2()
63+
{
64+
cout << "Enter S2 (string): ";
65+
cin >> S2;
66+
cout << "Enter m (number of elements): ";
67+
cin >> m;
68+
cout << "Enter elements of D2: ";
69+
for (int i = 0; i < m; i++) {
70+
cin >> D2[i];
71+
}
72+
cout << endl;
73+
}
74+
75+
double sum2()
76+
{
77+
double sum = 0;
78+
for (int i = 0; i < m; i++)
79+
for (int j = 0; j <= i; j++)
80+
{
81+
if (D2[j] > b)
82+
sum += pow(D2[j], 2*(j + 1));
83+
else
84+
sum += pow(D2[j], j + 1);
85+
}
86+
return sum;
87+
}
88+
89+
void display2()
90+
{
91+
cout << "string is " << S2 << endl;
92+
cout << "constant is " << b << endl;
93+
94+
cout << "elemnts of D1:"<< endl;
95+
for (int i = 0 ;i < m; i++) // just for style
96+
{
97+
cout << D2[i];
98+
cout << ((i + 1) % 5 == 0 && i != 0? "\n": " ");
99+
}
100+
cout << endl;
101+
}
102+
};
103+
104+
class Data : public Data1, public Data2
105+
{
106+
private:
107+
string ND;
108+
int T_sum;
109+
public:
110+
void calculateSum() {
111+
T_sum = sum1() + sum2();
112+
}
113+
114+
void display()
115+
{
116+
display1();
117+
display2();
118+
cout << "ND: " << ND << ", Total Sum: " << T_sum << endl;
119+
}
120+
};
121+
122+
int main()
123+
{
124+
Data d;
125+
d.readData1();
126+
d.readData2();
127+
d.calculateSum();
128+
d.display();
129+
130+
//system("pause");
131+
return 0;
132+
}

0 commit comments

Comments
 (0)