Class types - LF Hints

On my 6th Build and im lost on what i need to modify and change, need pointers. The build is marked as succeeded but the output is not matching the test contents tho when i put in "Brain", "Johnson", '*', 85, 95, 3.89 i get out "Brain", "Johnson", '*', 85, 95, 3.89

Instructions
define the struct studentType to implement the basic properties of a student. Define the class studentType with the same components as the struct studentType, and add member functions to manipulate the data members. (Note that the data members of the class studentType must be private.)

Write a program to illustrate how to use the class studentType.

Struct studentType:

struct studentType
{
string firstName;
string lastName;
char courseGrade;
int testScore;
int programmingScore;
double GPA;
};


--------------------------------------
My 6th Build
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
// Main.cpp
// Build 6
//
#include <iostream>
#include <fstream>
#include "studentType.h"
using namespace std;

int main()
{

    studentType s;

    cout << "Name: ";
    getline (cin, s.firstName);

    cout << "Grade: ";
    cin >> s.courseGrade;
    
    cout << "Test score: ";
    cin >> s.testScore;
    
    cout << "Programming score: ";
    cin >> s.programmingScore;
    
    cout << "GPA: ";
    cin >> s.GPA;
    
    cout << "***************" << endl << endl;
    
    s.print();
    
    return 0;
}  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//studentType.h
// Build 6
//
#ifndef STUDENTTYPE_H
#define STUDENTTYPE_H
#include <fstream>
#include <string>
using std::string;
struct studentType 
{
        studentType (const string &firstName = " ", const string &lastName = " ", char courseGrade = ' ', int testScore = 0, int programmingScore = ' ', double GPA = 0.0f );
        void setstudentType(int testScore, string firstName, string lastName, double GPA, char courseGrade, int programmingScore);
        void print();

    string firstName;
    string lastName;
    char courseGrade;
    int testScore;
    int programmingScore;
    double GPA; 

};
#endif 

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
// studentTypeImp.cpp
// Build 6
//
#include "studentType.h"
#include <iostream>
#include <fstream>
using namespace std;


studentType :: studentType (const string &firstName, const string &lastName, char courseGrade, int testScore, int programmingScore, double GPA )
{
    this -> testScore = testScore;
    this -> firstName = firstName;
    this -> lastName = lastName;
    this -> GPA = GPA;
    this -> courseGrade = courseGrade;
    this -> programmingScore = programmingScore;
}

void studentType :: print()
{
    cout << "Name: " << firstName << " " << lastName << '\n'
     << "Grade: " << courseGrade << '\n'
     << "Test score: " << testScore << '\n'
     << "Programming score: " << programmingScore << '\n'
     << "GPA: " << GPA << '\n';
    cout << "***************" << endl << endl;
} 


Test Output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[==========] Running 1 test from 1 test case.
[----------] 1 test from Grades
[ RUN      ] Grades.1
/root/sandbox90392b99/nt-test-e4fe2774.cpp:14: Failure
Value of: "Name:  \nGrade: F\nTest score: 0\nProgramming score: 0\nGPA: 0\n***************\n\nName: Brain Johnson\nGrade: A\nTest score: 85\nProgramming score: 95\nGPA: 3.89\n***************\n\n"
Expected: output
Which is: "Name:    \nGrade:  \nTest score: 0\nProgramming score: 32\nGPA: 0\n***************\n\n***************\n\nName: Brain Johnson\nGrade: *\nTest score: 85\nProgramming score: 95\nGPA: 3.89\n***************\n\n***************\n\n"
[  FAILED  ] Grades.1 (0 ms)
[----------] 1 test from Grades (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] Grades.1

 1 FAILED TEST


Test Contents
1
2
3
4
5
6
7
8
9
10
11
12
13
TEST(Grades, 1) {
  testing::internal::CaptureStdout();
  studentType student;
  studentType newStudent("Brain", "Johnson", '*', 85, 95, 3.89);

  student.print();
  cout << "***************" << endl << endl;

  newStudent.print();
  cout << "***************" << endl << endl;
  std::string output = testing::internal::GetCapturedStdout();
  ASSERT_EQ(output, "Name:  \nGrade: F\nTest score: 0\nProgramming score: 0\nGPA: 0\n***************\n\nName: Brain Johnson\nGrade: A\nTest score: 85\nProgramming score: 95\nGPA: 3.89\n***************\n\n");
}

Last edited on
Compare your program's output to the expected output. Do you see any difference?
Last edited on
I Modified the original post to change a few things, in the future ill just post below but felt some things needed to be fixed in the original posting to better clarify things
Small video file on were i currently am in the project
https://drive.google.com/open?id=1JNUf1vBzBQBeU9_se1utYtDMjZrRxn0n

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
60
61
62
63
64
65
// main.cpp
// Build 9
//
#include <iostream>
#include "studentType.h"
using namespace std;

int main()
{

    studentType student;

    //cout << "Name: ";
    //getline (cin, student.firstName);
    //
    cout << "Name: ";
    cin >> student.firstName;
    cin >> student.lastName;

    cout << "Grade: ";
    cin >> student.courseGrade;
    
    cout << "Test score: ";
    cin >> student.testScore;
    
    cout << "Programming score: ";
    cin >> student.programmingScore;
    
    cout << "GPA: ";
    cin >> student.GPA;
    cout << "***************" << endl << endl;
    
    student.print();
    cout << "***************" << endl << endl;
   
    
    // Test Sample of what needs to be output by above code
    //studentType newStudent("Brain", "Johnson", 'A', 85, 95, 3.89);
    
    //newStudent.print();
    //cout << "***************" << endl << endl;
    
    studentType newStudent;
  // student = newStudent;  <--- assuming this is messing up and not correct
   student = newStudent;
    int score;
    //cin >> newStudent.testScore >> newStudent.programmingScore;  <-- need it to take the student test/programming scores and put in code below
    score = (newStudent.testScore + newStudent.programmingScore) /2;
    if (score >= 90){
        newStudent.courseGrade = 'A';
    }else if (score >= 80)
        newStudent.courseGrade = 'B';
    else if (score >= 70)
        newStudent.courseGrade = 'C';
    else if (score >= 60)
        newStudent.courseGrade = 'D';
    else
        newStudent.courseGrade = 'F';
    
    newStudent.print();
    cout << "***************" << endl << endl;
    
    return 0;
}  


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// studentType.h
// Build 9
//
#define STUDENTTYPE_H
#include <string>
using namespace std;

class studentType 
{
    public:
    studentType (const string &firstName = " ", const string &lastName = " ", char courseGrade = ' ', int testScore = 0, int programmingScore = 0, double GPA = 0.0f );
    void setstudentType(int testScore, string firstName, string lastName, double GPA, char courseGrade, int programmingScore);
    void print();
    
    string firstName;
    string lastName;
    char courseGrade;
    int testScore;
    int programmingScore;
    double GPA; 
};


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
// studentTypeImp.cpp
// Build 9
//
#include "studentType.h"
#include <iostream>
using namespace std;

studentType :: studentType (const string &firstName, const string &lastName, char courseGrade, int testScore, int programmingScore, double GPA )
{
    this -> testScore = testScore;
    this -> firstName = firstName;
    this -> lastName = lastName;
    this -> GPA = GPA;
    this -> courseGrade = courseGrade;
    this -> programmingScore = programmingScore;
}

void studentType :: print()
{
    cout << "Name: " << firstName << " " << lastName << '\n'
        << "Grade: " << courseGrade << '\n'
        << "Test score: " << testScore << '\n'
        << "Programming score: " << programmingScore << '\n'
        << "GPA: " << GPA << '\n';
} 
Topic archived. No new replies allowed.