Suppose we have to write a program where a mark out of 60 is entered and then the corresponding symbol has to be displayed. A message indicating whether the person has passed or not, should also be displayed. We decide to write the program in three steps. You should submit the program and out of Question 1c only.
Question 1a:
We give the main function below. Your task is to write a function, namely letters, of type char. It receives in a parameter of type int and returns a letter of the alphabet. The symbol is determined as follows:

Mark Character
0 – 39 F or f
40 – 49 E or e
50 – 59 D or d
60 – 69 C or c
70 – 79 B or b
80 – 100 A or a
Test your program with several input values

#include<iostream>
using namespace std;

// the required function prototype should be inserted here

int main()
{
	int mark;
	char ch;

	cout << “Enter the mark out of 60: ”;
	cin >> mark;

	ch = letters(mark);

	cout << “Symbol corresponding to ” << mark << “ is ”
                    << ch << endl;

	return 0;
}

Question 1b:
Now you should write another value-returning function, namely passOrNot of type bool. It receives a letter in a parameter of type char. If the letter is either E, e , or F,f, the value false should be returned, otherwise the value true should be returned.

Question 1c:
Write a full fledged modular program that contains the functions letters and passOrNot that you wrote in Questions 1a and 1b. The program has to determine who pass and who do not pass, given a list of marks. It should also inform how many students passed and how many failed as well the number of distinctions. (>= 75%). The main( ) function should contain a while loop that is repeated until XXX is entered for a mark. Run the program on the list of marks below and submit printouts of the program and the output

22
55
80
48
60
87
44
50
77
17
XXX

I'll just hope you're not in highschool yet so...here's the first function you'll need...it's pretty straightforward:

char letter( int mark ) {
     if( mark <= 39 ) return 'F';
     else if( mark <= 49 ) return 'E';
     else if( mark <= 59 ) return 'D';
     else if( mark <= 69 ) return 'C';
     else if( mark <= 79 ) return 'B';
     else if( mark <= 100 ) return 'A'; 
}

I'll just hope you're not in highschool yet so...here's the first function you'll need...it's pretty straightforward:

char letter( int mark ) {
     if( mark <= 39 ) return 'F';
     else if( mark <= 49 ) return 'E';
     else if( mark <= 59 ) return 'D';
     else if( mark <= 69 ) return 'C';
     else if( mark <= 79 ) return 'B';
     else if( mark <= 100 ) return 'A'; 
}

Theres one problem with this function that may give you a compiler warning.
Heres what I got:

warning C4715: 'letter' : not all control paths return a value

To fix it just add this:

char letter( int mark ) {
     if( mark <= 39 ) return 'F';
     else if( mark <= 49 ) return 'E';
     else if( mark <= 59 ) return 'D';
     else if( mark <= 69 ) return 'C';
     else if( mark <= 79 ) return 'B';
     else if( mark <= 100 ) return 'A'; 
     return 0;
}

This way the function is guaranteed to return a value.

hmmmm but why would we expect anything else but integers between 1 and 100? Well anyways...if the default return satisfies your compiler...ok

Thats not really the point ^_^ But its always good practice to make sure that there are no warnings what so ever.

hmmmm but why would we expect anything else but integers between 1 and 100?

Thats not really the point ^_^ But its always good practice to make sure that there are no warnings what so ever.

williamhemsworth is correct. And in addition, haven't you ever heard of extra credit, or maybe mistakes?

Hope this helps for the point 1b)

bool passOrNot(const char& letter){
  return (letter>='a' && letter<='d' || letter >='A' && letter<='D');
}

regards!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.