Create object and call function in Main

Homework assistance only,I need to create an object from this class (StudentRecord) Call an input function of this object (not class) Call an output function of this object and I am okay until this point. How should it look? No errors until that section of code??????


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  #include <iostream>
 using namespace std;
 //define class StudentRecord before the main function
class StudentRecord {

//private variables must be created - exam1, exam2, average, lettergrade, studentID 
private:
 double exam1;
 double exam2;
 double average;
 char lettergrade;
 char studentID [5];
 int objStudent;
 
 // two public functions should be defined - input( ) and output( )
 // input function contains all the cin statements to receive studentID, exam1 and exam2 scores
 
 public:          
 void input () {
 cout << "Enter the Student ID: ";
 cin >> studentID;
 cout << "Enter Exam 1 Score: ";
 cin >> exam1 ;
 cout << "Enter Exam 2 score: ";
 cin >> exam2 ;

 }        
//output function contains the code to compute average and letter grade, and display all the information
void output () {
 average = (exam1+exam2) / 2;
 
 if (average<=100 && average>89)
 lettergrade='A';
 else if (average<=89 && average>79)
 lettergrade='B';
 else if (average<=79 && average>69)
 lettergrade='C';
 else if (average<=69 && average>59)
 lettergrade='D';
 else if (average<=59 && average>0)
 lettergrade='F';
 
cout << "Student ID - " << studentID << endl;
cout << "Exam 1 score - " << exam1 << endl;
cout << "Exam 2 score - " << exam2 << endl; 
cout << "Class average - " << average << endl;
cout << "Letter grade - " << lettergrade << endl;
};
//Main function contains three main code Create an object from this class (StudentRecord) Call an input function of this object (not class) Call an output function of this object

int main () 
{
 StudentRecord objStudent;
 input "()";
 output "()"	
 	
    system("PAUSE");
    return 0;
    }
Line 47 you're missing a }
Line 54-55. Calls need to be qualified by the object instance,
Remove the quotes around the ().
Line 55 is missing a ;

1
2
    objStudent.input ();
    objStudent.output ();	

Last edited on
StudentRecord objStudent;
objStudent.input();
objStudent.output ();
Line 54-55. Remove the quotes around the ().


ANd write:


objStudent.input();
objStudent.output ();
Also you forgot to place the closing brace in the definition of the function output.
He is right... Line 49 should have two braces like this }};
Thank you all, I made the changes but am still getting two error messages:
I can't find the problem??????
[
#include <iostream>
using namespace std;
//define class StudentRecord before the main function
class StudentRecord {

//private variables must be created - exam1, exam2, average, lettergrade, studentID
private:
double exam1;
double exam2;
double average;
char lettergrade;
char studentID [5];
int objStudent;

// two public functions should be defined - input( ) and output( )
// input function contains all the cin statements to receive studentID, exam1 and exam2 scores

public:
void input () {
cout << "Enter the Student ID: ";
cin >> studentID;
cout << "Enter Exam 1 Score: ";
cin >> exam1 ;
cout << "Enter Exam 2 score: ";
cin >> exam2 ;

}
//output function contains the code to compute average and letter grade, and display all the information
void output () {
average = (exam1+exam2) / 2;

if (average<=100 && average>89)
lettergrade='A';
else if (average<=89 && average>79)
lettergrade='B';
else if (average<=79 && average>69)
lettergrade='C';
else if (average<=69 && average>59)
lettergrade='D';
else if (average<=59 && average>0)
lettergrade='F';

cout << "Student ID - " << studentID << endl;
cout << "Exam 1 score - " << exam1 << endl;
cout << "Exam 2 score - " << exam2 << endl;
cout << "Class average - " << average << endl;
cout << "Letter grade - " << lettergrade << endl;
};
//Main function contains three main code Create an object from this class (StudentRecord) Call an input function of this object (not class) Call an output function of this object

int main ()
{
StudentRecord objStudent;
objStudent.input ();
objStudent.output ();

system("PAUSE");
return 0;
}
}

]

59 expected unqualified-id at end of input
59 expected `,' or `;' at end of input
read one more what I wrote.
Thanks, you're the best. I can't thank you enough, professor is not so helpful.....
it works!!!!!!! YEAH!!!!
As has been pointed out several times, you're missing the closing brace for function output.

At line 48 in your OP, the }; terminates the class. You have no } terminating the output function.

And you now have an extraneous } in main.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.



Topic archived. No new replies allowed.