void FUNCTIONS WITH DIFFERENT TYPES AND NUMBERS OF PARAMETERS
Ms Smart, a lecturer at a famous university, wants to compare the results of male and female students. She decides
to calculate four averages, namely
the average year mark for male students,
the average year mark for female students,
the average exam mark for male students
the average exam mark for female students.
Write a C++ program to help Ms Smart with this. The program is developed in three steps. You have to submit
printouts for 5c only.
Question 5a: Three reference parameters
Write a void function inputAndValidate where the results of one student are input and validated. The
function should have three reference parameters, namely a parameter that stores the sex of the student, i.e. male or
female, as a character ‘m’ or ‘f’ (thus of type char), a parameter that stores the year mark of the student (of type
int) and a parameter that stores the exam mark of the student (of type int).
// Assignment 2 Question 5a
#include <iostream>
using namespace std;
// The required function inputAndValidate should be inserted here.
void inputAndValidate (char Sex, int YearMark, int ExamMark){
char sex;
int yearMark, examMark;
do {cout << "Please enter your sex, m if you are male and f if you are female ";
cin >> sex;
cout << "This student is ";
if (sex == 'm')
cout << "male and has a year mark of";
else
cout << "female and has a year mark of ";
cout << yearMark << " and an exam mark of "
<< examMark << endl;}
while (sex != 'm' || sex != 'f');
}
int main( )
{
int yearMark, examMark;
char sex;
inputAndValidate(sex, yearMark, examMark);
cout << "This student is ";
if (sex == 'm')
cout << "male and has a year mark of";
else
cout << "female and has a year mark of ";
cout << yearMark << " and an exam mark of "
<< examMark << endl;
return 0;
}