HELP!! Adding multiple arrays into a variable

So I've written out a program that is supposed to calculate my grades and give me a letter grade and total point score. However for some reason my getScore function keeps returning me junk (-2.5304.. etc). I know it has something to do with my arrays because when i exclude them it works as expected. Can anyone tell me what might be my problem?


Student Grades.h


#include <iostream>
#include <string>
using namespace std;

class StudentGrades
{
private:
double labs[12];
double attendance[15];
double midterm;
double quiz;
double final;
double score;
string grade;

public:
StudentGrades();

StudentGrades(double [], double [], double , double , double );



void setGrades(double [], double [], double, double, double);

const double GetScore(double [], double [], double, double, double)
{
labs;
attendance;
midterm;
quiz;
final;


double score=labs[12]+attendance[15]+midterm+quiz+final;

return score;
}

const string GetGradeLetter(double TotalScore)
{
double MaxGrade=400;
double percentage= (TotalScore/MaxGrade)*100;
string grade;

if (percentage >=90 && percentage <=100)
{
grade='A';

}

else if (percentage >= 80 && percentage<= 89 )
{
grade='B';
}

else if (percentage >=70 && percentage <= 79)
{
grade ='C';
}

else if (percentage >= 60 && percentage <=69)
{
grade ='D';
}

else
{
grade ='F';
}

return grade;
}


}


Student Grades.cpp

#include "Student Grades.h"
#include <iostream>
;
using namespace std;

StudentGrades::StudentGrades()
{
labs[12]=0;
attendance[15]=0;
midterm=0;
quiz=0;
final=0;
score=0;
grade=" ";

}

StudentGrades::StudentGrades(double Labs[], double Attendance[], double Midterm, double Quiz, double Final)
{
labs[12]=Labs[12];
attendance[15]=Attendance[15];
midterm=Midterm;
quiz=Quiz;
final=Final;
}

void StudentGrades::setGrades(double Labs[12], double Attendance[15], double Midterm, double Quiz, double Final)
{
labs[12]=Labs[12];
attendance[15]=Attendance[15];
midterm=Midterm;
quiz=Quiz;
final=Final;

}


main.cpp

#include "Student Grades.h"
#include <iostream>
#include <string>
;
using namespace std;

int main()
{
//const int numlabs=12;
//const int numdays=15;
double LABS[12];
double ATTENDANCE[15];
double MIDTERM;
double QUIZ;
double FINAL;
int i;

cout<<"Please enter the number of points"<<endl;
cout<<"you scored for each lab assignment."<<endl;
for (i=0;i<12;i++)
{
cout<<"Enter Lab "<<(i+1)<<"'s points"<<endl;
cin>>LABS[i];
}
cout<<endl;

cout<<"Please enter the number of points"<<endl;
cout<<"you scored for each day you attended class."<<endl;
for (i=0;i<15;i++)
{
cout<<"Enter number of points recieved on day "<<(i+1)<<endl;
cin>>ATTENDANCE[i];
}
cout<<endl;

cout<<"Please enter the number of points"<<endl;
cout<<"you earned in your quiz."<<endl;
cin>>QUIZ;
cout<<endl;

cout<<"Please enter the number of points"<<endl;
cout<<"you scored in your midterm."<<endl;
cin>>MIDTERM;

cout<<endl;
cout<<"Please enter the number of points"<<endl;
cout<<"you earned in your final."<<endl;
cin>>FINAL;
cout<<endl;

StudentGrades Student;
Student.setGrades(LABS, ATTENDANCE, QUIZ, MIDTERM, FINAL);

cout<<"Your total points acummalated this semester was "<<Student.GetScore(LABS, ATTENDANCE, QUIZ, MIDTERM, FINAL)<<" points."<<endl;

//double SCORE = Student.GetScore(LABS, ATTENDANCE, QUIZ, MIDTERM, FINAL);

cout<<endl;
cout<<"Your grade for this semester is "<<Student.GetGradeLetter(Student.GetScore(LABS, ATTENDANCE, QUIZ, MIDTERM, FINAL))<<endl;
}


[/code]
Last edited on
Please, anyone?
1
2
3
4
int foo[7];
int bar[7];

foo[7] = bar[7]; // ERROR 

1. Both arrays have 7 elements. The valid indices are thus 0..6.
The foo[7] points to memory that is just beyond the block allocated for array foo.
An out of bounds error.

2. foo[k] deferences k'th element. foo[k] is one integer, not an array.
Are you trying to copy arrays? If yes:
1
2
3
4
5
const size_t N = 7;
int foo[N];
int bar[N];

std::copy_n( bar, N, foo );
Topic archived. No new replies allowed.