# include<iostream>
#include<conio.h>
using namespace std;
class array{
float *f_a;
public:
array(int);
~array();
void getdata(int);
float average(int);
};
array::array(int k){
f_a=new float[k];
if(!f_a){
cout<<"Allocation failure."<<endl;
}
}
array::~array(){
delete[]f_a;
}
void array::getdata(int l){
cout<<"Enter "<<l<<" elements: ";
for(int i=0; i<l;i++){
cin>>f_a[i];
}
}
float array::average(int m){
float sum;
for(int j=0;j<m;j++){
sum+=f_a[j];
}
return(sum/m);
}
int main(){
int n;
cout<<"Number of elements: ";
cin>>n;
array f(n);
f.getdata(n);
cout<<"The average is: "<<f.average(n)<<endl;
return 0;
}
|
Friday, April 28, 2017
Calculating Average Using OOP (C++)
Subscribe to:
Post Comments (Atom)
-
#include<bits/stdc++.h> #define ll long long using namespace std ; ll n , k , t_case ; ll bigmod ( ll b , ll p , ll m...
-
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 ...
-
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 3...
No comments:
Post a Comment