Question

Modify Assignment #18 so it drops each student’s lowest score when determining the students’ test score...

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 && average[i]<=89)
grade[i]='B';

else if(average[i]>=70 && average[i]<=79)
grade[i]='C';

else if(average[i]>=60 && average[i]<=69)
grade[i]='D';

else if(average[i]>=0 && average[i]<=59)
grade[i]='F';

}

cout<<"Name\tAverage\tMarks"<<endl;

for(int i=0; i<5; i++)
{
cout<<name[i]<<"\t"<<average[i]<<"\t"<<grade[i]<<endl;
}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#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;
int min=100;
for(int j=0; j<5; j++)
{
int grades;
cout<<"Enter Grades:"<<j+1<<" : ";
cin>>grades;

//checking whether grade is less than 0 or greater than 100
if(grades<0 || grades>100){//if condition satisfies re-entering  the value
cout<<"Invalid grades!!! Please re-enter\n";
j--;
}

else{
sum+=grades;
if(min > grades){
//storing minimum grade in min variable
min = grades;
}
}
}
sum = sum - min;
//dropping minimum grade
average[i]=(float)sum/4;//now average is taken from 4 grades

if(average[i]>=90 && average[i]<=100)
grade[i]='A';

else if(average[i]>=80 && average[i]<=89)
grade[i]='B';

else if(average[i]>=70 && average[i]<=79)
grade[i]='C';

else if(average[i]>=60 && average[i]<=69)
grade[i]='D';

else if(average[i]>=0 && average[i]<=59)
grade[i]='F';

}

cout<<"Name\tAverage\tMarks"<<endl;

for(int i=0; i<5; i++)
{
cout<<name[i]<<"\t"<<average[i]<<"\t"<<grade[i]<<endl;
}

}

OUTPUT :

Hope this helps you!!!

Add a comment
Know the answer?
Add Answer to:
Modify Assignment #18 so it drops each student’s lowest score when determining the students’ test score...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that prompts the user to enter the number of students and each student’s name and score, and finally displays the student with the highest score (display the student’s name and score). Also calculate the average score and indicate by how

    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...

  • Am I getting this error because i declared 'n' as an int, and then asking it...

    Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() {    int n;    double avg, sum = 0;;    string in_file, out_file;    cout << "Please enter the name of the input file: ";    cin >> in_file;   ...

  • Need help with a C++ program. I have been getting the error "this function or variable...

    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...

  • Fix my code, if I the song or the artist name is not on the vector,...

    Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...

  • What did I do wrong with this C++ code? Assume that we don't need to ask...

    What did I do wrong with this C++ code? Assume that we don't need to ask users for the number of students. #include <iostream> #include <iomanip> using namespace std; int main() { float *grades; // a pointer used to point to an array int size; int count = 0; // track the number of grade/student float grade; // the grade of a student float average, total; // average grade and total grades //**************start your code here************************ cout<<"How many student grades...

  • // This program will read in a group of test scores (positive integers from 1 to...

    // This program will read in a group of test scores (positive integers from 1 to 100) // from the keyboard and then calculate and output the average score // as well as the highest and lowest score. There will be a maximum of 100 scores. // #include <iostream> using namespace std; float findAverage (const int[], int); // finds average of all grades int findHighest (const int[], int); // finds highest of all grades int findLowest (const int[], int); //...

  • Implement and test a function that uses dynamic array to store students’ grades and calcuate the...

    Implement and test a function that uses dynamic array to store students’ grades and calcuate the average grade. // This program demonstrates the use of dynamic array // it #include <iostream> #include <iomanip> using namespace std; int main() { float *grades; // a pointer used to point to an array int size = 2; grades = new float[size];    int count = 0; // track the number of grade/student float grade; // the grade of a student float average, total;...

  • C++ Assignment on Search and Sort for Chapter 8 Problem: Modify the student grade problem to...

    C++ Assignment on Search and Sort for Chapter 8 Problem: Modify the student grade problem to include the following: •   Write a Search function to search by student score •   Write a Search function to search by student last name •   Write a Sort function to sort the list by student score •   Write a Sort function to sort the list by student last name •   Write a menu function that lets user to choose any action he/she want to...

  • The following is solved using C++ in Vocareum: In this problem, you will be prompting a...

    The following is solved using C++ in Vocareum: In this problem, you will be prompting a student for grades and credits for courses taken. From that, you will calculate a GPA. This site: http://www.back2college.com/gpa.htm shows you how to calculate a GPA. Keep prompting the student if they want to add more courses. IMPORTANT NOTES! The course name is prompted for, but nothing is done with it. We are just using the grades A, B, C, D, and F so you...

  • Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment...

    Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT