Question:
C++ Experts q3 - VALUE RETURNING FUNCTIONS WITH ONE OR MORE VALUE PARAMETERS : Long problem with 3 parts ?
Ashley Durban SA
2009-08-27 05:19:00 UTC
The IT firm ITEnterprizes has a unique way of deciding whether an applicant for a post should be invited for an
interview or not. The decision depends on the candidate’s qualifications, age and years of experience and is made as
follows: a certain weight is assigned to each of these aspects and the total is determined. All candidates with a rating
above 44 are invited for an interview.
You have to develop a C++ program to do the above. It will be done in three steps. You need to submit the program
and output of question 3c only. You will see that we declare a global constant.
Question 3a: Start small
We give the main function below. Your task is to write three functions, namely qualFactor, ageFactor and
experFactor, all of return type int. Each of these functions has one value parameter.
The function qualFactor receives a char value. The character U indicates a university degree and a weight
of 40 should be returned. The character D indicates a diploma and a weight of 30 should be returned. The
character M indicates that the candidate has passed Grade 12 at school and a weight of 20 should be returned.
If any other character is received, a weight of 0 should be returned. Use a switch statement in this
function.
The function ageFactor receives an int value, namely the age. If the candidate is older than 22 but younger
than 40, a weight of 10 should be returned. If the candidate is 40 years or older but not older than 55, a
weight of 5 should be returned. A weight of 0 should be returned in all other cases..
The function experFactor receives an int value, namely the years experience. If the candidate has 10 or
more years experience, a weight of 20 should be returned. If the candidate has less than 10 but more than 5
years experience, a weight of 10 should be returned. Otherwise a weight of 0 should be returned.

Test your program with several input values but do not submit any printouts.
// Assignment 2 Question 3a
#include
using namespace std;
/
/ The required functions qualFactor, ageFactor and experFactor
// should be inserted here.
i
nt main( )
{
char qual;
int age, exper, qualWeight, ageWeight, experWeight;
cout << "Highest qualification" << endl << "Enter U (degree), or "
<< " D (diploma), or M (grade 10); otherwise any character: ";
cin >> qual;
cout << "Age: ";
cin >> age;
cout << "Years experience: ";
cin >> exper;
qualWeight = qualFactor(qual);
ageWeight = ageFactor(age);
experWeight = experFactor(exper);
cout << qualWeight << " " << ageWeight << " "
<< experWeight << endl;
return 0;
}

Question 3b: Still small
Now write another value returning function, namely interviewOrNot, of return type bool. There are three
value parameters. The function receives the three weights that were assigned to the qualification, age and years
experience, respectively, and then has to determine whether the candidate should be invited to an interview. If so,
the value true has to be returned. If not, the value false has to be returned. We give the main function again.
Test your program with several input values but do not submit any printouts.

// Assignment 2 Question 3b
#include
using namespace std;
c
onst int CUT_OFF = 44;
/
/ The required functions qualFactor, ageFactor,
// experFactor and interviewOrNot should be inserted here.
i
nt main( )
{
char qual;
int age, exper, qualWeight, ageWeight, experWeight;
bool invite;
cout << "Highest qualification" << endl << "Enter U (degree), or "
<< " D (diploma), or M (grade 10); otherwise any character: ";
cin >> qual;
cout << "Age: ";
cin >> age;
cout << "Years experience: ";
cin >> exper;
qualWeight = qualFactor(qual);
ageWeight = ageFactor(age);
experWeight = experFactor(exper);

invite = interviewOrNot(qualWeight, ageWeight, experWeight);
if (invite)
cout << "Candidate should be invited for an interview."
<< endl;
else
cout << "Candidate is unsuccessful." << endl;
return 0;
}

Question 3c: Add a loop to the main function
Write a program containing the functions qualFactor, ageFactor, experFactor and interviewOrNot
that you wrote in 3a and 3b. The program has to process a list of applications and display the applicable message for
every application. You may use the main function of 3b but you will have to change it as it should now contain a
for loop. Run your program on the list of 9 applications below and submit printouts of the program and output.
U 26 4
D 26 5
M 26 8
X 33 13
U 66 40
U 44 2
M 38 20
D 44 20
D 36 12
Three answers:
anonymous
2009-08-27 05:53:53 UTC
What is the question ?
?
2016-10-03 09:44:53 UTC
a million. considerable syntax     considerable() {} this is valid (on some implementations) by way of fact the integer return-kind is implicit.     int considerable() {} this is efficiently an identical by way of fact the 1st.     int considerable(void) {} this suggests that the function would not take any arguments. The arguments to considerable are presented with the help of the person; while "void" is interior the parameters no arguments would be everyday into the function.     void considerable() {} The above isn't valid. that is not even general C. in basic terms use one among the two modifications on suitable as a exchange. 2. purposes putting void in front of the function call wasn't the subject. in actuality, it replaced into surprising in view which you're no longer returning a value. the subject replaced into this line:     structureName obtainStructureOne(structureName *ptr) {         strcpy(ptr->firstName,"John");         ptr->age=23;     } The return-kind is distinctive as an merchandise of trend structureName, yet you do no longer even return a value interior the function. perhaps you meant to return ptr? if so, then in basic terms upload the line "return *ptr" (observe the *) on the top of the function. So there replaced into no choose for void in that function, different than in case you intentionally did no longer choose to return a value, wherein case you are able to accomplish that. A "void" return-kind is for purposes that don't return values.
Paul
2009-08-27 05:55:24 UTC
I doubt that anyone will want to write the entire program for you - try to focus on a specific area that you are having difficulty with and ask for help with that. E.g. you might ask what data structures would be good to use for this problem, or how you get the input data into the data structures, etc.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...