I am trying to write a C++ class definition called student.h
which will read the grades from the input file defined by the user, and write the grades into an output file
defined by the user. This is what I have so far but I'm getting this error and I have no idea how to fix it. I was wondering if anyone could help me with this problem:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <fstream>
using namespace std;
class student {
private:
int id;
int n; // no of- grades
int A[200]; // array to hold the grades
public:
student(void); // constructor
void READ(void); // to read from a file to be prompted by user;
void PRINT(void); // to write into an output file
void showStudent(); //show the three attributes
void REVERSE_PRINT(void); // to write into output file in reverse order;
double GPA(void); // interface to get the GPA
double FAIL_NUMBER(void); //interface to get the number of fails
};
void student::READ()
{
ifstream inFile;
ofstream outFile;
string fileName;
cout << "Input the name of your file" << endl;
cin >> fileName;
inFile.open(fileName.c_str());
if (inFile.fail()) {
cout << fileName << "does not exist!" << endl;
}
else
{
int x;
inFile >> x;
while (inFile.good())
{
for(int i=0;i<200;i++)
{
A[i]=x;
}
inFile >> x;
}
inFile.close();
}
}
int main()
{
student a();
a.READ(); //Line 56
}
This is the syntax that I get when I compile the code:
1>------ Build started: Project: New Project, Configuration: Debug Win32 ------
1> Main.cpp
1>c:users
andydocumentsvisual studio 2012projects
ew project
ew projectmain.cpp(56): error C2228: left of '.READ' must have class/struct/union
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
See Question&Answers more detail:os