Question

in c++ please Assignment Instructions: MAIN FUNCTION: Ask the user how many students were surveyed.   Call...

in c++ please

Assignment Instructions:

MAIN FUNCTION:

  1. Ask the user how many students were surveyed.  
  2. Call a function called makeArray to define an array of integers with the number of elements equal to the number of students surveyed.
  3. Call a function called getStudentData to allow the user to enter the number of hours each student spent watching Netflix into the array.
  4. Call a function called getAverage to calculate and display the average of the hours entered.
  5. Call a function called selectionSort to sort the hours in ascending order.  This function is provided for you.
  6. Call a function called printArray to print out the hours in the array.
  7. Print out the Average

makeArray Function

Define an array of integers with the number of elements equal to the number of students surveyed. The function will accept as arguments the following:  An integer that indicates the number of elements in the array.

The array should be dynamically allocated.  
Use pointer notation instead of array notation in this function.




getStudentData Function

Allow the user to enter the number of hours each student watched Netflix into the array. The function will accept as arguments the following:

  1. An array of integers
  2. An integer that indicates the number of elements in the array.

Input Validation:  Do not accept negative numbers for input.  
Use pointer notation instead of array notation in this function.

printArray Function

This function should print out the text “Number of hours each student watched Netflix in ascending order: “.  Then, the function should print out each element in the array with a space between each element.  The function will accept as arguments the following:

  1. An array of integers
  2. An integer that indicates the number of elements in the array.

Use pointer notation instead of array notation in this function.

getAverage Function

The average of a set of values is calculated by adding all the values and then dividing the sum by the number of values in the set.  Write a function that accepts as arguments the following:

  1. An array of integers
  2. An integer that indicates the number of elements in the array.

The function should determine the average of the array.  The average is the value the function should return.  
Use pointer notation instead of array notation in this function.

selectionSort Function:

/**************************************************

* Function selectionSort                         *

* This function performs the selection sort      *

* algorithm on array, sorting it into ascending  *

* order. The parameter size holds the number of  *

* elements in the array.                         *

**************************************************/

void selectionSort(int *array, int size)

{

   int startScan, minIndex, minValue;

   for (startScan = 0; startScan < (size - 1); startScan++)

   {

      minIndex = startScan;

      minValue = *(array+startScan);

      for(int index = startScan + 1; index < size; index++)

      {

         if (*(array+index) < minValue)

         {

            minValue = *(array+index);

            minIndex = index;

         }

      }

      *(array+minIndex) = *(array+startScan);

      *(array+startScan) = minValue;

            }

}

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

#include<stdio.h>

main()

{

int n=0;
cout<<"Enter the number of students:";

cin>>size;

makeArray(&size);

getStudentData(&array,&size);

printarray(&array,&size);

getaverage(&array,&size);

cout<<"The average number of hours spent are:"<<avrg;

}

void getStudentData(int *array,int *size)

{

int i=0;

for(i=0;i<size;i++)

{
count<<"enter the number of hours for student"<<i;

cin>>*array[i];

if(*array[i] <0)

{
cout<<"no negative inputs allowed";

cin>>*array[i];

}

i++;

}
}
void makeArray(int *size)

{

int *arr = (int *)malloc(*size * sizeof(int));

}

int printarray(int *array,int*size)

{

int i=0;

selectionSort(&array,size);

cout<<"Number of hours each student watched Netflix in ascending order: ";

for(i=0;i<size;i++)

{

cout<<array[i];

i++;

}
void selectionSort(int *array, int size)

{

   int startScan, minIndex, minValue;

   for (startScan = 0; startScan < (size - 1); startScan++)

   {

      minIndex = startScan;

      minValue = *(array+startScan);

      for(int index = startScan + 1; index < size; index++)

      {

         if (*(array+index) < minValue)

         {

            minValue = *(array+index);

            minIndex = index;

         }

      }

      *(array+minIndex) = *(array+startScan);

      *(array+startScan) = minValue;

            }

}

int getAverage(int *array,int*size)

{

int sum=0,avrg=0,i=0;

for(i=0;i<size;i++)

{

sum=sum+*array[i];

i++;

}

avrg=sum/size;

return(avrg);

}

Add a comment
Know the answer?
Add Answer to:
in c++ please Assignment Instructions: MAIN FUNCTION: Ask the user how many students were surveyed.   Call...
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
  • 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,...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question: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...

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

  • please use c ++ language and write the comment too. thanks Pointer Arithmetic Write a function...

    please use c ++ language and write the comment too. thanks Pointer Arithmetic Write a function that passes an array address to a function as a pointer. Using pointer arithmetic, the function determines the average, high, and low value of the array. Your function should have this header: void pointerArithmetic(int *array, int size, double &average, int &high, int &low) Parameter size is the number of elements in array. You may not use the subscript notation [] inside your function –...

  • Write program in C. Please ask the user to determine how many numbers to enter, and...

    Write program in C. Please ask the user to determine how many numbers to enter, and then find and display the largest one with two digits. Please call the following two functions in your main functions. void input_numbers(float *data, int num); void find_largest(float *data, int num); Note: In this assignment, please save the entered numbers using pointer, pass the pointer as the arguments. Depending upon the number of elements, the required size is allocated which prevents the wastage of memory....

  • Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int...

    Programming language C Please go through this carefully. Needs function void add(int *a1, int n, int *a2) Write a program addition.c that reads in an array (a1) of numbers, and creates a new array (a2) of numbers such that the first and last numbers of a1 are added and stored as the first number, the second and second-to-last numbers are added and stored as the second number, and so on. You need to check for even and odd length of...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • in C++ and also each function has its own main function so please do the main...

    in C++ and also each function has its own main function so please do the main function as well. Previously when i asked the question the person only did the function and didn't do the main function so please help me do it. 1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...

  • 17.9 Worksheet 7 (C++) Follow the instructions commented into the given template. int main() { int...

    17.9 Worksheet 7 (C++) Follow the instructions commented into the given template. int main() { int array1[20] = {3, 18, 1, 25, 4, 7, 30, 9, 80, 16, 17}; int numElements = 11; cout << "Part 1" << endl; // Part 1 // Enter the statement to print the numbers in index 4 and index 9 // put a space in between the two numbers    cout << endl; // Enter the statement to print the numbers 3 and 80...

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

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