-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquare,Cube and Sum array indexes.cpp
More file actions
56 lines (56 loc) · 1.33 KB
/
Square,Cube and Sum array indexes.cpp
File metadata and controls
56 lines (56 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*Write a program that uses four arrays "numbers", "squares","cubes" and "sums" each consisting of 5 elements. The number array stores
the values of its indexes, the square array stores the squares of its indexes, the "cubes" array stores the cubes of its indexes and
"sums" array stores the sum of corresponding indexes of three arrays. The program should display the values of all arrays and the total
of all values in the "sums" array.*/
#include<iostream>
#include<array>
using namespace std;
class CLASS{
private:
array<int,5>numbers;
array<int,5>squares;
array<int,5>cubes;
array<int,5>sums;
int sumsTotal;
public:
CLASS();
void calc();
void display();
};
CLASS::CLASS(){
sumsTotal=0;
}
void CLASS::calc(){
for(int i=0;i<=4;i++){
numbers[i]=i;
squares[i]=i*i;
cubes[i]=i*i*i;
sums[i]=numbers[i]+squares[i]+cubes[i];
}
}
void CLASS::display(){
cout<<"\nnumbers :\t";
for(int i=0;i<5;i++){
cout<<numbers[i]<<"\t";
}
cout<<"\nsquares :\t";
for(int i=0;i<5;i++){
cout<<squares[i]<<"\t";
}
cout<<"\ncubes :\t\t";
for(int i=0;i<5;i++){
cout<<cubes[i]<<"\t";
}
cout<<"\nsums :\t\t";
for(int i=0;i<5;i++){
cout<<sums[i]<<"\t";
sumsTotal+=sums[i];
}
cout<<"\nTotal of sums :\t"<<sumsTotal;
}
int main(){
CLASS obj;
obj.calc();
obj.display();
return 0;
}