Hello all I am a second year C++ student in college and I am running into some issues with a code assignment I am writing. *Note: I realize that there may be better ways of doing the code but I am following my instructors guidelines so please no posts about that I have had bad expericane*
Anyway here is my code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
//************************************
const int NAMESIZE=11;
const int FILENAMESIZE=51;
const int ARRAYSIZE=20;
int N=0;
typedef char Name_t[NAMESIZE];
typedef int Grade_t;
typedef char Filename_t[FILENAMESIZE];
typedef fstream Datafile_t;
typedef fstream Outfile_t;
//*************************************
class cStudent
{
private:
Name_t fname;
Name_t lname;
Grade_t t1;
Grade_t t2;
Grade_t t3;
Grade_t t4;
Grade_t assigngrade;
Grade_t examgrade;
public:
cStudent();//default constructor
cStudent(Name_t NewName, Grade_t NewGrade);
void Read(Datafile_t &Datafile);
void Print(Outfile_t &Outfile);
//set
void set_fname(Name_t fname)
{ strcpy(fname,fname);}
void set_lname(Name_t lname)
{ strcpy(lname,lname);}
void set_t1(Grade_t t1)
{ t1=t1;}
void set_t2(Grade_t t2)
{ t2=t2;}
void set_t3(Grade_t t3)
{ t3=t3;}
void set_t4(Grade_t t4)
{ t4=t4;}
void set_assigngrade(Grade_t assigngrade)
{ assigngrade=assigngrade;}
void set_examgrade(Grade_t examgrade)
{ examgrade=examgrade;}
//end set
//get
void get_fname(Name_t &fname)
{ strcpy(fname,this->fname);}
void get_lname(Name_t &lname)
{ strcpy(lname,this->lname);}
int get_t1(Grade_t &t1)
{return t1;}
int get_t2(Grade_t &t2)
{return t2;}
int get_t3(Grade_t &t3)
{return t3;}
int get_t4(Grade_t &t4)
{return t4;}
int get_assigngrade(Grade_t &assigngrade)
{return assigngrade;}
int get_examgrade(Grade_t &examgrade)
{return assigngrade;}
//end get
};//end of class cStudent
typedef cStudent StudentArray[30];
StudentArray CSCI208Class;//array
StudentArray TempStudent;//array #2
void InputIntoArray(StudentArray &CSCI208Class, int &N);
void PrintFromArray(StudentArray CSCI208Class, int N);
//***MAIN***
main()
{
StudentArray TempStudent;
StudentArray CSCI208Class;
InputIntoArray(CSCI208Class,N);
PrintFromArray(CSCI208Class,N);
};//***end_MAIN***
void PrintFromArray(StudentArray CSCI208Class, int N)
{
Filename_t Filename;
Outfile_t Outfile;
cout<<"Please enter the name of the output file to be created:"<<endl;
cin>>Filename;
cout<<"Opening output file......."<<endl;
Outfile.open(Filename,ios::out);
Outfile<<setw(10)<<"Name"<<" "<<"Test Grades"<<" "<<"Assignment Grade"<<" "<<"Exam Grade"<<endl;
Outfile<<endl;
for(int I=0; I<N; I++)
{
Name_t fname;
Name_t lname;
Grade_t t1;
Grade_t t2;
Grade_t t3;
Grade_t t4;
Grade_t assigngrade;
Grade_t examgrade;
CSCI208Class[I].get_fname(fname);
CSCI208Class[I].get_lname(lname);
CSCI208Class[I].get_t1(t1);
CSCI208Class[I].get_t2(t2);
CSCI208Class[I].get_t3(t3);
CSCI208Class[I].get_t4(t4);
CSCI208Class[I].get_assigngrade(assigngrade);
CSCI208Class[I].get_examgrade(examgrade);
Outfile<<setw(7)<<fname<<" "<<lname<<setw(6)<<t1<<" "<<t2<<" "<<t3<<" "<<t4<<" "<<assigngrade<<" "<<examgrade<<endl;
Outfile<<"******************************************************"<<endl;
};//end for loop
cout<<endl;
cout<<"The number of reccords in the output is "<<N<<"."<<endl;
cout<<"Now closing all files............"<<endl;
Outfile.close();
cout<<"Terminating program........GOODBYE...."<<endl;
};//end print from array
void InputIntoArray(StudentArray &CSCI208Class, int &N)
{
Filename_t Filename;
Datafile_t Datafile;
cout<<"Enter the name of the data file:"<<endl;
cin>>Filename;
cout<<"Opening Datafile..............."<<endl;
StudentArray TempStudent;
Datafile.open(Filename,ios::in);
Datafile>>TempStudent::fname;
while(!Datafile.eof())
{
N=0;
Datafile>>TempStudent::lname;
Datafile>>TempStudent::t1;
Datafile>>TempStudent::t2;
Datafile>>TempStudent::t3;
Datafile>>TempStudent::t4;
Datafile>>TempStudent::assigngrade;
Datafile>>TempStudent::examgrade;
CSCI208Class[N]=TempStudent;
N=N+1;
Datafile>>TempStudent::fname;
}//end while loop
cout<<"Closing Datafile............"<<endl;
Datafile.close();
cout<<"Begining secondary processes.............."<<endl;
};//end InputIntoArray
I am compiling in Vi (again because we have to) and here are the following errors I am getting:
assign3.cpp: In function ‘void InputIntoArray(cStudent (&)[30], int&)’:
assign3.cpp:140: error: ‘TempStudent’ is not a class or namespace
assign3.cpp:144: error: ‘TempStudent’ is not a class or namespace
assign3.cpp:145: error: ‘TempStudent’ is not a class or namespace
assign3.cpp:146: error: ‘TempStudent’ is not a class or namespace
assign3.cpp:147: error: ‘TempStudent’ is not a class or namespace
assign3.cpp:148: error: ‘TempStudent’ is not a class or namespace
assign3.cpp:149: error: ‘TempStudent’ is not a class or namespace
assign3.cpp:150: error: ‘TempStudent’ is not a class or namespace
assign3.cpp:152: error: no match for ‘operator=’ in ‘CSCI208Class[N] = TempStudent’
assign3.cpp:17: note: candidates are: cStudent& cStudent::operator=(const cStudent&)
assign3.cpp:154: error: ‘TempStudent’ is not a class or namespace
Im really stuck as to what is wrong, I have tried declaring the class in diffrent areas, etc... everything I know to do but have come up with nothing.
Is there any help out there?
Thanks
-atticusr5