Professor Dolittle has asked some computer science students to write a program that will help him calculate his final grades. Professor Dolittle gives two midterms and a final exam. Each of these is worth 100 points. In addition, he gives a number of homework assignments during the semester. Each homework assignment is worth 100 points.
At the end of the semester, Professor Dolittle wants to calculate the median score on the homework assignments for the semester. He believes that the median score is a good measure of the student's overall performance on the homework assignments. The median is found by putting the homework scores in order, and then taking the score that is at the midpoint of this list. If there are an odd number of assignments, the median is the score exactly in the middle of the list. If there are an even number of assignments, the median is the average of the two scores closest to the midpoint of the data.
Once the median score is known, professor Dolittle takes the sum of the exam scores and the median homework score and uses this value to compute a letter grade. Letter grades are assigned based on the following table:
Total Score | Letter Grade |
---|---|
381 - 400 | A |
361 - 380 | A- |
341 - 360 | B+ |
321 - 340 | B |
301 - 320 | B- |
281 - 300 | C+ |
261 -280 | C |
241 - 260 | C- |
221 - 240 | D+ |
201 - 220 | D |
181 - 200 | D- |
180 and below | fail |
Program Requirements
Your program should work as follows:
Below is the expected output:
Dr. DoLittle's Grading Program ..... Please enter in the score for the first exam: abc Sorry, your input must be an integer. Please try again. Please enter in the score for the first exam: 97 Please enter in the score for the second exam: 65 Please enter in the score for the final exam: 85 Enter the score for a homework assignment: abc Sorry, your input must be an integer. Please try again. Enter the score for a homework assignment: 200 Sorry, your input must be between 0 and 100. Please try again. Enter the score for a homework assignment: 99 Enter the score for a homework assignment: 65 Enter the score for a homework assignment: 78 Enter the score for a homework assignment: 80 Enter the score for a homework assignment: -1 The median homework score was 79 The total points earned was 326 The letter calculated letter grade is B
Below is the test input:
As a reminder, you need to place all input at once into the input window in Zylabs. For the example above, the input is:
abc 97 65 85 abc 200 99 65 78 80 -1
Code copied:
#include<iostream>
#include<vector>
#include<string>
using namespace std;
double FindMedianScore(vector<int>& scores);
string CalculateLetterGrade(int totalScore);
int main()
{
double firstExam = 0.0;
double secondExam = 0.0;
double finalExam = 0.0;
vector<int> scores;
cout << "Dr. DoLittle's Grading Program ....."
<< endl;
while (true)
{
cout << "Please enter in the
score for the first exam : ";
cin >> firstExam;
//is it not a number?
if (cin.fail()) //(!cin)
{
cout <<
"Sorry, your input must be an integer. Please try again." <<
endl;
cin.clear();
cin.ignore(1024,
'\n');
}
//is it not between 0 and
100?
else if (firstExam < 0 ||
firstExam > 100)
{
cout <<
"Sorry, your input must be an integer. Please try again." <<
endl;}
else
{
break;
}
}
while (true)
{
cout << "Please enter in the
score for the second exam : ";
cin >> secondExam;
//is it not a number?
if (cin.fail()) //(!cin)
{
cout <<
"Sorry, your input must be an integer. Please try again." <<
endl;
cin.clear();
cin.ignore(1024,
'\n');
}
//is it not between 0 and
100?
else if (secondExam < 0 ||
secondExam > 100)
{
cout <<
"Sorry, your input must be an integer. Please try again." <<
endl;
}
else
{
break;
}
}
//added
cout << endl;
while (true)
{
cout << "Please enter in the
score for the final exam : ";
cin >> finalExam;
//is it not a number?
if (cin.fail()) //(!cin)
{
cout <<
"Sorry, your input must be an integer. Please try again." <<
endl;
cin.clear();
cin.ignore(1024,
'\n');
}
//is it not between 0 and
100?
else if (finalExam < 0 ||
finalExam > 100)
{
cout <<
"Sorry, your input must be an integer. Please try again." <<
endl;
}
else
{
break;
}
}
int inputValue = 0;
while (inputValue != -1)
{
while (true)
{
cout <<
"Enter the score for a homework assignment: ";
cin >> inputValue;
//is it not a number?
if (cin.fail()) //(!cin)
{
cout << "Sorry, your
input must be an integer. Please try again." << endl;
cin.clear();
cin.ignore(1024, '\n');
}
//is it not between 0 and 100?
else if (inputValue < -1 || inputValue >
100)
{
cout << "Sorry, your
input must be an integer. Please try again." << endl;
}
else
{
if (inputValue != -1)
{
scores.push_back(inputValue);
}
break;
}
}
}
double median = FindMedianScore(scores);
double total = firstExam + secondExam + finalExam +
median;
string letterGrade =
CalculateLetterGrade(total);
cout << "The median homework score was "
<< median << endl;
cout << "The total points earned was " <<
total << endl;
cout << "The letter calculated letter grade is "
<< letterGrade << endl;
}
double FindMedianScore(vector<int>& scores)
{
//sort vector
//determine if its even or odd size
//get medianreturn 0.0;
}
string CalculateLetterGrade(int totalScore)
{
return string();
}
I have provided the code for your question.
You just have to edit the the two functions , CalculateLetterGrade() and FindMedianScore(). Additionally, a sorting function is also used which is implemented as Selection Sort (you need to declare the function above main. " void sort(vector<int>& arr);"). You can use any sorting function . If you can use the library funtions, you need to add #include <algorithm> as a header, and just use "sort(scores.begin(),scores.end());" in FindMedianScore() for sorting.
If you don't know what Selection Sort is. :
For every number from beginning, it find the number smaller than this element in the remaining array until the end and swaps these two elements.
This process is repeated until end.
The required functions' Code:-
double FindMedianScore(vector<int>& scores)
{ int mid = scores.size()/2;
double median;
// sort(scores.begin(),scores.end()); // Un comment this line if
you can
// use the inbuild- sort function. for this you need to add
"#include<algorithm>" as header in line 1.
sort(scores);
if(scores.size()%2==0){ // if its even , then median is average if
middle two elements
median= (float)((scores[mid]+scores[mid-1])/2.0);
}
else median=(float)(scores[mid]/1.0); // else median is the middle
element
//sort vector
//determine if its even or odd size
//get medianreturn 0.0;
return median;
}
string CalculateLetterGrade(int totalScore)
{
// this is straight forawrd.
if(totalScore>380)
return "A";
if(totalScore>360)
return "A-";
if(totalScore>340)
return "B+";
if(totalScore>320)
return "B";
if(totalScore>300)
return "B-";
if(totalScore>280)
return "C+";
if(totalScore>260)
return "C";
if(totalScore>240)
return "C-";
if(totalScore>220)
return "D+";
if(totalScore>200)
return "D";
if(totalScore>180)
return "D-";
else return "fail";
// return string();
}
/*Selection Sort Algorithm to sort a given vector.
Add the following line above main .
void sort(vector<int>& arr);
*/
void sort(vector<int>& arr){
for(int i=0; i<arr.size(); i++)
{
for(int j=i+1; j<arr.size(); j++)
{
if(arr[i]>arr[j])
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
}
**Thank You. Please comment for any additional clarifications.**
COMPLETE CODE:
#include<iostream>
#include<vector>
#include<string>
// #include<algorithm>
using namespace std;
double FindMedianScore(vector<int>& scores);
string CalculateLetterGrade(int totalScore);
void sort(vector<int>& arr);
int main()
{
double firstExam = 0.0;
double secondExam = 0.0;
double finalExam = 0.0;
vector<int> scores;
cout << "Dr. DoLittle's Grading Program ....." <<
endl;
while (true)
{
cout << "Please enter in the score for the first exam :
";
cin >> firstExam;
//is it not a number?
if (cin.fail()) //(!cin)
{
cout << "Sorry, your input must be an integer. Please try
again." << endl;
cin.clear();
cin.ignore(1024, '\n');
}
//is it not between 0 and 100?
else if (firstExam < 0 || firstExam > 100)
{
cout << "Sorry, your input must be an integer. Please try
again." << endl;}
else
{
break;
}
}
while (true)
{
cout << "Please enter in the score for the second exam :
";
cin >> secondExam;
//is it not a number?
if (cin.fail()) //(!cin)
{
cout << "Sorry, your input must be an integer. Please try
again." << endl;
cin.clear();
cin.ignore(1024, '\n');
}
//is it not between 0 and 100?
else if (secondExam < 0 || secondExam > 100)
{
cout << "Sorry, your input must be an integer. Please try
again." << endl;
}
else
{
break;
}
}
//added
cout << endl;
while (true)
{
cout << "Please enter in the score for the final exam :
";
cin >> finalExam;
//is it not a number?
if (cin.fail()) //(!cin)
{
cout << "Sorry, your input must be an integer. Please try
again." << endl;
cin.clear();
cin.ignore(1024, '\n');
}
//is it not between 0 and 100?
else if (finalExam < 0 || finalExam > 100)
{
cout << "Sorry, your input must be an integer. Please try
again." << endl;
}
else
{
break;
}
}
int inputValue = 0;
while (inputValue != -1)
{
while (true)
{
cout << "Enter the score for a homework assignment: ";
cin >> inputValue;
//is it not a number?
if (cin.fail()) //(!cin)
{
cout << "Sorry, your input must be an integer. Please try
again." << endl;
cin.clear();
cin.ignore(1024, '\n');
}
//is it not between 0 and 100?
else if (inputValue < -1 || inputValue > 100)
{
cout << "Sorry, your input must be an integer. Please try
again." << endl;
}
else
{
if (inputValue != -1)
{
scores.push_back(inputValue);
}
break;
}
}
}
double median = FindMedianScore(scores);
double total = firstExam + secondExam + finalExam + median;
string letterGrade = CalculateLetterGrade(total);
cout << "The median homework score was " << median
<< endl;
cout << "The total points earned was " << total
<< endl;
cout << "The letter calculated letter grade is " <<
letterGrade << endl;
}
double FindMedianScore(vector<int>& scores)
{ int mid = scores.size()/2;
double median;
// sort(scores.begin(),scores.end()); // Un comment this line if
you can
// use the inbuild- sort function. for this you need to add
"#include<algorithm>" as header in line 1.
sort(scores);
if(scores.size()%2==0){ // if its even , then median is average if
middle two elements
median= (float)((scores[mid]+scores[mid-1])/2.0);
}
else median=(float)(scores[mid]/1.0); // else median is the middle
element
//sort vector
//determine if its even or odd size
//get medianreturn 0.0;
return median;
}
string CalculateLetterGrade(int totalScore)
{
// this is straight forawrd.
if(totalScore>380)
return "A";
if(totalScore>360)
return "A-";
if(totalScore>340)
return "B+";
if(totalScore>320)
return "B";
if(totalScore>300)
return "B-";
if(totalScore>280)
return "C+";
if(totalScore>260)
return "C";
if(totalScore>240)
return "C-";
if(totalScore>220)
return "D+";
if(totalScore>200)
return "D";
if(totalScore>180)
return "D-";
else return "fail";
// return string();
}
/*Selection Sort Algorithm to sort a given vector.
Add the following line above main .
void sort(vector<int>& arr);
*/
void sort(vector<int>& arr){
for(int i=0; i<arr.size(); i++)
{
for(int j=i+1; j<arr.size(); j++)
{
if(arr[i]>arr[j])
{
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
}
}
Professor Dolittle has asked some computer science students to write a program that will help him...
This is my code for a final GPA calculator. For this assignment, I'm not supposed to use global variables. My question is: does my code contain a global variable/ global function, and if so how can I re-write it to not contain one? /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Title: Final GPA Calculator * Course Computational Problem Solving CPET-121 * Developer: Elliot Tindall * Date: Feb 3, 2020 * Description: This code takes grades that are input by the student and displays * their...
Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) { // average function , declaring variable int i; char str[40]; float avg = 0; // iterating in...
C++ language I am having some trouble with user validation, can someone look at my code and tell me what I am doing wrong: char firstInital, lastInitial; int userAge; std::cout << "Program 1-2: Get user initials and age in days\n "; std::cout << "-------------------------------------------------------------------------\n"; std::cout << "Please enter the first letter of your first name: \n " << flush; std::cin >> firstInital; std::cout << "Please enter the first letter of your last name: \n...
Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...
Assignment Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). For non-prime numbers, output a list of all divisors of the number. Format your...
I did a program in computer science c++. It worked fine the first and second time when I ran the program, but suddenly it gave me an error. Then, after a few minutes, it started to run again and then the error showed up again. This is due tonight but I do not know what is wrong with it. PLEASE HELP ME! Also, the instruction for the assignment, the code, and the error that occurred in the program are below....
I would like to preface this by saying this is NOT a current homework assignment; but it is an assignment from 3 years ago before I dropped out of school. I am self teaching and am revisiting an old assignment. I am NOT asking for the entire program, I'm simply looking for help building the skeleton for the initial start of the game.MORE INFO: Player 1 will enter word(of any length / i have been using "Testing") for Player 2...
This is what I have as of right now. I am lost on what to do next#include <stdio.h>#include <iostream>using namespace std;int main(){ double scores, numOfStudents, average = 0, highscore, sum = 0; string names; cout << "Hello, please enter the number of students" << endl; cin >> numOfStudents; do { cout << "Please enter the student's name:\n"; cin >> names; cout << "Please enter the student's...
Need code written for a java eclipse program that will follow the skeleton code. Exams and assignments are weighted You will design a Java grade calculator for this assignment. A user should be able to calculate her/his letter grade in COMS/MIS 207 by inputting their scores obtained on worksheets, assignments and exams into the program. A skeleton code named GradeCompute.java containing the main method and stubs for a few other methods, is provided to you. You must not modify/make changes...
Modify Assignment #18 so it drops each student’s lowest score when determining the students’ test score average and Letter grade. No scores less than 0 or greater than 100 should be accepted #include<iostream> #include<string> using namespace std; int main() { double average[5]; string name[5]; char grade[5]; for(int i=0; i<=5; i++) { cout<<"Enter student name: "; cin.ignore(); getline(cin,name[i]); int sum=0; for(int j=0; j<5; j++) { int grades; cout<<"Enter Grades:"<<j+1<<" : "; cin>>grades; sum+=grades; } average[i]=(float)sum/5; if(average[i]>=90 && average[i]<=100) grade[i]='A'; else if(average[i]>=80...