struct studentType { string firstName; string lastName; char courseGrade; int testScore; int programmingScore; double GPA; }; |
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"); } |
|
|
|
|
|
|
|
|
fiji885 (218) |
In file included from main.cpp:6:0: studentType.h:36:1: error: expected unqualified-id before ‘{’ token { ^ main.cpp: In function ‘int main()’: main.cpp:11:11: error: ‘class studentType’ has no member named ‘print’ student.print(); ^~~~~ main.cpp:14:14: error: ‘class studentType’ has no member named ‘print’ newStudent.print(); ^~~~~ studentType.h:36:1: error: expected unqualified-id before ‘{’ token { ^ studentTypeImp.cpp:9:1: error: expected unqualified-id before ‘if’ if (student.firstName == newStudent.firstName && student.lastName == newStudent.lastName) ^~ studentTypeImp.cpp: In function ‘void printStudent(studentType)’: studentTypeImp.cpp:35:20: error: ‘std::__cxx11::string studentType::firstName’ is private within this context cout <<student.firstName << " " << student.lastName ^~~~~~~~~ studentType.h:27:12: note: declared private here string firstName; ^~~~~~~~~ studentTypeImp.cpp:35:48: error: ‘std::__cxx11::string studentType::lastName’ is private within this context t <<student.firstName << " " << student.lastName ^~~~~~~~ studentType.h:28:12: note: declared private here string lastName; ^~~~~~~~ studentTypeImp.cpp:36:27: error: ‘char studentType::courseGrade’ is private within this context << " " << student.courseGrade ^~~~~~~~~~~ studentType.h:29:10: note: declared private here char courseGrade; ^~~~~~~~~~~ studentTypeImp.cpp:37:27: error: ‘int studentType::testScore’ is private within this context << " " << student.testScore ^~~~~~~~~ studentType.h:30:9: note: declared private here int testScore; ^~~~~~~~~ studentTypeImp.cpp:38:27: error: ‘int studentType::programmingScore’ is private within this context << " " << student.programmingScore ^~~~~~~~~~~~~~~~ studentType.h:31:9: note: declared private here int programmingScore; ^~~~~~~~~~~~~~~~ studentTypeImp.cpp:39:27: error: ‘double studentType::GPA’ is private within this context << " " << student.GPA << endl; ^~~ studentType.h:32:12: note: declared private here double GPA; ^~~ bash: line 2: ./a.out: No such file or directory |
|
|
|
|
|
|
|
|
$ ./a.out Student ------- First name: Richard Last name: Feynman Course grade: A Test score: 100 Programming score: 100 Student ------- First name: Bjarne Last name: Stroustrup Course grade: A Test score: 95 Programming score: 100 $ |
|
|
|
|
|
|
In file included from /root/sandboxd8237062/studentTypeImp.cpp:4:0, from /root/sandboxd8237062/nt-test-a1086e1d.cpp:2: /root/sandboxd8237062/studentType.h:39:1: error: expected unqualified-id before '{' token { ^ In file included from /root/sandboxd8237062/nt-test-a1086e1d.cpp:2:0: /root/sandboxd8237062/studentTypeImp.cpp:9:1: error: 'score' does not name a type score = (student.testScore + student.programmingScore) / 2; ^~~~~ /root/sandboxd8237062/studentTypeImp.cpp:10:1: error: expected unqualified-id before 'if' if (score >= 90) ^~ /root/sandboxd8237062/studentTypeImp.cpp:12:5: error: expected unqualified-id before 'else' else if (score >= 80) ^~~~ /root/sandboxd8237062/studentTypeImp.cpp:14:5: error: expected unqualified-id before 'else' else if (score >= 70) ^~~~ /root/sandboxd8237062/studentTypeImp.cpp:16:5: error: expected unqualified-id before 'else' else if (score >= 60) ^~~~ /root/sandboxd8237062/studentTypeImp.cpp:18:5: error: expected unqualified-id before 'else' else ^~~~ /root/sandboxd8237062/studentTypeImp.cpp: In function 'void print(studentType&)': /root/sandboxd8237062/studentTypeImp.cpp:27:24: error: 'GPA' was not declared in this scope << "GPA: " << GPA << '\n'; ^~~ /root/sandboxd8237062/nt-test-a1086e1d.cpp: In member function 'virtual void Grades_1_Test::TestBody()': /root/sandboxd8237062/nt-test-a1086e1d.cpp:6:63: error: no matching function for call to 'studentType::studentType(const char [6], const char [8], char, int, int, double)' studentType newStudent("Brain", "Johnson", '*', 85, 95, 3.89); ^ In file included from /root/sandboxd8237062/studentTypeImp.cpp:4:0, from /root/sandboxd8237062/nt-test-a1086e1d.cpp:2: /root/sandboxd8237062/studentType.h:9:7: note: candidate: studentType::studentType() class studentType ^~~~~~~~~~~ /root/sandboxd8237062/studentType.h:9:7: note: candidate expects 0 arguments, 6 provided /root/sandboxd8237062/studentType.h:9:7: note: candidate: studentType::studentType(const studentType&) /root/sandboxd8237062/studentType.h:9:7: note: candidate expects 1 argument, 6 provided /root/sandboxd8237062/studentType.h:9:7: note: candidate: studentType::studentType(studentType&&) /root/sandboxd8237062/studentType.h:9:7: note: candidate expects 1 argument, 6 provided /root/sandboxd8237062/nt-test-a1086e1d.cpp:8:11: error: 'class studentType' has no member named 'print' student.print(); ^~~~~ /root/sandboxd8237062/nt-test-a1086e1d.cpp:11:14: error: 'class studentType' has no member named 'print' newStudent.print(); ^~~~~ make[2]: *** [CMakeFiles/runTests.dir/nt-test-a1086e1d.cpp.o] Error 1 make[1]: *** [CMakeFiles/runTests.dir/all] Error 2 make: *** [all] Error 2 |
|
|
#endif
.blackstar wrote: |
---|
BTW i had a original working post posted at http://www.cplusplus.com/forum/beginner/252211/ Now this one was working but not passing the argument, could their be any possible way to modify this one with the work above ? |
|
|
i oddly feel like im onto something here but confused as well. (mabye im going insane now) lol staring at this for the last 20 hrs[==========] Running 1 test from 1 test case. [----------] Global test environment set-up. [----------] 1 test from Grades [ RUN ] Grades.1 /root/sandbox1014ee0d/nt-test-b5843ca6.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\nName: Brain Johnson\nGrade: *\nTest score: 85\nProgramming score: 95\nGPA: 3.89\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 |
Value of: Name: \nGrade: F\nTest score: 0\nProgramming score: 0\nGPA: 0\n***************\n\n Name: 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 Name: Brain Johnson\nGrade: *\nTest score: 85\nProgramming score: 95\nGPA: 3.89\n***************\n\n" |
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"); } |
|
|
|
|
|
|
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.) |
|
|
|
|
|
|
main.cpp: In function ‘int main()’: main.cpp:17:3: error: ‘print’ was not declared in this scope print(student); ^~~~~ main.cpp:17:3: note: suggested alternative: ‘printf’ print(student); ^~~~~ printf main.cpp:19:55: error: no matching function for call to ‘studentType::studentType(const char [6], const char [8], char, int, int)’ studentType student2("Brain", "Johnson", 'A', 85, 95); ^ In file included from main.cpp:5:0: studentType.h:9:7: note: candidate: studentType::studentType() class studentType ^~~~~~~~~~~ studentType.h:9:7: note: candidate expects 0 arguments, 5 provided studentType.h:9:7: note: candidate: studentType::studentType(const studentType&) studentType.h:9:7: note: candidate expects 1 argument, 5 provided studentType.h:9:7: note: candidate: studentType::studentType(studentType&&) studentType.h:9:7: note: candidate expects 1 argument, 5 provided studentTypeImp.cpp:7:1: error: ‘score’ does not name a type; did you mean ‘short’? score = (student.testScore + student.programmingScore) / 2; ^~~~~ short studentTypeImp.cpp:8:1: error: expected unqualified-id before ‘if’ if (score >= 90) ^~ studentTypeImp.cpp:10:5: error: expected unqualified-id before ‘else’ else if (score >= 80) ^~~~ studentTypeImp.cpp:12:5: error: expected unqualified-id before ‘else’ else if (score >= 70) ^~~~ studentTypeImp.cpp:14:5: error: expected unqualified-id before ‘else’ else if (score >= 60) ^~~~ studentTypeImp.cpp:16:5: error: expected unqualified-id before ‘else’ else ^~~~ studentTypeImp.cpp: In function ‘void print(studentType&)’: studentTypeImp.cpp:25:24: error: ‘GPA’ was not declared in this scope << "GPA: " << GPA << '\n'; ^~~ bash: line 2: ./a.out: No such file or directory |
studentType
.
|
|
fiji885 (225) |