-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayop.cpp
More file actions
105 lines (100 loc) · 2.58 KB
/
Copy pathArrayop.cpp
File metadata and controls
105 lines (100 loc) · 2.58 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*-------------------------------------------------------------------------------------------------------------------------------------------
Arrayop.cpp
An object-oriented program in cpp to create an array object with respect to method
181713
06-02-19
-------------------------------------------------------------------------------------------------------------------------------------------*/
#include<iostream>
#include<math.h>
using namespace std;
class Arrayop
{
private:
int N,A[30];
public:
Arrayop(int Num);
void InputArray();
void PrintArray();
void BubbleSort();
int MaxArray();
float StdDev();
};
main()
{
Arrayop X(5);
int Max;
cout<<"C++ program to create an array object with respect to method\n\n";
X.InputArray();
X.PrintArray();
X.BubbleSort();
cout<<"\nAfter sorting";
X.PrintArray();
Max=X.MaxArray();
cout<<"The maximum element in the array is: "<<Max;
cout<<"\nThe standard deviation is: "<<X.StdDev();
}
//---------------------------------------------------------Array()-------------------------------------------------------------------------
Arrayop::Arrayop(int Num)
{
N=Num;
}
//---------------------------------------------------------InputArray()----------------------------------------------------------------------
void Arrayop::InputArray()
{
int i;
cout<<"Enter the array elements:\n";
for(i=1;i<=N;i++){
cin>>A[i];
}
}
//---------------------------------------------------------PrintArray()----------------------------------------------------------------------
void Arrayop::PrintArray()
{
int i;
cout<<"\nThe elements in the array are: "<<endl;
for(i=1;i<=N;i++){
cout<<A[i]<<endl;
}
}
//---------------------------------------------------------BubbleSort()----------------------------------------------------------------------
void Arrayop::BubbleSort()
{
int i,j,temp;
for(i=1;i<=N;i++){
for(j=1;j<=N-i;j++){
if(A[j]>=A[j+1]){
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
}
}
}
}
//---------------------------------------------------------MaxArray()----------------------------------------------------------------------
int Arrayop::MaxArray()
{
int Max,i;
Max=A[1];
for(i=2;i<=N;i++){
if(Max<A[i]){
Max=A[i];
}
}
return Max;
}
//---------------------------------------------------------StdDev()----------------------------------------------------------------------
float Arrayop::StdDev()
{
int SumX=0,SumXSqr=0,i;
float Avg,T1,T2,Variance,SDev;
for(i=1;i<=N;i++){
SumX=SumX+A[i];
SumXSqr=SumXSqr+(A[i]*A[i]);
}
Avg=SumX/N;
T2=Avg*Avg;
T1=SumXSqr/N;
Variance=T1-T2;
SDev=sqrt(Variance);
return SDev;
}