Reputation: 21
I'm trying to complete a structs exercise;
- a. You will define and declare struct data with the following 3 hypothetical student information in this course. Assume Lab score is 70% and Test score is 30% of the total grades.
First name (string) : John Alisa Mike Last name (string) : White Brown Green Course Grade (char) : 0 (to be calculated) “ “ Test score (int) : 88 90 75 Lab score (int) : 70 64 97
b. Perform the following tasks:
- Initialize/declare each student in struct data type. Notice the IntelliSense feature of MVS.
- Calculate Course grade with a function call (i.e. getGrade). This could be a void function pass-by-reference or appropriate char function to return course grade. Inputs will be the test score and the labs score. The percentages (30% and 70%) could be defined as global double constants. Use step-by-step incremental approach to develop your code.
- Display the student information back to the user. Try to use a function call to print this output (See page 620). And ask me for some ideas about how to proceed. A sample output might be:
John White Grade is: C Test Score is: 88 Lab Score is: 70 Alisa Brown Grade is: C Test Score is: 90 Lab Score is: 64 Mike Green Grade is: A Test Score is: 75 Lab Score is: 97 Press any key to continue . . .
Here's what I have put together so far and am stuck- Not sure why I'm not getting the desired output. (any help would be greatly appreciated!):
//
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const double testweight = 0.30;
const double labweight = 0.70;
char getGrade(int testScore, int labScore) {
if ((testweight * testScore) + (labweight * labScore) >= 90)
return 'A';
else if ((testweight * testScore) + (labweight * labScore) >= 80)
return 'B';
else if ((testweight * testScore) + (labweight * labScore) >= 70)
return 'C';
else if ((testweight * testScore) + (labweight * labScore) >= 60)
return 'D';
else return 'F';
}
struct studentType
{
string studentFName;
string studentLName;
int testScore;
int labScore;
char grade;
};
void printstudent(studentType student)
{
cout << student.studentFName << " " << student.studentLName
<< "" << student.testScore
<< "" << student.labScore
<< "" << student.grade << endl;
}
int main()
{
studentType student1;
studentType student2;
studentType student3;
student1.studentFName = "John";
student1.studentLName = "White";
student1.testScore = 88;
student1.labScore = 70;
student1.grade = getGrade(student1.testScore, student1.labScore);
student2.studentFName = "Alisa";
student2.studentLName = "Brown";
student2.testScore = 90;
student2.labScore = 64;
student2.grade = getGrade(student2.testScore, student2.labScore);
student3.studentFName = "Mike";
student3.studentLName = "Green";
student3.testScore = 75;
student3.labScore = 97;
student3.grade = getGrade(student3.testScore, student3.labScore);
void printstudent(studentType student);
}
Upvotes: 1
Views: 1628
Reputation: 122298
This..
void printstudent(studentType student);
is not how you call a function (it is a function declaration).
After replacing that line with
printStudent(student3);
// ^^ name of the function to call
// ^^ parameter(s) passed to the function
I get the following output:
Mike Green7597A
You probably want to add some blanks and print also the other students. I suggest you to study std::vector
and loops to make your code easier.
Upvotes: 2
Reputation: 11
The last line of your code is a function declaration. This should be function call. Replace it with one or all lines from code below:
printstudent(student1);
printstudent(student2);
printstudent(student3);
For function call you need function_name, parenthesis in which you put argument and semicolon at the end.
function_name(argument);
Upvotes: 1