I need the two programs seperated. In C++ Problem 2: Test Scores (Chapter 9: Poi
ID: 3913378 • Letter: I
Question
I need the two programs seperated. In C++ Problem 2: Test Scores (Chapter 9: Pointers & chapter 8: Searching and Sorting) Write a program that dynamically allocates an array large enough to hold a user defined number of test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and the average. Use pointer notation rather than array notation whenever possible. nput validation: Do not accept negative numbers for test scores. b. Drop Lowest Score Modify program (problem 2) so the lowest test score is dropped. included in the calculation of the average. This score should not beExplanation / Answer
here is your program : ---------->>>>>>>>>
#include<iostream>
using namespace std;
void display(int *test,int size,int average){
cout<<" Scores : ";
for(int *i = test;i<(test+size);i++){
cout<<(*i)<<" ";
}
cout<<" Average : "<<average;
}
void sort(int *test,int size){
int temp;
for(int *i = test;i<(test+size);i++){
for(int *j = i+1;j<(test+size);j++){
if((*i) > (*j)){
temp = *i;
*i = *j;
*j = temp;
}
}
}
}
int calculateAverage(int *test,int size){
int temp = 0;
for(int *i = test+1;i<(test+size);i++){
temp += *i;
}
return temp/size;
}
int main(){
int N = 0;
while(N <= 0){
cout<<" Enter Number Of Test Score : ";
cin>>N;
if(N <= 0){
cout<<" Please Enter Number Larger than 0";
}
}
int *testScores = new int[N];
cout<<" Enter "<<N<<" Number of test Score : ";
for(int *i = testScores;i<(testScores+N);i++){
cin>>(*i);
if((*i) < 0){
cout<<" Error:Negative Number !!! ";
i--;
}
}
sort(testScores,N);
int avg = calculateAverage(testScores,N);
display(testScores,N,avg);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.