Question

Write a program that dynamically allocates an integer array of size of 20 to hold a user-defined number of test scores. Once

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

//C++ code

// this code in c++
#include<iostream>
using namespace std;
void calculate(int* arr,int s, int &min, int &max, double &avg);
int search(int* arr,int s, int num);
//Function prototype
int main()
{
   cout << "Enter the size of array: ";
   int size;
   cin >> size;
   int* a = new int[size];
   for (int i = 0; i < size; i++)
   {
       cout << "Enter number " << (i + 1) << ": ";
       cin >> a[i];

   }
   int min=0, max=0;
   double avg=0;
   calculate(a, size, min, max, avg);
   cout << "Max = " << max<<endl;
   cout << "Min = " << min << endl;
   cout << "Avg = " << avg << endl;
   cout << "Number to be searched: ";
   int num;
   cin >> num;
   int index = search(a, size, num);
   if (index < 0)
       cout << num << " not found..." << endl;
   else
       cout << num << " is found at " << index << endl;
   //pause
   system("pause");
}
void calculate(int* arr,int s, int &min, int &max, double &avg)
{
  
   max = *arr;
   min = *arr;
   int sum = 0;
   for (int i = 0; i < s; i++)
   {
       if (min > arr[i])
           min = arr[i];
       if (max < arr[i])
           max = arr[i];
       sum += arr[i];
   }
   avg = (double)sum / s;

  
  
}
int search(int* arr,int s, int num)
{
  
   for (int i = 0; i < s; i++)

   {
       if (arr[i] == num)
           return i;
   }
   return -1;
}

//Output

Enter the size of array: 5 Enter number 1: 45 Enter number 2: 23 Enter number 3: 67 Enter number 4: 43 Enter number 5: 12 (Мa

//If you need any help regarding this solution..... please leave a comment.......... thanks

Add a comment
Know the answer?
Add Answer to:
Write a program that dynamically allocates an integer array of size of 20 to hold a...
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 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...

  • 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 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...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • 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...

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • write program in c # to do the following : Insert 10 student scores and store...

    write program in c # to do the following : Insert 10 student scores and store them in an array Create a function that prints array elements Create a function that returns the highest mark Create a function that calculates the average score Create a function that calculates the pass rate, knowing that the pass mark is 60

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
ADVERTISEMENT