![]() |
| | #1 | ||
| Registered User Join Date: Nov 2006
Posts: 38
| new problem with class However when executed it has problems. Here is what i see case 2 is not saving the imput scores correctly case 3 shuts the whole program into fubar land i am including the code and the console window so maybe someone can explain what is happening and i can fix it. thanks console window shows Quote:
Code: /*
Jessie Brown
cop2334
*/
#include "Student.h"
//Prototypes -- function declarations.
//-----------------------------------
void Menu_Selection();
void enter_students (int,int& total);
Student student[STUDENT_LIMIT];
int find_student(int,int,int& total);
int main()
{
Menu_Selection();
// the following lines keep the console open
cout << "\nPress <ENTER> to continue.\n";
fflush(stdin);
cin.get();
return 0;
}
/*------------------------------------------------------------------------------
This section of code is the initial screen after employee signs in
to system. From here said employee can choose what she must
do with each customer being assisted.
------------------------------------------------------------------------------*/
void Menu_Selection()
{
int total=0;
int studentID;
int option;
int examNumber;
double score;
do
{
cout << endl
<< "1. Add a new student to roster. \n \n"
<< "2. Enter exam score for all students. \n \n"
<< "3. Display student exam averages. \n \n"
<< "4. Display course information for all students. \n \n"
<< "5. Exit program: \n \n";
cin >> option;
cout << endl;
switch (option)
{
case 1:
enter_students (STUDENT_LIMIT,total);
cout << endl;
break;
case 2:
/* this allows you to enter an exam number and score for
each stutdent in this class. assumes that you know the
number, that you have put the papers in some sort of order
that matches the order of students....if you skip a number
or the score does not track your average will be off as
a -1 will be put in that exam number spot.*/
for( int i = 0; i < total ; i++ )
{
cout << "Enter Exam number and score.\n";
cin >> examNumber;
cin >> score;
student[i].setExamScore(examNumber, score);
}
break;
case 3:
/*this will find a particular student based on his ID number
and will then print the average of the scored he has taken
and that have been recorded, it will also list the test scores
individually so that one can see if there is one missing,
a missing one would be indicated by -1*/
int tempID;
cout << "Please enter the Student ID number\n";
cin >> tempID;
for( int i=0; i<EXAM_LIMIT; i++ )
cout << student[tempID].getExamScore(i) << endl;
cout << "Avg = " << student[tempID].getExamAverage() << endl;
break;
case 4:
for( int i = 0; i < total ; i++ )
{
cout << student[i].getFullName() << endl;
cout << "ID: " << student[i].getID() << endl;
for(int i=0; i<EXAM_LIMIT; i++ )
{
cout << student[i].getExamScore(i) << endl;
}
cout << "Avg = " << student[i].getExamAverage() << 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 student, assuming that each id number is
original (like a social security number) id number is not checked for duplicity
If class is full it will not allow you to register another student.
------------------------------------------------------------------------------*/
void enter_students (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 and last name.\n";
cin >> temp1;
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++;
}
}
Code: /*
Student.cpp
Implementation file for Student class for Project 6
Jim Lewis - 11.15.06
*/
#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;
}
Quote:
This is the first program i have had to write manipulating class files and objects. If i do not understand this I will not be able to go forward. Frankly you guys here have been the best! Jess | ||
| jrb47 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Mesh Class Design problem | sarah22 | Game Programming | 2 | 05-20-2009 04:52 AM |
| Getting an error with OpenGL: collect2: ld returned 1 exit status | Lorgon Jortle | C++ Programming | 6 | 05-08-2009 08:18 PM |
| Class design problem | h3ro | C++ Programming | 10 | 12-19-2008 09:10 AM |
| My Window Class | Epo | Game Programming | 2 | 07-10-2005 02:33 PM |
| Returning an object from a method - Problem when creating my own string class | pecymanski | C++ Programming | 3 | 12-03-2001 01:45 PM |