C++: I'm using Microsoft Visual Studio 2012 and I am not sure what to do about these two errors:
2 IntelliSense: identifier "x" is undefined
Error 1 error C2065: 'x' : undeclared identifier
Prompt: Make program that reads 20 integers, display that array, and find min, max, sum, and avg.
One method named "read from user file" which will ask the user to input a filename and will then read from 1 to 20 integers from that file, but not calculate any statistics. Second method will display the values read in, in the order they were found in the file. Third method will calculate the statistics and store these in the appropriately named variables that are also to be declared in the class. Finally a fourth method will display those statistics from those variables. Your int main function will create an object variable of the Numbers class type. It will then use that object to call those four methods, one after another, in order to demonstrate that the class and it's methods work correctly. No global variables should be used in this program. The Numbers class will be defined in its own .h file, and will use the Ifndef Trick. Make no system calls. User Interface Note that no debugging information (useful for testing a program's internal states) should be output in the submitted program
//numbers1.cpp//
#include <iostream>
#include <fstream>
#include <string>
#include "numbers1.h"
#define x 20
using namespace std;
void Numbers::read_from_user_file(int m_arr)
{
ifstream f("Numbers.txt");
if(f.is_open())
{
cout << "File Open successful!" << endl;
while(!f.eof() && i<a[x])
{
f>>a[i];
i++;
}a[i-1] = '\0';
}
}
void Numbers::displays(int m_arr)
{
for(i=0; i<m_arr; i++)
cout<<a[i]<<" ";
}
void Numbers::m_min(int m_arr)
{
int min=a[0];
for(i=1; i<m_arr; i++)
if(a[i]<min)
min=a[i];
cout<<"\nMinimum= "<<min;
}
void Numbers::m_max(int m_arr)
{
int max=a[0];
for(i=1; i<m_arr; i++)
if(a[i]>max)
max=a[i];
cout<<"\nMaximum= "<<max;
}
void Numbers::sum_tot(int m_arr)
{
int sum=0;
for(i=0; i<m_arr; i++)
sum+=a[i];
cout<<"\nSum= "<<sum;
}
void Numbers::avg(int m_arr)
{
double avg=0;
for (i=0; i<m_arr; i++)
avg+=a[i];
avg/=m_arr;
cout << "\nAverage= " << avg;
}
int main()
{
Numbers obj;
fstream f;
int m_arr=20;
cout<<"\nNumbers: \n";
obj.read_from_user_file(m_arr);
obj.displays(m_arr);
obj.m_min(m_arr);
obj.m_max(m_arr);
obj.sum_tot(m_arr);
obj.avg(m_arr);
cout<<endl;
system("pause");
return 0;
}
//numbers1.h
#ifndef NUMBERS_H
#define NUMBERS_H
class Numbers
{
private:
int i, a[x];
public:
void m_min(int);
void m_max(int);
void sum_tot(int);
void avg(int);
void read_from_user_file(int);
void displays(int);
};
#endif
**//numbers1.txt// **
20 13 15 16 18 12 21 34 54 6 25 29 53 36 42 66 41 14 85 30