Question

In: Computer Science

Write a program that dynamically allocates a built-in array large enough to hold a user-defined number...

Write a program that dynamically allocates a built-in array large enough to hold a user-defined number of test scores. (Ask the user how many grades will be entered and use a dynamic array to store the numbers.) Once all the scores are entered, the array should be passed to a function that calculates the average score. The program should display the scores and average. Use pointer notation rather than array notation whenever possible. (Input Validation: Do not accept negative numbers for test scores.) Make it a class, call it something like gradeholder. You will need a destructor because you are using dynamic arrays.

please help!! this is C++ programming fundamental 2 and this is visual studio, thank you!

Solutions

Expert Solution

CODE IN JAVA-

#include <stdio.h>

#include<iostream>

using namespace std;


class gradeholder {

private: int n;
int *arr; //Dynamic array
float sum=0;

public: gradeholder()
{
cout << "Enter the number of grades";
cin >> n;
arr = new int[n];
cout << "Enter the " << n << " grades. \n";
for (int i = 0; i < n; i++)
{
cin >> *(arr + i);
if ((arr[i]) < 0) {
cout << "Do not enter negative scores.\n"; //Not accepting negative scores.
i--;
}
}
}

void avg_score()
{
for (int i = 0; i < n; i++)
sum+= *(arr + i);
}

void display()
{
cout << "The scores are : ";
for (int i = 0; i < n; i++) {

cout << *(arr + i) << " ";
}
cout << "\nThe average score is : " << sum / n;
}

~gradeholder()
{
delete [] arr; //Deleting dynamic array
}

};

int main()
{
  

gradeholder obj1;
obj1.avg_score();
obj1.display();
  
return 0;

}

CODE WINDOW-

OUTPUT WINDOW-


Related Solutions

In C++ Write a program that dynamically allocates a built-in array large enough to hold a...
In C++ Write a program that dynamically allocates a built-in array large enough to hold a user-defined number of test scores. (Ask the user how many grades will be entered and use a dynamic array to store the numbers.) Once all the scores are entered, the array should be passed to a function that calculates the average score. The program should display the scores and average. Use pointer notation rather than array notation whenever possible. (Input Validation: Do not accept...
In C++ 1. Test Scores #1 Write a program that dynamically allocates a built-in array large...
In C++ 1. Test Scores #1 Write a program that dynamically allocates a built-in array large enough to hold a user-defined number of test scores. (Ask the user how many grades will be entered and use a dynamic array to store the numbers.) Once all the scores are entered, the array should be passed to a function that calculates the average score. The program should display the scores and average. Use pointer notation rather than array notation whenever possible. (Input...
C++ Task 1 Write a program that allocates an array large enough to hold 5 student...
C++ Task 1 Write a program that allocates an array large enough to hold 5 student 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. Input Validation: Do not accept negative numbers for test scores. Task 2 Modify the program so the lowest...
C++ Task 1 Write a program that allocates an array large enough to hold 5 student...
C++ Task 1 Write a program that allocates an array large enough to hold 5 student 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. Input Validation: Do not accept negative numbers for test scores. Task 2 Modify the program so the lowest...
Task 1 Write a program that allocates an array large enough to hold 5 student test...
Task 1 Write a program that allocates an array large enough to hold 5 student 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. Input Validation: Do not accept negative numbers for test scores. Task 2 Modify the program so the lowest test...
Write a program that allows the user to search the array to find the number entered
Write a program that allows the user to search the array to find the number entered
write a MIPS program to ask user to input the number of elements of array
write a MIPS program to ask user to input the number of elements of array
Sorting Benchmarks Write a program that generates and sorts an array of a user-specified number (arraySize)...
Sorting Benchmarks Write a program that generates and sorts an array of a user-specified number (arraySize) of randomly generated numbers. To keep the values to a reasonable range by using the array size as the upper bound for the random numbers (between 1 and arraySize). Your program should call the individual functions that implement the five sorting algorithms discussed in class (see the lecture slides). Each function should keep a count of the number of comparisons/exchanges it makes. Display the...
Please write this program in C++ Write a program that           - a user-defined class Cuboid...
Please write this program in C++ Write a program that           - a user-defined class Cuboid which has the following elements:                    - default constructor (has no parameters)                    - constructor that has 3 parameters (height, length, width)                    - data members                              - height, length, width                    - member functions                              - to set the value of each of the data members - 3 functions                              - to get the value of each of the data members - 3...
Write a function that dynamically allocates references to other arrays. The goal is to end up...
Write a function that dynamically allocates references to other arrays. The goal is to end up with a square 2D array who's value increment with each index increment so that the values placed in first array start at zero and end at 9, and the values placed in the last array start at 90 and end at 99.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT