Ok, I created a mess, and I am in 36 complier errors. Now, I fixed most of what I know how to fix but some of the errors I don't know how to fix and I am taking a different approach to this problem.
The program is supposed to ask a student what is name and grades are, then it is supposed to get grades from a student and write them to a file using dynamic memory allocation. I will post the code first and if anyone needs to see the billions of errors I can post the log file.
OS: XP Tablet PC Edition.
Complier: Visual C++ 2005 express
Code:
#include <iostream>
#include <cmath>
#include <iostream>
using namespace std;
class Student
{
public:
void calculate();
void writeToFile();
char name[20];
int age, grade;
int numtests;
int i = 0;
int *iPtr;
};
int main()
{
Student stud;
//Ask for students name
cout << "Enter the student's name: ";
cin.get(stud.name, 20, '\n');
cout << "Enter the student's age and grade seperated by a space: ";
cin >> stud.age >> stud.grade;
stud.calculate();
stud.writeToFile();
return 0;
}
//Calculate grades
void calculate()
{
Student st;
cout << "Enter the number of tests you are entering: ";
cin >> st.numtests;
int * st.iPtr = new int[st.numtests];
for (int st.i=0; st.i<st.numtests; st.i++)
{
cout << "Enter test score #" << st.i + 1 << " : ";
cin >> st.iPtr[i];
}
}
//WritetoFile function
int writeToFile()
{
Student stu;
ifstream a_file;
cout << "Now writing data to file.....";
ofstream a_file("grades.txt");
if (a_file.is_open() )
{
cout << "The file opened incorrectly, program terminating.";
return 0;
}
else
{
a_file << "The student's name is: " << stu.name << endl;
a_file << "The student's grade is: " << stu.grade << endl;
for (int stu.i = 0; stu.i < stu.numtests; stu.i++;)
{
a_file << "Test score #" << stu.i + 1 << " is " << stu.iPtr[stu.i] << endl;
cout << "Data finished writing to file.";
delete [] stu.iPtr;
}
}
}