I'm having some issues with a homework assignment. I've tried everything I can think of but there is just something I'm missing. Basically the assignment tells me to make a composition class with a student class that stores names and test scores and that is within a studentInformation class which takes information from an array of student objects and is able to take information from specific objects in the array and make data charts based on that information. Right now I am getting a bunch of ERROR 2228's. And that's what I'm having trouble figuring out how to fix. Now comes the big block of code. Sorry I wish it were smaller but I have no idea where to narrow it down. So here is my code thus far.
Code:
/************************************************
* William Meabrod *
* *
* CIS2152 C++ Object Oriented Programming *
* *
* lab3.cpp *
* *
* This program will make a composision class *
* * *
************************************************/
#include "studentInformation.h"
int stop = 1;
string lName;
string fName;
double fScore;
double midScore;
double lab1Score;
double lab2Score;
int main()
{
studentInformation CIS2152;
while(stop) //continues asking for additional students until user askes the loop to stop
{
cout << "\nPlease enter student's first name(if you are finished type "
<< "exit for a first name): ";
cin >> fName;
if(fName!="exit")
{
cout << "\nNow enter the student's last name: ";
cin >> lName;
cout << "\nNow enter the student's final exam score: ";
cin >> fScore;
cout << "\nNow enter the student's midterm exam score: ";
cin >> midScore;
cout << "\nNow enter the student's lab1 score: ";
cin >> lab1Score;
cout << "\nNow enter the student's lab2 exam score: ";
cin >> lab2Score;
CIS2152.add(fName,lName,fScore,midScore,lab1Score,lab2Score);
}
else
{
stop = 0;
}
}
int input;
string input2;
stop = 1;
while(stop) //Continues program until user wants to exit
{
cout << "\n\n1 : Print All Students and Final Scores\n"
<< "2 : Print All Students and Letter Grades\n"
<< "3 : Print Highest Final Score\n"
<< "4 : Print Lowest Final Score\n"
<< "5 : Print Average Final Score\n"
<< "6 : Print All Students Final Grade Chart\n"
<< "0 : Exit The Program\n\n"
<< "Please Enter Your Choice: ";
cin >> input;
switch(input)
{
case 1: //Print names and final scores
{
CIS2152.print();
system("pause");
break;
}
case 2: //Print names and grades
{
CIS2152.printGrades();
system("pause");
break;
}
case 3: //print highest score
{
cout << "The highest final score is: " << CIS2152.highestScore()<< "\n";
system("pause");
break;
}
case 4: //print lowest score
{
cout << "The lowest final score is: " << CIS2152.lowestScore() << "\n";
system("pause");
break;
}
case 5: //print average score
{
cout << "The class average is: " << CIS2152.avgScore() << "\n";
system("pause");
break;
}
case 6:
{
CIS2152.printChart();
system("pause");
break;
}
default:
{
stop = 0;
}
}
}
return 0;
}
Code:
/************************************************
* William Meabrod *
* *
* CIS2152 C++ Object Oriented Programming *
* *
* student.h *
* *
* This program will make a composision class *
* * *
************************************************/
#include <iostream>
using std::cout;
using std::cin;
#include <string>
using std::string;
#include <iomanip>
using std::setw;
class student
{
public:
student( string, string, double, double, double, double );
void setFirstName(string);
void setLastName(string);
void setFinalScore(double);
void setMidScore(double);
void setLab1(double);
void setLab2(double);
void setClassScore();
string getFirstName();
string getLastName();
double getFinal();
double getMidScore();
double getLab1();
double getLab2();
double getClassScore();
private:
string firstName;
string lastName;
double finalScore;
double midScore;
double lab1;
double lab2;
double classScore;
};
Code:
/************************************************
* William Meabrod *
* *
* CIS2152 C++ Object Oriented Programming *
* *
* studentInformation.h *
* *
* This program will make a composision class *
* * *
************************************************/
#include "student.h"
class studentInformation
{
public:
studentInformation();
void setArray();
void add(string, string, double, double, double, double);
void print();
void printGrades();
void printChart();
double highestScore();
double lowestScore();
double avgScore();
private:
student *stuInfo[30];
int arrayNum;
int A;
int B;
int C;
int F;
double totalA;
double totalB;
double totalC;
double totalF;
};
Code:
/************************************************
* William Meabrod *
* *
* CIS2152 C++ Object Oriented Programming *
* *
* student.cpp *
* *
* This program will make a composision class *
* * *
************************************************/
#include "student.h"
student::student(string fName, string lName, double fScore, double midTerm, double labOne,
double labTwo) //contructor
{
setFirstName(fName);
setLastName(lName);
setFinalScore(fScore);
setMidScore(midTerm);
setLab1(labOne);
setLab2(labTwo);
setClassScore();
}
void setFirstName(string fName)
{
firstName = fName;
}
void setLastName(string lName)
{
lastName = lName;
}
void setFinalScore(double fScore)
{
finalScore = fScore;
}
void setMidScore(double midTerm)
{
midScore = midTerm;
}
void setLab1(double labOne)
{
lab1 = labOne;
}
void setLab2(double labTwo)
{
lab2 = labTwo;
}
void setClassScore()
{
classScore = (finalScore + midScore + lab1 + lab2) / 4;
}
string getFirstName()
{
return firstName;
}
string getLastName()
{
return lastName;
}
double getFinalScore()
{
return finalScore;
}
double getMidScore()
{
return midScore;
}
double getLab1()
{
return lab1;
}
double getLab2()
{
return lab2;
}
double getClassScore()
{
return classScore;
}
Code:
/************************************************
* William Meabrod *
* *
* CIS2152 C++ Object Oriented Programming *
* *
* studentInformation.cpp *
* *
* This program will make a composision class *
* * *
************************************************/
#include "studentInformation.h"
studentInformation::studentInformation() //constructor
{
setArray();
}
void studentInformation::setArray() //sets a number representing the current array slot number
//being used
{
arrayNum = -1;
}
void studentInformation::add(string fName, string lName, double fScore, double midTerm, double lab1,
double lab2) //adds a new student
//to the next slot on the array list
{
arrayNum++;
stuInfo[arrayNum] = new student(fName, lName, fScore, midTerm, lab1, lab2);
}
void studentInformation::print() //prints all students and final scores
{
std::cout << "\nFirst Name" << setw(13) << "Last Name" << setw(13) << "Final Score\n\n";
for(int i = arrayNum; i >= 0; i--)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << stuInfo[i].getClassScore() << "\n";
}
}
void studentInformation::printGrades() //prints all students and letter grades
{
std::cout << "First Name" << setw(13) << "Last Name" << setw(13) << "Grade\n\n";
for(int i = arrayNum; i >= 0; i--)
{
if(stuInfo[i].getClassScore() >= 90 && stuInfo[i].getClassScore() <= 100)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "A" << "\n";
}
else if(stuInfo[i].getClassScore() >= 80 && stuInfo[i].getClassScore() < 90)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "B" << "\n";
}
else if(stuInfo[i].getClassScore() >= 70 && stuInfo[i].getClassScore() < 80)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "C" << "\n";
}
else if(stuInfo[i].getClassScore() < 70 && stuInfo[i].getClassScore() >= 0)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "F" << "\n";
}
else if(stuInfo[i].getClassScore() > 100 || stuInfo[i].getClassScore() < 0)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "ERROR" << "\n";
}
}
}
void studentInformation::printChart()
{
A = 0;
B = 0;
C = 0;
F = 0;
for(int i = arrayNum; i >= 0; i--)
{
if(stuInfo[i].getClassScore() == 100)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "**********" << "\n";
A++;
totalA += stuInfo[i].getClassScore();
}
if(stuInfo[i].getClassScore() >= 90 && stuInfo[i].getClassScore() <= 100)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "*********" << "\n";
A++;
totalA += stuInfo[i].getClassScore();
}
else if(stuInfo[i].getClassScore() >= 80 && stuInfo[i].getClassScore() < 90)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "********" << "\n";
B++;
totalB += stuInfo[i].getClassScore();
}
else if(stuInfo[i].getClassScore() >= 70 && stuInfo[i].getClassScore() < 80)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "*******" << "\n";
C++;
totalC += stuInfo[i].getClassScore();
}
else if(stuInfo[i].getClassScore() >= 60 && stuInfo[i].getClassScore() < 70)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "******" << "\n";
F++;
totalF += stuInfo[i].getClassScore();
}
else if(stuInfo[i].getClassScore() >= 50 && stuInfo[i].getClassScore() < 60)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "*****" << "\n";
F++;
totalF += stuInfo[i].getClassScore();
}
else if(stuInfo[i].getClassScore() >= 40 && stuInfo[i].getClassScore() < 50)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "****" << "\n";
F++;
totalF += stuInfo[i].getClassScore();
}
else if(stuInfo[i].getClassScore() >= 30 && stuInfo[i].getClassScore() < 40)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "***" << "\n";
F++;
totalF += stuInfo[i].getClassScore();
}
else if(stuInfo[i].getClassScore() >= 20 && stuInfo[i].getClassScore() < 30)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "**" << "\n";
F++;
totalF += stuInfo[i].getClassScore();
}
else if(stuInfo[i].getClassScore() >= 10 && stuInfo[i].getClassScore() < 20)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "*" << "\n";
F++;
totalF += stuInfo[i].getClassScore();
}
else if(stuInfo[i].getClassScore() >= 0 && stuInfo[i].getClassScore() < 10)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << " " << "\n";
F++;
totalF += stuInfo[i].getClassScore();
}
else if(stuInfo[i].getClassScore() > 100 || stuInfo[i].getClassScore() < 0)
{
std::cout << stuInfo[i].getFirstName() << setw(13) << stuInfo[i].getLastName() << setw(13) << "ERROR" << "\n";
}
}
cout << "\nA: " << setw(8) << A << setw(8) << (totalA/A)
<< "\nB: " << setw(8) << B << setw(8) << (totalB/B)
<< "\nC: " << setw(8) << C << setw(8) << (totalC/C)
<< "\nF: " << setw(8) << F << setw(8) << (totalF/F) << "\n";
}
double studentInformation::highestScore() //returns the highest final score
{
double highGrade = 0;
for(int i = arrayNum; i >= 0; i--)
{
if(stuInfo[i].getClassScore() > highGrade)
{
highGrade = stuInfo[i].getClassScore();
}
}
return highGrade;
}
double studentInformation::lowestScore() //returns the lowest final score
{
double lowGrade = 100;
for(int i = arrayNum; i >= 0; i--)
{
if(stuInfo[i].getClassScore() < lowGrade)
{
lowGrade = stuInfo[i].getClassScore();
}
}
return lowGrade;
}
double studentInformation::avgScore() //returns the average final score
{
double totalScore = 0;
for(int i = arrayNum; i>=0; i--)
{
totalScore = stuInfo[i].getClassScore() + totalScore;
}
double aScore = totalScore/(arrayNum + 1);
return aScore;
}
Can anyone help?