- Joined
- Jul 26, 2001
- Location
- Houston, TX
Any help or pointers in the right direction would be appreciated.
Ok I can get this program to work if I put it all into 1 *.cpp file and compile it, it works perfect. But I am having trouble if I try to seperate it into a Proj1_prototype.cpp file and a Proj1_prototype.h file. The main problem I am havinf is that it does not seem to recognize the "string" types in my struct. Here are some of the errors I am getting.
--------------------Configuration: CS_Project - Win32 Debug--------------------
Compiling...
Proj1_prototype.cpp
F:\CS 2310\Proj1\Proj1_prototype.h(13) : error C2146: syntax error : missing ';' before identifier 'Name'
F:\CS 2310\Proj1\Proj1_prototype.h(13) : error C2501: 'string' : missing storage-class or type specifiers
F:\CS 2310\Proj1\Proj1_prototype.h(13) : error C2501: 'Name' : missing storage-class or type specifiers
F:\CS 2310\Proj1\Proj1_prototype.h(14) : error C2146: syntax error : missing ';' before identifier 'ssn'
F:\CS 2310\Proj1\Proj1_prototype.h(14) : error C2501: 'string' : missing storage-class or type specifiers
F:\CS 2310\Proj1\Proj1_prototype.h(14) : error C2501: 'ssn' : missing storage-class or type specifiers
F:\CS 2310\Proj1\Proj1_prototype.cpp(71) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(75) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(108) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(112) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(145) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(149) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(182) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(186) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(219) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(223) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(302) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(306) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(340) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(344) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(378) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(382) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(416) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(420) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(505) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(506) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
Error executing cl.exe.
Proj1_prototype.obj - 26 error(s), 0 warning(s)
Here are the files
Proj1_prototype.cpp
// CS2310 Project 1 Implementation file
//*******************************************
#include <iostream>
#include <fstream>
#include <string>
#include "Proj1_prototype.h"
using namespace std;
//***********************************************************************
//***********************************************************************
void StuRecords::InsertRecord(StudentRecord& newRecord)
{
data[length] = newRecord;
length++;
}
void StuRecords:rintByGrades() const
{
// Postcondition:
// Print out student records by the letter grades, with the records
// of 'A' first, 'B' the second, ..., 'F' the last.
//********************************************
//************* Opens file for writing *******
//********************************************
ofstream fout;
fout.open ("f:/gfile.txt");
//********************************************
if ( fout.fail() )
{
cout<< "Output file opening failed.\n";
exit(1);
}
//********************************************
int i;
int j;
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<"Name";
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<"Student ID";
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Rank";
fout<<"Grade"<<endl;
for ( i = 0; i < 5; i++)
{
if (i == 0)
for (j = 0; j < length; j++)
{
if (data[j].letterGrade == A)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
switch (data[j].rank)
{
case Freshman: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
break;
case Sophomore: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
break;
case Junior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
break;
case Senior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
break;
}
fout<<'A'<<endl;
}
}
if ( i == 1)
for (j = 0; j < length; j++)
{
if (data[j].letterGrade == B)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
switch (data[j].rank)
{
case Freshman: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
break;
case Sophomore: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
break;
case Junior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
break;
case Senior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
break;
}
fout<<'B'<<endl;
}
}
if ( i ==2)
for (j = 0; j < length; j++)
{
if (data[j].letterGrade == C)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
switch (data[j].rank)
{
case Freshman: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
break;
case Sophomore: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
break;
case Junior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
break;
case Senior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
break;
}
fout<<'C'<<endl;
}
}
if (i == 3)
for (j = 0; j < length; j++)
{
if (data[j].letterGrade == D)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
switch (data[j].rank)
{
case Freshman: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
break;
case Sophomore: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
break;
case Junior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
break;
case Senior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
break;
}
fout<<'D'<<endl;
}
}
if (i == 4)
for (j = 0; j < length; j++)
{
if (data[j].letterGrade == F)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
switch (data[j].rank)
{
case Freshman: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
break;
case Sophomore: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
break;
case Junior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
break;
case Senior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
break;
}
fout<<'F'<<endl;
}
}
}
fout<<endl;
fout.close();
}
void StuRecords:rintByRanks() const
{
// Postcondition:
// Print out student records by their classification, with the records
// of "Freshman" first, "Junior" second, ..., Senior the last.
//********************************************
//******* Opens file for writing & appends ***
//********************************************
ofstream fout;
fout.open ("f:/gfile.txt", ios::app);
//********************************************
if ( fout.fail() )
{
cout<< "Output file opening failed.\n";
exit(1);
}
//********************************************
int i;
int j;
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<"Name";
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<"Student ID";
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Rank";
fout<<"Grade"<<endl;
for ( i = 0; i < 4; i++)
{
if (i == 0)
for (j = 0; j < length; j++)
{
if (data[j].rank == Freshman)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
switch (data[j].letterGrade)
{
case A: fout.setf(ios::left);
fout<<'A'<<endl;
break;
case B: fout.setf(ios::left);
fout<<'B'<<endl;
break;
case C: fout.setf(ios::left);
fout<<'C'<<endl;
break;
case D: fout.setf(ios::left);
fout<<'D'<<endl;
break;
case F: fout.setf(ios::left);
fout<<'F'<<endl;
break;
}
}
}
if ( i == 1)
for (j = 0; j < length; j++)
{
if (data[j].rank == Sophomore)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
switch (data[j].letterGrade)
{
case A: fout.setf(ios::left);
fout<<'A'<<endl;
break;
case B: fout.setf(ios::left);
fout<<'B'<<endl;
break;
case C: fout.setf(ios::left);
fout<<'C'<<endl;
break;
case D: fout.setf(ios::left);
fout<<'D'<<endl;
break;
case F: fout.setf(ios::left);
fout<<'F'<<endl;
break;
}
}
}
if ( i ==2)
for (j = 0; j < length; j++)
{
if (data[j].rank == Junior)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
switch (data[j].letterGrade)
{
case A: fout.setf(ios::left);
fout<<'A'<<endl;
break;
case B: fout.setf(ios::left);
fout<<'B'<<endl;
break;
case C: fout.setf(ios::left);
fout<<'C'<<endl;
break;
case D: fout.setf(ios::left);
fout<<'D'<<endl;
break;
case F: fout.setf(ios::left);
fout<<'F'<<endl;
break;
}
}
}
if (i == 3)
for (j = 0; j < length; j++)
{
if (data[j].rank == Senior)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
switch (data[j].letterGrade)
{
case A: fout.setf(ios::left);
fout<<'A'<<endl;
break;
case B: fout.setf(ios::left);
fout<<'B'<<endl;
break;
case C: fout.setf(ios::left);
fout<<'C'<<endl;
break;
case D: fout.setf(ios::left);
fout<<'D'<<endl;
break;
case F: fout.setf(ios::left);
fout<<'F'<<endl;
break;
}
}
}
}
fout.close();
}
StuRecords::StuRecords() {
// Default constructor: Zero the length of the array.
length = 0;
}
//***********************************************************************
//******************** Main Function ************************************
//***********************************************************************
int main() {
StudentRecord recordTemp;
StuRecords CurrentRecords;
int numberOfRecords;
int i;
int classRank;
string string1, string2, string3, string4;
ifstream fin;
ofstream fout;
//********************************************
//********* Opens file for reading ***********
//********************************************
fin.open ("stuflie.txt");
//********************************************
if ( fin.fail() )
{
cout<< "Input file opening failed.\n";
exit(1);
}
//********************************************
fin>>numberOfRecords;
//******************************************************************
//********************* Assignment of records **********************
//******************************************************************
if (numberOfRecords > 0)
for ( i = 0; i < numberOfRecords; i++)
{
fin>> string1;
fin>> string2;
string3 = string1 + ' ' + string2;
recordTemp.Name = string3;
fin>> recordTemp.ssn;
fin>> classRank;
fin>> recordTemp.grades[0] >>recordTemp.grades[1] >> recordTemp.grades[2];
recordTemp.average = (recordTemp.grades[0] + recordTemp.grades[1] + recordTemp.grades[2])/3.0;
switch (classRank)
{
case 1: recordTemp.rank = Freshman;
break;
case 2: recordTemp.rank = Sophomore;
break;
case 3: recordTemp.rank = Junior;
break;
case 4: recordTemp.rank = Senior;
break;
}
if (recordTemp.average >= 90)
recordTemp.letterGrade = A;
else if (recordTemp.average < 90 && recordTemp.average >= 80)
recordTemp.letterGrade = B;
else if (recordTemp.average < 80 && recordTemp.average >= 75)
recordTemp.letterGrade = C;
else if (recordTemp.average < 75 && recordTemp.average >= 70)
recordTemp.letterGrade = D;
else recordTemp.letterGrade = F;
CurrentRecords.InsertRecord(recordTemp);
}
//******************************************************************
//******************* Function Calls *******************************
//******************************************************************
CurrentRecords.PrintByGrades();
CurrentRecords.PrintByRanks();
fin.close();
return 0;
}
Proj1_prototype.h
// CS2310 Project 1 Specification file
const int MAX_NUM_STUDENTS = 15;
const int LEN_SPACING_NAME = 23;
const int LEN_SPACING_SSN = 14;
const int LEN_SPACING_RANK = 12;
enum letRank {Freshman, Sophomore, Junior, Senior};
enum letGrade {A, B, C, D, F};
struct StudentRecord
{
string Name;
string ssn;
letRank rank;
letGrade letterGrade;
int grades[3];
int average;
};
class StuRecords
{
public:
void InsertRecord(StudentRecord& newRecord);
// Precondition:
// A new student record is passed in by newRecord.
// Postcondition:
// The new record is inserted into the bottom of the record array.
// This function assume the array is not sorted.
void PrintByGrades() const;
// Postcondition:
// Print out student records by the letter grades, with the records
// of 'A' first, 'B' the second, ..., 'F' the last.
void PrintByRanks() const;
// Postcondition:
// Print out student records by their classification, with the records
// of "Freshman" first, "Junior" second, ..., Senior the last.
StuRecords();
// Default constructor: Zero the length of the array.
private:
int length; // Keep track the number of students.
StudentRecord data[MAX_NUM_STUDENTS];
};
Thanks!!!
Ok I can get this program to work if I put it all into 1 *.cpp file and compile it, it works perfect. But I am having trouble if I try to seperate it into a Proj1_prototype.cpp file and a Proj1_prototype.h file. The main problem I am havinf is that it does not seem to recognize the "string" types in my struct. Here are some of the errors I am getting.
--------------------Configuration: CS_Project - Win32 Debug--------------------
Compiling...
Proj1_prototype.cpp
F:\CS 2310\Proj1\Proj1_prototype.h(13) : error C2146: syntax error : missing ';' before identifier 'Name'
F:\CS 2310\Proj1\Proj1_prototype.h(13) : error C2501: 'string' : missing storage-class or type specifiers
F:\CS 2310\Proj1\Proj1_prototype.h(13) : error C2501: 'Name' : missing storage-class or type specifiers
F:\CS 2310\Proj1\Proj1_prototype.h(14) : error C2146: syntax error : missing ';' before identifier 'ssn'
F:\CS 2310\Proj1\Proj1_prototype.h(14) : error C2501: 'string' : missing storage-class or type specifiers
F:\CS 2310\Proj1\Proj1_prototype.h(14) : error C2501: 'ssn' : missing storage-class or type specifiers
F:\CS 2310\Proj1\Proj1_prototype.cpp(71) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(75) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(108) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(112) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(145) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(149) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(182) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(186) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(219) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(223) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(302) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(306) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(340) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(344) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(378) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(382) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(416) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(420) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(505) : error C2039: 'Name' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.cpp(506) : error C2039: 'ssn' : is not a member of 'StudentRecord'
F:\CS 2310\Proj1\Proj1_prototype.h(12) : see declaration of 'StudentRecord'
Error executing cl.exe.
Proj1_prototype.obj - 26 error(s), 0 warning(s)
Here are the files
Proj1_prototype.cpp
// CS2310 Project 1 Implementation file
//*******************************************
#include <iostream>
#include <fstream>
#include <string>
#include "Proj1_prototype.h"
using namespace std;
//***********************************************************************
//***********************************************************************
void StuRecords::InsertRecord(StudentRecord& newRecord)
{
data[length] = newRecord;
length++;
}
void StuRecords:rintByGrades() const
{
// Postcondition:
// Print out student records by the letter grades, with the records
// of 'A' first, 'B' the second, ..., 'F' the last.
//********************************************
//************* Opens file for writing *******
//********************************************
ofstream fout;
fout.open ("f:/gfile.txt");
//********************************************
if ( fout.fail() )
{
cout<< "Output file opening failed.\n";
exit(1);
}
//********************************************
int i;
int j;
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<"Name";
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<"Student ID";
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Rank";
fout<<"Grade"<<endl;
for ( i = 0; i < 5; i++)
{
if (i == 0)
for (j = 0; j < length; j++)
{
if (data[j].letterGrade == A)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
switch (data[j].rank)
{
case Freshman: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
break;
case Sophomore: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
break;
case Junior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
break;
case Senior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
break;
}
fout<<'A'<<endl;
}
}
if ( i == 1)
for (j = 0; j < length; j++)
{
if (data[j].letterGrade == B)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
switch (data[j].rank)
{
case Freshman: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
break;
case Sophomore: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
break;
case Junior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
break;
case Senior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
break;
}
fout<<'B'<<endl;
}
}
if ( i ==2)
for (j = 0; j < length; j++)
{
if (data[j].letterGrade == C)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
switch (data[j].rank)
{
case Freshman: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
break;
case Sophomore: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
break;
case Junior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
break;
case Senior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
break;
}
fout<<'C'<<endl;
}
}
if (i == 3)
for (j = 0; j < length; j++)
{
if (data[j].letterGrade == D)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
switch (data[j].rank)
{
case Freshman: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
break;
case Sophomore: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
break;
case Junior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
break;
case Senior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
break;
}
fout<<'D'<<endl;
}
}
if (i == 4)
for (j = 0; j < length; j++)
{
if (data[j].letterGrade == F)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
switch (data[j].rank)
{
case Freshman: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
break;
case Sophomore: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
break;
case Junior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
break;
case Senior: fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
break;
}
fout<<'F'<<endl;
}
}
}
fout<<endl;
fout.close();
}
void StuRecords:rintByRanks() const
{
// Postcondition:
// Print out student records by their classification, with the records
// of "Freshman" first, "Junior" second, ..., Senior the last.
//********************************************
//******* Opens file for writing & appends ***
//********************************************
ofstream fout;
fout.open ("f:/gfile.txt", ios::app);
//********************************************
if ( fout.fail() )
{
cout<< "Output file opening failed.\n";
exit(1);
}
//********************************************
int i;
int j;
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<"Name";
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<"Student ID";
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Rank";
fout<<"Grade"<<endl;
for ( i = 0; i < 4; i++)
{
if (i == 0)
for (j = 0; j < length; j++)
{
if (data[j].rank == Freshman)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Freshman";
switch (data[j].letterGrade)
{
case A: fout.setf(ios::left);
fout<<'A'<<endl;
break;
case B: fout.setf(ios::left);
fout<<'B'<<endl;
break;
case C: fout.setf(ios::left);
fout<<'C'<<endl;
break;
case D: fout.setf(ios::left);
fout<<'D'<<endl;
break;
case F: fout.setf(ios::left);
fout<<'F'<<endl;
break;
}
}
}
if ( i == 1)
for (j = 0; j < length; j++)
{
if (data[j].rank == Sophomore)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Sophomore";
switch (data[j].letterGrade)
{
case A: fout.setf(ios::left);
fout<<'A'<<endl;
break;
case B: fout.setf(ios::left);
fout<<'B'<<endl;
break;
case C: fout.setf(ios::left);
fout<<'C'<<endl;
break;
case D: fout.setf(ios::left);
fout<<'D'<<endl;
break;
case F: fout.setf(ios::left);
fout<<'F'<<endl;
break;
}
}
}
if ( i ==2)
for (j = 0; j < length; j++)
{
if (data[j].rank == Junior)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Junior";
switch (data[j].letterGrade)
{
case A: fout.setf(ios::left);
fout<<'A'<<endl;
break;
case B: fout.setf(ios::left);
fout<<'B'<<endl;
break;
case C: fout.setf(ios::left);
fout<<'C'<<endl;
break;
case D: fout.setf(ios::left);
fout<<'D'<<endl;
break;
case F: fout.setf(ios::left);
fout<<'F'<<endl;
break;
}
}
}
if (i == 3)
for (j = 0; j < length; j++)
{
if (data[j].rank == Senior)
{
fout.width(LEN_SPACING_NAME);
fout.setf(ios::left);
fout<<data[j].Name;
fout.width(LEN_SPACING_SSN);
fout.setf(ios::left);
fout<<data[j].ssn;
fout.width(LEN_SPACING_RANK);
fout.setf(ios::left);
fout<<"Senior";
switch (data[j].letterGrade)
{
case A: fout.setf(ios::left);
fout<<'A'<<endl;
break;
case B: fout.setf(ios::left);
fout<<'B'<<endl;
break;
case C: fout.setf(ios::left);
fout<<'C'<<endl;
break;
case D: fout.setf(ios::left);
fout<<'D'<<endl;
break;
case F: fout.setf(ios::left);
fout<<'F'<<endl;
break;
}
}
}
}
fout.close();
}
StuRecords::StuRecords() {
// Default constructor: Zero the length of the array.
length = 0;
}
//***********************************************************************
//******************** Main Function ************************************
//***********************************************************************
int main() {
StudentRecord recordTemp;
StuRecords CurrentRecords;
int numberOfRecords;
int i;
int classRank;
string string1, string2, string3, string4;
ifstream fin;
ofstream fout;
//********************************************
//********* Opens file for reading ***********
//********************************************
fin.open ("stuflie.txt");
//********************************************
if ( fin.fail() )
{
cout<< "Input file opening failed.\n";
exit(1);
}
//********************************************
fin>>numberOfRecords;
//******************************************************************
//********************* Assignment of records **********************
//******************************************************************
if (numberOfRecords > 0)
for ( i = 0; i < numberOfRecords; i++)
{
fin>> string1;
fin>> string2;
string3 = string1 + ' ' + string2;
recordTemp.Name = string3;
fin>> recordTemp.ssn;
fin>> classRank;
fin>> recordTemp.grades[0] >>recordTemp.grades[1] >> recordTemp.grades[2];
recordTemp.average = (recordTemp.grades[0] + recordTemp.grades[1] + recordTemp.grades[2])/3.0;
switch (classRank)
{
case 1: recordTemp.rank = Freshman;
break;
case 2: recordTemp.rank = Sophomore;
break;
case 3: recordTemp.rank = Junior;
break;
case 4: recordTemp.rank = Senior;
break;
}
if (recordTemp.average >= 90)
recordTemp.letterGrade = A;
else if (recordTemp.average < 90 && recordTemp.average >= 80)
recordTemp.letterGrade = B;
else if (recordTemp.average < 80 && recordTemp.average >= 75)
recordTemp.letterGrade = C;
else if (recordTemp.average < 75 && recordTemp.average >= 70)
recordTemp.letterGrade = D;
else recordTemp.letterGrade = F;
CurrentRecords.InsertRecord(recordTemp);
}
//******************************************************************
//******************* Function Calls *******************************
//******************************************************************
CurrentRecords.PrintByGrades();
CurrentRecords.PrintByRanks();
fin.close();
return 0;
}
Proj1_prototype.h
// CS2310 Project 1 Specification file
const int MAX_NUM_STUDENTS = 15;
const int LEN_SPACING_NAME = 23;
const int LEN_SPACING_SSN = 14;
const int LEN_SPACING_RANK = 12;
enum letRank {Freshman, Sophomore, Junior, Senior};
enum letGrade {A, B, C, D, F};
struct StudentRecord
{
string Name;
string ssn;
letRank rank;
letGrade letterGrade;
int grades[3];
int average;
};
class StuRecords
{
public:
void InsertRecord(StudentRecord& newRecord);
// Precondition:
// A new student record is passed in by newRecord.
// Postcondition:
// The new record is inserted into the bottom of the record array.
// This function assume the array is not sorted.
void PrintByGrades() const;
// Postcondition:
// Print out student records by the letter grades, with the records
// of 'A' first, 'B' the second, ..., 'F' the last.
void PrintByRanks() const;
// Postcondition:
// Print out student records by their classification, with the records
// of "Freshman" first, "Junior" second, ..., Senior the last.
StuRecords();
// Default constructor: Zero the length of the array.
private:
int length; // Keep track the number of students.
StudentRecord data[MAX_NUM_STUDENTS];
};
Thanks!!!