Question

C++ programming language POINTERS Write a program that dynamically allocates an array, on the Heap, large...

C++ programming language

POINTERS

Write a program that dynamically allocates an array, on the Heap, large enough to hold 200 test scores between 55 and 99 -- using a Random Number generator to populate the array. Then do the following:

1) Sort scores in ascending order.
2) List your scores in rows of ten(10) values.
3) Calculate the Mean for the distribution.
4) Calculate the Variance for the distribution.
5) Calculate the Median for the distribution.
6) Calculate the Mode for the distribution.
7) Determine the number of scores in each of
the discrete intervals specified below:

55-59|**
60-64|***
65-69|*****
70-74|******
75-79|***********
80-84|****
85-89|***
90-94|**
95-99|*
|----|----|----|----|----|----|----|----|
0 5 10 15 20 25 30 3 5 40

7a) List the number of scores in each interval.

7b) Display your Histogram Chart distribution to the Console screen.

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

Code with sample output

#include <iostream>
#include <stdlib.h>
using namespace std;

int main ()
{
int i,n,j,temp,count=1,highestCount=1, mode,num;
float sum =0,mean,count1=0,count2=0,count3=0,count4=0,count5=0,count6=0,count7=0,count8=0,count9=0;
int * array1;
//hold 200 elements
array1= new (nothrow) int[200];
n=200;
if (array1== NULL)
cout << "Error: memory could not be allocated";
else
{
for (i=0; i<n; i++)
{
//random number generator
array1[i]=rand() % (99 - 55) + 55;
}
//sort
for (i = 0; i < n-1; i++)   
  
// Last i elements are already in place
for (j = 0; j < n-1-i; j++)
if (array1[j] > array1[j+1])
{
temp = array1[j];
array1[j] = array1[j+1];
array1[j+1] = temp;
}
//displau in rows of 10 values   
for (i=0; i<n; i++){
cout << array1[i] << " ";
if(i%10==9)
cout<<"\n";
}
//mean
for (i=0; i<n; i++)
sum+=array1[i];
mean = sum/n;
cout<<"\nMean ="<<mean;
//mode
num = array1[0];
for (i=1; i<n; i++)
{
if (array1[i] == num)
{ // count occurrences of the current number
count++;
}
else
{ // encountered different number check if this count is higher than previous count if yes make that mode
if (highestCount< count)
{
highestCount = count;
mode = num;
}
count = 1; // reset count for the new number
num = array1[i];
}
}

cout << "\nMode of the array is: " << mode<<"\n";
for (i=0; i<n; i++)
{ if(array1[i]<=59)
count1++;
else if(array1[i]<=64)
count2++;
else if(array1[i]<=69)
count3++;
else if(array1[i]<=74)
count4++;
else if(array1[i]<=79)
count5++;
else if(array1[i]<=84)
count6++;
else if(array1[i]<=89)
count7++;
else if(array1[i]<=94)
count8++;
else
count9++;

}
cout<<"\n Count 55-59 : "<<count1;
cout<<"\n Count 60-64 : "<<count2;
cout<<"\n Count 65-69 : "<<count3;
cout<<"\n Count 70-74 : "<<count4;
cout<<"\n Count 75-79 : "<<count5;
cout<<"\n Count 80-84 : "<<count6;
cout<<"\n Count 85-89 : "<<count7;
cout<<"\n Count 90-94 : "<<count8;
cout<<"\n Count 95-99 : "<<count9;
//clear array which is allocated dynamically
delete[] array1;
}
return 0;
}

sample output

Add a comment
Know the answer?
Add Answer to:
C++ programming language POINTERS Write a program that dynamically allocates an array, on the Heap, large...
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 C++ program that dynamically allocates an array large enough to hold a user-defined number...

    Write a C++ 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. Input Validation: Do not accept negative numbers for...

  • read it carefully C++ Question: Write a program that dynamically allocates an array large enough to...

    read it carefully C++ Question: 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. Input Validation: Do not...

  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • Write a program that dynamically allocates an array in the freestore large enough to hold a...

    Write a program that dynamically allocates an array in the freestore large enough to hold a user defined number of test scores as doubles. Once all the scores are entered, the array should be passed to a function that finds the highest score. Another function the array should be passed to a function that finds the lowest score. Another function should be called that calculates the average score. The program should show the highest, lowest and average scores. Must use...

  • Write a program that dynamically allocates an integer array of size of 20 to hold a...

    Write a program that dynamically allocates an integer array of size of 20 to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to • a function that calculates the average score, the minimal score, and the maximal score in the array, and returns these scores to the main function (hint: use pass by reference, I gave an example in the class) • a function that searches a specific number. The...

  • C Language Write the code that dynamically allocates an array of struct objects based on a...

    C Language Write the code that dynamically allocates an array of struct objects based on a size entered through the command line arguments, You will use the following struct and enum. typedef enum Color { RED, GREEN, BLUE } Color; typedef struct MyStruct { int value; Color color; } MyStruct; Write the code to do the following: a. Check for one additional command line argument. Only proceed to the rest of the program if it exists and that the value...

  • C++ programming language Write a program that asks the user for a file name. The file...

    C++ programming language Write a program that asks the user for a file name. The file contains a series of scores(integers), each written on a separate line. The program should read the contents of the file into an array and then display the following content: 1) The scores in rows of 10 scores and in sorted in descending order. 2) The lowest score in the array 3) The highest score in the array 4) The total number of scores in...

  • C++ Programming By using Binary heap Develop a CPP program to test is an array conforms...

    C++ Programming By using Binary heap Develop a CPP program to test is an array conforms heap ordered binary tree. This program read data from cin (console) and gives an error if the last item entered violates the heap condition. Use will enter at most 7 numbers. Example runs and comments (after // ) are below. Your program does not print any comments. An output similar to Exp-3 and Exp-4 is expected. Exp-1: Enter a number: 65 // this is...

  • Write a program that uses pointer notation to dynamically allocate parallel array(s) large enough to hold...

    Write a program that uses pointer notation to dynamically allocate parallel array(s) large enough to hold a user-defined number of test scores and student names, using parallel arrays. After student names and corresponding scores are entered, the array(s) should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score for the group (do not include the lowest score in the calculation of average grade). The program should display the...

  • Language C++ Instructions Develop a CPP program to test is an array conforms heap ordered binary...

    Language C++ Instructions Develop a CPP program to test is an array conforms heap ordered binary tree. This program read data from cin (console) and gives an error if the last item entered violates the heap condition. Use will enter at most 7 numbers. Example runs and comments (after //) are below. Your program does not print any comments. An output similar to Exp-3 and Exp-4 is expected. Exp-1: Enter a number: 65 Enter a number: 56 // this is...

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