Can anyone describe this program

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#include <iostream.h>
#include <math.h>

class Statistc
{

//-----------------------------------------------------------------------------------
private:

int array[100];
int count;

//-----------------------------------------------------------------------------------

public:

Statistc(int a[], int n)
{
count=n;
int i;

for( i=0 ; i<count; i++)
{
array[i] = a[i];
}

sortArray();

}

//-----------------------------------------------------------------------------------

void sortArray()
{
	int i,j;
	
	for(i=0; i<count; i++)
	{
		for (j=0; j<count-1; j++)
		{
			if(array[j]<array[j+1])
			{
				int temp=array[j+1];
				array[j+1]=array[j];
				array[j]=temp;
			}
		}
	}
}


//-----------------------------------------------------------------------------------
int getTotal()
{
int total=0;
    for(int i=0; i<count; i++)
{
total=total + array[i];
} 

return total;
}

//-----------------------------------------------------------------------------------

int getMean()
{
int mean;
mean= (getTotal())/(getCount());
return mean;
}

//-----------------------------------------------------------------------------------
int getDifferenceAndSquare(int num)
{
int dif = (num - getMean());
return dif*dif;
}
//-----------------------------------------------------------------------------------

double getStrdDeviation()
{
int sumOfDifs = 0;
int meanOfDifs;
double sqrtOfMean;
double strdDeviation;
for ( int i=0; i<count; i++)
{
sumOfDifs = sumOfDifs + getDifferenceAndSquare(array[i]);
}

meanOfDifs = sumOfDifs / getCount();
sqrtOfMean = sqrt( meanOfDifs );


strdDeviation = sqrtOfMean;
return strdDeviation;
}

//-----------------------------------------------------------------------------------


int getCount()
{
return count;
}

//------------------------------------------------------------------------------------

int *getMaxAndMin()
{
int maxAndMin[2];

maxAndMin[0] = array[0];
maxAndMin[1] = array[0];

for( int i=0; i<count; i++ )
    {
        if( array[i] > maxAndMin[0] ) maxAndMin[0] = array[i];
        if( array[i]< maxAndMin[1] ) maxAndMin[1] = array[i];
    }

int *pointToMaxAndMin = maxAndMin;
return pointToMaxAndMin;
}

//-----------------------------------------------------------------------------------

int getFrequencyOfNumber(int num)
{
int countAppearance = 0;

for(int i=0; i<count; i++)
{
if( array[i] == num )
{
countAppearance++;
}
}
return countAppearance;
}

//-----------------------------------------------------------------------------------

int * getFrequency()
{
int frequency[100];
int * pointToFrequency = frequency;

for(int i=0; i<count; i++)
{
frequency[i] = getFrequencyOfNumber(array[i]);
}

return pointToFrequency;
}

//-----------------------------------------------------------------------------------
int getMode()
{
int mode;

int *ptr = getFrequency();
int max;
max = *ptr;
int index=0;
for ( int i=0; i<count; i++ )
{
if (*(ptr+i) > max)
{
max = *(ptr+i);
index = i;
}
}
mode = array[index];
return mode;
}

//-----------------------------------------------------------------------------------

double getMedian()
{
double median;

if((count%2)==0)
{
median = ( ( array[(count/2)] + array[(count/2 - 1)]) / 2);
}
else
{
median = array[((getCount() + 1) / 2-1)];
}
return median;
}

//-----------------------------------------------------------------------------------
int *getArray()
{
	int * ptr = array;
	return ptr;
}
}; //end of class Statistc

//-----------------------------------------------------------------------------------

int main()
{

int array[100];
int n;

cout<<"\nEnter how many number do you want to insert\n";
cin>>n;

cout<<"\nInsert"<<n<<" numbers\n";
int i;
for( i=0; i<n; i++)
{
cin>>array[i];
}

Statistc object(array, n);

cout<<"\nTotal : "<<object.getTotal()<<"\n";
cout<<"\nMean : "<<object.getMean()<<"\n";
cout<<"\nStandard Deviation: "<<object.getStrdDeviation()<<"\n";
cout<<"\nCount : "<<object.getCount()<<"\n";
int *ptrToMaxAndMin = object.getMaxAndMin();
cout<<"\nMaximum : "<<*ptrToMaxAndMin<<"\nMinimum : "<<*(ptrToMaxAndMin+1)<<"\n";

int *ptrToFrequency = object.getFrequency();
int j;
cout<<"\nFREQUNCIES of the numbers\n";
for ( j=0; j<n; j++)
{
cout<<"Frequency of"<<array[j]<<" : "<<*(ptrToFrequency+j)<<"\n";
}
cout<<"\nMode : "<<object.getMode()<<"\n";


cout<<"\nMedian : "<<object.getMedian()<<"\n";

cout<<"Enter the largestKth \n";
int * ptr = object.getArray();
int kth;
cin>>kth;
cout<<"\nLargest "<<kth<<" number is\n"<<*(ptr+kth-1)<<"\n";


return 0;
} //end of main


Can anyone explain this program and description to me at least
I need help is necessary to
Or at least help me to describe the function MaxAndMin - Mode - Frequency

Please, Please , Please, =(
You'll have to ask more specific questions (what question?) than that.

Or at least help me to describe the function MaxAndMin - Mode - Frequency

I'm gonna hazard a guess and say the functions calculate the minimum and maximum, mode and frequency of the elements in "array". They're also all broken, since pointers to local arrays are returned.
Last edited on
iostream is not .h and math.h should be cmath
This program is correct
100%
But I want a description of the way it works

--
Athar : can you explain it more
This program is correct

No, it isn't.

can you explain it more

What exactly? I'm not holding a dissertation starting from Adam and Eve.
why was i reported what did i do?

edit: if it was because you don't want to know about header files they are both not proper c++
Last edited on
Can you is be patient with little
I am beginner in programming
I have this program .. I want to write how it was done
What are the laws used in his work
I do not know what the solution
did you report me reemu? why!!!
I am so sorry
I thought that the word report means Reply
My language is too weak ="(
Forgive me
I have this program .. I want to write how it was done
What are the laws used in his work

Which lines don't you understand?
If you were tasked with this, surely you must have had some lessons on C++ before.
If not, now would be a good time to catch up.
its ok i just wanted to make sure i didnt do anything wrong
Topic archived. No new replies allowed.