Hello! Well, I've been given a fairly difficult assignment (at least to me), and I can't seem to wrap my head around some parts.
Here are the objectives:
"In this assignment you will demonstrate your ability to design a class and provide its declaration (.h) and implementation (.cpp) files. All activity relating to a Student object must be handled by the class. You must use a static variable to keep count of the actual number of students (not the number of objects in the array). Finally, use a stringstream to create the student display string."
Also,
"Declare a Student class that contains: student Id, first name, last name, five test scores, grade average, and course letter grade. Also declare an array of a maximum of 25 Student objects. Prompt the user and read the student data from the keyboard. You may clear the screen between student entries (system(“cls”)). Store the information in the array. When there are no more entries (EOF), clear the screen and then loop through the array to print each student. Calculate the average score, and determine the letter grade for each student. Finally display an average score for each test and for the entire class. Display the information in tabular form on the screen, one line for each student (including the average score and GPA) and a total line for the average score for each test and class. Don’t forget appropriate headings."
Okay, now for what I've written so far and what I'm having trouble with!
First, the header file:
using namespace std;
#ifndef STUDENT_CLASS
#define STUDENT_CLASS
Class Student
{
private:
int x;
int studentId;
string firstName;
string lastName;
int scores[5];
double avg;
char grade;
static int count;
public:
Student();
Student(int sX, string fN, string lN);
void setX(int i);
void setId(int sX);
void setFirst(string fN);
void setLast(string lN);
void setAverage(double sA);
void setGrade(char sG);
void setScores(int sS, int y);
int getId(void) const;
string getFirst(void) const;
string getLast(void) const;
int getScores(void) const;
double getAverage(void) const;
char getGrade(void) const;
string displayData(void) const;
};
#endif
Second, the implementation:
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
#include "Student.h"
Student :: Student()
{
sX = 0;
fN = "";
lN = "";
for(int i = 0, i < 5, i++)
scores[i] = {0};
double sA = 0.0;
char sG = ' ';
}
string Student :: displayData(void)
{
calcAverage();
setGrade();
stringstream strstr;
}
//================================Set Mutator Function declarations=============================================
void Student :: setX(int i)
{
x = i
}
void Student :: setId(int sX)
{
studentId = sX;
}
void Student :: setFirst(string fN)
{
firstName = fN;
}
void Student :: setLast(string lN)
{
lastName = lN;
}
void Student :: setAverage(double sA)
{
avg = sA;
}
void Student :: setGrade(char sG)
{
grade = sG;
}
void Student :: setScores(int sS, int y)
{
scores[y] = sS;
}
//================================Get Accessor Function declarations=============================================
int Student :: getId(void) const
{
return studentId;
}
string Student :: getFirst(void) const
{
return firstName;
}
string Student :: getLast(void) const
{
return lastName;
}
double Student :: getAverage(void) const
{
return avg;
}
char Student :: getGrade(void) const
{
return grade;
}
And lastly, main:
#include <cstdlib>
#include <iostream>
using namespace std;
const int MAX = 25;
void getData
bool getStudent(Student& userData);
void processStudents
void writeAverages
int main(int argc, char *argv[])
{
Student userData[MAX];
int i;
for(i = 0, i < MAX, i++)
userData[i]->setX[i];
system("PAUSE");
return EXIT_SUCCESS;
}
bool getStudent(Student& userData)
{
cout << "=======================New Student=======================" << endl;
cout << "!!When finished adding data use CNTRL-Z to clear & print!!\n" << endl;
cout << "Enter student ID: ";
cin >> sX;
if(cin.eof() || cin.fail())
return true;
cin.ignore();
cout << "Enter student's first name: ";
getline(cin, fN);
cout << "Enter student's last name: ";
getline(cin, lN);
userData.setId(sX);
userData.setFirst(fN);
userData.setLast(lN);
cout << "Please enter 5 test scores (seperate with spaces): ";
for(int i = 0; i < 5; i++)
cin >> Student::userData.scores[i];
return false;
}
Okay, obviously string stream is a problem here as I haven't even created a function to display the data yet. I have hardly any knowledge of string stream, but that's not that big of a deal at the moment.
The main question I have is how would I write a while loop in main to keep a count of each time the user finishes inputting a full student's data? Something like having the loop check to see if the user has input all of the information of one student, if they have add one to the count and move to the next object and if not then do not add to the count.
I am fairly weak when it comes to arrays, so hopefully you guys could clear some of this up for me! I am NOT fishing for answers here, I'd like to learn with your help. Thank you in advance!