Question
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
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please do rate it if you find it helpful :)

#include<iostream>
using namespace std;
int n; //global variable for number of students
float *mks; //pointer used for array of marks
void sort(float marks[]) //function to sort the arrays
{
   float temp;
   mks=marks;
   for(int i=0;i<n;i++)
   {
       for(int j=i+1;j<n;j++)
       {
           if(*(mks+i)>*(mks+j))
           {
               temp=*(mks+i);
               *(mks+i)=*(mks+j);
               *(mks+j)=temp;
           }  
       }
   }
}
float average(float marks[]) //function to calculate the average
{
   float avg=0.0;
   mks=marks;
   for(int i=0;i<n;i++)
   {
       avg+=*(mks+i);
   }
   avg=avg/n;
   return avg;
}
int main()
{
   cout<<"Enter the number of students: ";
   cin>>n;
   float *marks=new float[n]; //array of marks of students
   mks=marks;
   cout<<"\nEnter the marks of students:-\n\n";
   for(int i=0;i<n;i++)
   {
       reenter:
       cout<<"Enter marks of student"<<i+1<<": ";
       cin>>*(mks+i);
       cout<<endl;
       if(*(mks+i)<0)
       {
           cout<<"Please enter valid marks!\n\n";
           *(mks+i)=0;
           goto reenter;
       }
   }
   sort(marks);
   cout<<"\n\n Sorted Marks\n"; //for formatted output
   cout<<" -------------\n\n"; //for formatted output
   for(int i=0;i<n;i++)
   {
       cout<<"\t "<<*(mks+i)<<endl;
   }
   cout<<"\n\nAverage Marks are: "<<average(marks);
   return 0;
}

output:-

DELOPyy used Enter the number of students: 10 Enter the marks of students:- Enter marks of studenti: 12 Enter marks of studenEnter marks of students: 19.5 Enter marks of student9: 17 Enter marks of student10: 8 Sorted Marks 15.5 17 19.5 20 Average Ma

DELOPyy used Enter the number of students: 10 Enter the marks of students:- Enter marks of studenti: 12 Enter marks of student2: 15.5 Enter marks of student3: -20. Please enter valid marks! Enter marks of student3: 20 Enter marks of student4: 13 Enter marks of student5: 3 Enter marks of student6: 7 Enter marks of student7: 5 Enter marks of students: 19.5 Enter marks of studento: 17 Enter marks of student10: 8 cout<<"\n\nAverage Marks are: "<<average return

Enter marks of students: 19.5 Enter marks of student9: 17 Enter marks of student10: 8 Sorted Marks 15.5 17 19.5 20 Average Marks are: 12 Process exited after 27.38 seconds with return value o Press any key to continue. 60 61 62 cout<<"\n\nAverage Marks are: "<<average return

Add a comment
Know the answer?
Add Answer to:
read it carefully C++ Question: Write a program that dynamically allocates an array large enough to...
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 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...

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

  • c++ Instructions Overview In this programming challenge you will create a program to handle student test...

    c++ Instructions Overview In this programming challenge you will create a program to handle student test scores.  You will have three tasks to complete in this challenge. Instructions 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...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

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

  • 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 performs several operations on an array of positive ints. The program...

    - Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...

  • I need help with this c++ question please thank you ltls. The program should urt valte....

    I need help with this c++ question please thank you ltls. The program should urt valte. 11. Lowest Score Drop Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions: void getscore() should ask the user for a test score, store it in a reference param- eter variable, and validate it. This function should be called by main once for each of...

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