/*Write a program that reads a group of numbers from the user
and places them in an array of type float.
Once the numbers are stored in the array,
the program should average them and print the result.
Use pointer notation wherever possible*/
/*
first of all we enter the num of elements and then user will enter elements value,and then calculate average using pointer*/
#include <iostream>
using namespace std;
class Avg
{
public:
int n,i;
float arr[50],sum=0,average;
void get()
{
cout<<"enter the number of elements:";
cin>>n;
cout<<"enter elements:\n";
for(i=0;i<n;i++)
{
cin>>arr[i];
}
}
void show()
{
for(i=0;i<n;i++)
{
sum+= arr[i];
}
average=sum/n;
cout<<"average of the above entered number is:"<<average;
}
};
int main()
{
Avg *obj;
obj->get();
obj->show();
return 0;
}
Output
0 comments: