1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
i'm not sure what i'm doing wrong here but nothing is displaying...
Assignment Objectives:
Continued practice in passing arguments to functions
Returning values from functions and using those values returned
Continued practice in user-controlled looping
Continued practice in decision making
Your Task: Read these specifications very carefully and construct your program accordingly. In order to get full credit for this assignment, you must follow this design model. Before you proceed, you should be familiar with the terminology used in chapter 5, such as arguments, return type, and return value.
You will write a program with the following functions:
Calc_Average – This function called calc_average will accept two float arguments. It will also return a float. The job of this function is to take in the two floats (representing a student’s midterm and final grades) as arguments, average them together, and return the student’s average (in the form of a float) back to main.
Letter_Grade – This function called letter_grade will accept one float argument. It will also return a char. The job of this function is to accept the float (representing a student’s average, which you will have gotten back from calc_grade) as an argument, assign a letter grade based on the student’s average (use 90-100 is an A, 80-89 is a B and so on…), and return the student’s letter grade (in the form of a char – ‘A’, ‘B’, ‘C’…) back to main.
Eligible – This function called eligible will accept one char argument. It will also return an int. The job of this function is to accept the char (representing a student’s letter grade, which you will have gotten back from letter_grade) as an argument and, if the grade is an ‘A’ (meaning the student is eligible for the President’s List) return a 1 back to main. If the grade is not an A, return a 0 back to main. Meanwhile, in main, you will keep a tally of eligible students (i.e. 1’s). Realize that the value returned by the eligible function can be added to a running total up in main.
Main—In main, you will start by asking the user how many students are in the class. You will then construct a loop (use your loop of choice) that will go as many times as that number entered. Here is some pseudocode you can use to program the inside of the loop:
//Get miderm grade for student x
//Get final grade for student x
//Use calc_average to calculate student average; capture the return value in a variable; print the average on the screen
//Use letter_grade to assign a letter grade based on student average; capture the letter in a variable; print the letter grade on the screen
//Use eligible function to determine President List eligibility based on student’s letter grade; add the return value (either 0 or 1) to a running total. Remember that when we get a running total, we use our arithmetic assignment operators (e.g.+=).
Don’t forget to print the number of eligible students at the end of the program.
Sample Output:
How many students in the class?: 3
Enter midterm grade for student 1: 80
Enter final grade for student 1: 95
Student 1's average: 87.5
Student 1's letter grade: B
Enter midterm grade for student 2: 90
Enter final grade for student 2: 92
Student 2's average: 91
Student 2's letter grade: A
Enter midterm grade for student 3: 90
Enter final grade for student 3: 94
Student 3's average: 92
Student 3's letter grade: A
Number of students eligible for the President's List: 2
Press any key to continue
Remember that when your function returns a value, your function call is always going to be part of a larger statement, such as an assignment statement.
Example:
int x = somefunc(z); //Where somefunc is a function that returns an integer. Remember, you’ve got to put it somewhere!
Also, do not use any global variables in this program! (see pages 202-203 in your book)
my program so far
#include <iostream>
#include <string>
#include <stdlib.h>
#include <iomanip>
using namespace std;
float calc_average(float m, float f);
char letter_grade(float a);
float eligible(float t);
float students = 0;
char l = 0;
char AssignGrade(float letter_grade)
{
char letter_grade = '\0';
if (letter_grade >= 90)
letter_grade = 'A';
else if (letter_grade >= 80)
letter_grade = 'B';
else if (letter_grade >= 70)
letter_grade = 'C';
else if (letter_grade >= 60)
letter_grade = 'D';
else
letter_grade = 'F';
return letter_grade;
}
int main()
{
float mt = 0, fin = 0, avg = 0;
char letter = '\0';
int prezList = 0;
cout << "How many students in the class?: ";
cin >> students;
return students;
cout << "Enter midterm grade for student 1:";
cin >> mt;
cout << "Enter final grade for student 1: ";
cin >> fin;
avg = calc_average(mt, fin);
letter = letter_grade(avg);
prezList += eligible(letter);
cout << "Student 1 Average:";
cout << AssignGrade(avg) << endl;
cout << "Student 1 letter grade: ";
cout << letter_grade;
cout << "Number of students eligible for the Presidents List: ";
int eligible(char l);
{
if (l == 'A')
{
return 1;
}
else if (l /= 'A')
{
return 0;
}
return l;
}
system("PAUSE");
return 0;
}
float calc_average(float m, float f)
{
float average = (m + f) / 2;
return average;
}
float eligible(float t)
{
return 0 ;
}
|