I am having to write a program that works with class files.
The class file and the header file CAN NOT be changed. I have to write main.
I understand the concept but am not sure how to work with the "class" part and might be trying to use it in the same way you would an array.
any help or advice would be greatly appreciated.
here are the three files and the list of errors that I am getting.
this is the main file
this is the class filethis is the class fileCode:/* Jessie Brown cop2334 */ #include "Student.h" //Prototypes -- function declarations. //----------------------------------- void Menu_Selection(); void enter_students (int[] student[STUDENT_LIMIT], total=0, examnumber=0; int exam[EXAM_LIMIT];,studentID,STUDENT_LIMIT,total); cout << endl; break; case 2: cout << "works 2"; cout << endl; break; case 3: cout << "works 3"; cout << endl; break; case 4: cout << "works 4"; cout << endl; break; case 5: cout << "End of Program.\n"; break; default: cout << "Not a valid option. Please choose a valid option. \n\n"; } }while (option != 5); } /*------------------------------------------------------------------------------ This function allows a user to add an account with its beginning balance. accounts are to be sorted and no to account numbers are to be the same ------------------------------------------------------------------------------*/ void enter_accounts (int student[],int studentID,const int STUDENT_LIMIT, int& total) { string temp1; string temp2; int tempID; if(total >= STUDENT_LIMIT) { cout <<"Registration closed for this section.\n"; } else if(total <STUDENT_LIMIT) { cout <<"Please enter students first name.\n"; cin >> temp1; cout <<"Please enter students last name.\n"; cin << temp2; student[total].setName(temp1,temp2); cout << "Enter student ID.\n"; cin >> tempID; student[total].setID(tempID); cout << student[total].getFULLNAME() <<endl; cout << "ID: " << student[total].getID() << endl; total++; } }
this is the header file (student.h)this is the header file (student.h)Code:#include "Student.h" /* This is a constructor. It assigns default values to a new Student. */ Student::Student() { ID = -1; lastName = ""; firstName = ""; for( int i=0; i<EXAM_LIMIT; i++ ) exams[i] = -1; } /* Returns full name formatted LAST, FIRST */ string Student::getFullName() { return lastName + ", " + firstName; } /* Assigns the two parameters as first and last names. */ void Student::setName( string theFirstName, string theLastName ) { firstName = theFirstName; lastName = theLastName; } /* Standard getter (accessor) for ID */ int Student::getID() { return ID; } /* Standard setter (mutator) for ID */ void Student::setID( int theID ) { ID = theID; } /* Accesses the desired score. If the exam number does not map to the array it returns a -1. Notice, this function does not test for a negative test score. */ double Student::getExamScore( int examNumber ) { if( examNumber < 0 || examNumber > EXAM_LIMIT ) return -1; return exams[examNumber]; } /* Sets the indicated exam to the score provided. This over writes any score previously entered without warning!! */ void Student::setExamScore( int examNumber, double score ) { if( examNumber < 0 || examNumber > EXAM_LIMIT ) return; exams[examNumber] = score; } /* Returns the average of all positive test scores. Negative scores are assumed to be invalid. If the total of the scores is zero, return a zero. */ double Student::getExamAverage() { double total = 0; int examCount = 0; for( int i=0; i<EXAM_LIMIT; i++ ) if( exams[i] >= 0 ) { total = total + exams[i]; examCount++; } if( examCount == 0 ) return 0; else return total / examCount; }
these are the errors that I am getting and do not understand how to fix. I know that it has to do with the way i am coding "student[total]" but not sure of the specifics.these are the errors that I am getting and do not understand how to fix. I know that it has to do with the way i am coding "student[total]" but not sure of the specifics.#include <iostream>
#include <string>
using namespace std;
const int EXAM_LIMIT = 3;
const int STUDENT_LIMIT = 10;
class Student
{
public:
Student();
string getFullName();
void setName( string theFirstName, string theLastName );
int getID();
void setID( int theID );
double getExamScore( int examNumber );
void setExamScore( int examNumber, double score );
double getExamAverage();
private:
int ID;
string firstName, lastName;
double exams[EXAM_LIMIT];
};
I also am not worried about the warning as I have not written code to use the exam functions yet.
also I know I should not use this, this is the code the instructor has us use to keep the console window open in borland and yes I have read the FAQ on this. (standard disclaimer as someone always comments on this code in my assignments!)also I know I should not use this, this is the code the instructor has us use to keep the console window open in borland and yes I have read the FAQ on this. (standard disclaimer as someone always comments on this code in my assignments!)[C++ Warning] Project6.cpp(100): W8004 'examnumber' is assigned a value that is never used
[C++ Error] Project6.cpp(123): E2294 Structure required on left side of . or .*
[C++ Error] Project6.cpp(127): E2294 Structure required on left side of . or .*
[C++ Error] Project6.cpp(129): E2294 Structure required on left side of . or .*
[C++ Error] Project6.cpp(130): E2294 Structure required on left side of . or .*
I am using borland to compile.I am using borland to compile.Code:/ the following lines keep the console open cout << "\nPress <ENTER> to continue.\n"; fflush(stdin); cin.get();
Again any help is greatly appreciated.
Jess