Returning a value from Class?

Write your question here.

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
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

class RecordStudent {
      
string studentID;
int ExamScore1;
int ExamScore2;

public: void Input () {
cout << "Enter Student ID" << endl;
string IDinput;
cin >> IDinput;

cout << "Enter First Exam Score:" << endl;
int  Exam1;
cin >> Exam1;

cout << "Enter Second Exam Score:" <<endl;
int Exam2;
cin >> Exam2;
};

void RecordStudent::Input (string a){
     studentID=a;}
void RecordStudent::Input (int b, int c){
     ExamScore1=b;
     ExamScore2=c;}

public: 
void Output () {
cout << "***OutPut***" << endl;
string IDinput;
cout << "Student ID" <<  endl;
cout << IDinput; }
void RecordStudent::Output(string a){
studentID=a;}
}; 

int main ()
{
RecordStudent RS;
RS.Input();
RecordStudent SR;
SR.Output();
system ("pause");
return 0;
;}
Last edited on
I don't have a question but I have a statement. In C++ a class only needs one public, protected, and private declaration.

This isn't Java, C#, VB, etc.
Oh, I'm really new to this lol but thanks...?
...still kinda stuck.
I'm still new myself, so I might be wrong here.

1
2
3
4
cout << "Enter Second Exam Score:" <<endl;
int Exam2;
cin >> Exam2;
};

Why do you have a semicolon after the ending bracket? You should only put one after the end of the class.

1
2
3
4
5
void RecordStudent::Input (string a){
     studentID=a;}
void RecordStudent::Input (int b, int c){
     ExamScore1=b;
     ExamScore2=c;}

What are these supposed to do? You never call them anywhere.

1
2
3
4
5
6
7
8
public: 
void Output () {
cout << "***OutPut***" << endl;
string IDinput;
cout << "Student ID" <<  endl;
cout << IDinput; }
void RecordStudent::Output(string a){
studentID=a;}

You don't need two public declarations in the same class. You also never call
"void RecordStudent::Output(string a)" either.
Last edited on
This would probably help you guys more if I posted my assignment...

Program #2

Write a grading program for a class with the following grading policies

a. There are two exams, each graded on the basis of 100 points

c. Any grade of 90 or more is an A, any grade of 80 or more (but less than 90) is a B, any grade of 70 or more (but less than 80) is a C, any grade of 60 or more (but less than 70) is a D, and any grade below 60 is an F. The program will read in the student’s scores and output the student’s record, which consists of two exam scores as well as the student’s average numeric score for the entire course and final letter grade. Define and use a structure or class for the student record.

d. A student ID should be 3-digit characters (create a char variable with size of 5, or a string variable).

e. This class has two public methods - one for input (student ID, two exam scores), another for output (student ID, two exam scores, class average, letter grade)

Hint: a class or structure must contain the following private variables ==> studentNumber (char[ ] or string), exam1, and exam2

Hint: use StudentRecord for the class name, and objStudent for the only object name you create in the main function.

Sample output:

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
This would probably help you guys more if I posted my assignment...

It would help us more is if you actually posted a question and/or described what you were having trouble with.
Topic archived. No new replies allowed.