In: Computer Science
In C++, please comment on everything as much as posible because i have hard understanding with this topic.
DO NOT COPY PAST FROM OTHER POSTS PLEASE
Write a program to do the following.
In the main function, the program should define an integer array and a pointer that points to the array.it will ask the user to input25students’scores (scores are between 0 and 100inclusive, so need to do input validation), then pass the pointer and its size to a function. The function should find the corresponding letter grades and return the pointer that points to the array of letter grades.
Also pass the score pointer and its size to the other function, which will calculate the average of those 25 scores with the lowest and highest score dropped, and then return the average (double type).
The input of those scores and output of the letter scores and average must be in the main function, and there is no input and output in the functions besides the main function.
No global variables are allowed.
90-100 (include 90 and 100) is A
80-90 (include 80 but not include 90) is B
70-80 (include 70 but not include 80) is C
60-70 (include 60 but not include 70) is D
below 60 is F
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.
Thank You!
===========================================================================
#include<iostream>
using namespace std;
// The function should find the corresponding letter
grades
// ghand return the pointer that points to the array of letter
grades.
char* letterGrades(int* scores, int size){
char* grades = new char[size];
for(int i=0; i<size;i++){
if(scores[i]>=90)
grades[i]='A';
else if(scores[i]>=80)
grades[i]='B';
else if(scores[i]>=70)
grades[i]='C';
else if(scores[i]>=60)
grades[i]='D';
else grades[i]='F';
}
return grades;
}
//Also pass the score pointer and its size to the
other
// function, which will calculate the average of those 25
// scores with the lowest and highest score dropped,
double getAverage(int *scores, int size){
int min=0, max = 0;
int total = scores[0];
for(int i=1; i<size;i++){
if(scores[i]>scores[max])max
=i;
if(scores[i]<scores[min])min
=i;
total += scores[i];
}
total = total - scores[min] - scores[max];
return total/(size-2);
}
int main(){
const int STUDENTS = 25;
//CREATE array of int and store the address in scores
pointer
int* scores = new int[STUDENTS];
for(int i=0; i<STUDENTS; i++){
do{
cout<<"Enter score for student #"<<i+1<<":
";
cin >>
scores[i];
}while(scores[i]<0 ||
scores[i]>100);
}
char* letter = letterGrades(scores,STUDENTS);
for(int i=0;
i<STUDENTS;i++){
cout<<scores[i]<<" Grade: "
<<letter[i]<<endl;
}
cout<<"Average after removing
max and min scores: "<<getAverage(scores,STUDENTS);
return 0;
}
==================================================================