Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create programs using Visual C++ to solve the following problems. Be sure that e

ID: 3852712 • Letter: C

Question

Create programs using Visual C++ to solve the following problems. Be sure that each program includes the following: Header: //Your Name //Dr, R. Knowles //Program Description Initialized variables Comments for clarity Whitespace for readability Specific instructions for the user Create a New Project called YourLastnameSortScores. 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 averages with appropriate headings. Use pointer notation rather than array notation whenever possible.

Explanation / Answer

// Example program
#include <iostream>
#include <string>

void sortArray(int* anArray, int size)
{
bool sort = false;

for (int i = 0; i < size; i++)
{
for (int j = 0; j < size - 1; j++)
{
if (anArray[j] > anArray[j + 1])
{
sort = true;
double temp = anArray[j];
anArray[j] = anArray[j + 1];
anArray[j + 1] = temp;
}
}
}

}

double averageArray(int* anyArray, int size)
{
double count = 0.0;

for (int i = 0; i < size; i++)
{
count += anyArray[i];
}

return (count / (double) size);
}
int main()
{
int* x = NULL;
int n, numbers;
std::cout<<"How many scores to enter ";
std::cin >> n;
x = new int[n];
std::cout<<"Enter scores ";
for (int i=0;i<n;i++)
{
std::cin >> x[i];

}
sortArray(x,n);
std::cout<<"Sorted array is ";
for (int i=0;i<n;i++)
{
std::cout<<x[i]<<" ";

}
std::cout<<" Avearge score is "<<averageArray(x,n);
}

=====================================

Output:

How many scores to enter

3

Enter scores

3 2 1

Sorted array is 1 2 3

Avearge score is 2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote