I'm missing something and struggling.

I've been at this for days and researched the web, read, and studied for a while. I have tried to work this out before posting and have to utilize inheritance for this. I am a student and not asking for a handout just a push in the correct direction. I'm sure its a rookie mistake but I am new at this, thank you anyone for any advice/guidance in advance. The output should be:


enter the student id: 111

enter exam1 score: 80

enter exam2 score: 90

*** Output ***

student id - 111

exam1 score - 80

exam2 score - 90

class average - 85

letter grade - B

My code so far is:

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

class StudentRecord
{
public:
Student()
Student(string theID, String theExam1, String theExam2, String theAverage, String theLetter);
void average()const;

private:
string ID;
string Exam1;
string Exam2
String Average;
String Letter;

double exam1;
double exam2;
double average;
int StudentID;
int Letter;

};

Student::Student(string theID, String theExam1, String theExam2, String theAverage, String theLetter){
Student ID=theID;
Exam1=theExam1;
Exam2=theExam2;
Average=theAverage;
LetterGrade=theLetter;
}
void letterGrade(int finGrade);

int main()
{
String ID, String Exam1, String Exam2;
cout << "Enter The Student ID:"<< endl;
cin student.id;
cout << "Enter Exam1" << endl;
cin >> grade.exam1;
cout << "Enter Exam2" << endl;
cin >> grade.exam2;

cout << "*** Output ***" << endl;

int average = grade.exam1 * grade.exam2 / 2;
letterGrade=(finalGrade);

cout << "Student ID" << endl
cout << student.id << endl;
cout << "Exam1 " << grade.exam1 << endl;
cout << "Exam2 " << grade.exam2 << endl;
cout << "Class Average " << average << endl;
cout << "Your Letter Grade Is: " << letterGrade << endl;

system("PAUSE");

return 0;

}

void letterGrade(int finGrade){ //Determines Letter Grade
if(finGrade>=90)
cout << "A";
else if(finGrade>=80 && finGrade<90)
cout << "B";
else if(finGrade>=70 && finGrade<80)
cout << "C";
else if(finGrade>=60 && finGrade<70)
cout << "D";
else if(finGrade<60)
cout << "F";
whats it doing wrong?
So many things wrong with this... Sorry, but it's true.

First:
1
2
3
4
5
6
class StudentRecord
{
public:
Student()	
Student(string theID, String theExam1, String theExam2, String theAverage, String theLetter);
void average()const;


Student is defined twice... And it has no return value... I would actually recommend that it should be the constructor, because it looks like you're initializing all the variables...

1
2
3
4
5
class StudentRecord
{
public:
StudentRecord(string theID, String theExam1, String theExam2, String theAverage, String theLetter);
void average();


Oh, and you're going to calculate the letter later on, so that can go as well... Unless you're going to expand the program and need to have that variable in there... In any case, leave it out of the constructor so you can calculate it later, unless you want to calculate the letter grade in the constructor... Blah blah blah... And you don't have a average function, so it should look like this now:

1
2
3
4
class StudentRecord
{
public:
StudentRecord(string theID, String theExam1, String theExam2);


Look at this:
1
2
3
4
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;

letterGrade=(finalGrade); void letterGrade(int finGrade){
Nothing wrong? Nope... You need to tell the compiler that there is a function at the end to compile:
1
2
3
4
5
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
void letterGrade(int finGrade);


Oh, this is wrong as well:
letterGrade=(finalGrade);
Think about it...

I'll just tell you:
char TheLetterGrade = letterGrade(average);

Which also makes this wrong (very, very wrong):
1
2
3
4
5
6
7
8
9
10
11
void letterGrade(int finGrade){ //Determines Letter Grade
if(finGrade>=90)
cout << "A";
else if(finGrade>=80 && finGrade<90)
cout << "B";
else if(finGrade>=70 && finGrade<80)
cout << "C";
else if(finGrade>=60 && finGrade<70)
cout << "D";
else if(finGrade<60)
cout << "F";


Make it look a little more like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void letterGrade(int finGrade)
{
     if(finGrade>=90)
     {
          return 'A';
     }
     else if(finGrade>=80 && finGrade<90)
     {
          return 'B';
     }
     else if(finGrade>=70 && finGrade<80)
     {
          return 'C';
     }
     else if(finGrade>=60 && finGrade<70)
     {
          return 'D';
     }
     else if(finGrade<60)
     {
          return 'F';
     }
}


Why make variables you don't use?

1
2
3
4
5
6
7
String ID, String Exam1, String Exam2;
cout << "Enter The Student ID:"<< endl;
cin student.id;
cout << "Enter Exam1" << endl;
cin >> grade.exam1;
cout << "Enter Exam2" << endl;
cin >> grade.exam2;


You'll also have to make a instance of you class... And fix the variable type and cin to the right things... So here:
1
2
3
4
5
6
7
8
9
int ID;
int Exam1;
int Exam2;
cout<<"Enter The Student ID: ";
cin>>ID;
cout<<"Enter Exam1: ";
cin>>Exam1;
cout<<"Enter Exam2: ";
cin>>Exam2

I didn't make an instance of the class, here is why:

USE and make your class:
StudentRecord MyStudent(ID, Exam1, Exam2);

Ya... Sorry if I came across as an asshole... Message back if you still need help!

- Kyle
Thank you, Kyle for your time this helps bring things to perspective and makes sense. I'll see what I can do with it and I really appreciate it.
Topic archived. No new replies allowed.