1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Colt1911 [192]
4 years ago
12

Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scor

es are entered, the array should be passed to a function that sorts them in ascending order (use any sort methods--bubble or selection--from Chapter 8). Another function should be called the calculates the average score and drop the lower test score. The program should display the sorted list of scores and average score. The program should display the sorted list of scores and average with appropriate headings. Use pointer notation rather than array notation whenever possible.
Engineering
1 answer:
Readme [11.4K]4 years ago
6 0

Answer:

#include <iostream>

#include <iomanip>

using namespace std;

//Function prototypes

void arrSelectSort(double *, int);

double arrAvgScore(double *, int);

int main()

{  

//Variables  definition

double *TestScores,  

total = 0.0,

average;

int numTest,

count;

//Enter the number of test scores you want to get to their average in ascending order

cout << "How many test scores do you wish to enter?";

cin >> numTest;

//Dynamically allocate an array large enough to hold that many scores

TestScores = new double[numTest];

//Get the test scores

cout << "Enter the test scores below.\n";

for (count = 0; count < numTest; count++)

{

//Display score

cout << "Test Score " << (count + 1) << ": ";

cin >> TestScores[count];

 }  

// Input validation. Only numbers between 0-100

while (numTest<0)

{

cout << "You must enter a scores that non-negative" << endl;

cout << "Please enter a non-negative interger between 0 and 100: ";

cin >> TestScores[count];

}

//Calculate the total test scores

for (count = 0; count < numTest; count++)

{

total += TestScores[count];

}

average = total / numTest;

//Dsiplay the results

cout << fixed << showpoint << setprecision(2);

cout << "The average of all the test score is " << average << endl;

//Free dynamically allocated memory

delete [] TestScores;

TestScores = 0; //make TestScores point to null

//Display the Test Scores in ascending order

cout << "The test scores, sorted in ascending order, are: \n";

system ("pause");

return 0;

}

//Ascending order selection sort

void arrSelectSort(double *arr, int size)

{

int startScan;

double minIndex;

double minElem;  

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

{

minIndex = startScan;

minElem = arr[startScan];  

}

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

{

if (arr[index] < minElem)

{

minElem = arr[index];

minIndex = index;  

}

}

void arrAvgScore (double *arr[], int size)

{

double total = 0;

int numTest;

for (int count = 0; count < numTest; count++)

{

total += numTest[count];

average = total / numTest;

}

}

}

You might be interested in
Question 2 (Multiple Choice Worth 3 points)
ololo11 [35]

Answer:

the car to the right

Explanation:

its in the name the RIGHT of way hope it helps good luck

6 0
3 years ago
(40 points) Program the following sorting algorithms: InsertionSort, MergeSort, and QuickSort. There are 9 test les uploaded for
babunello [35]

Answer:

Explanation:

MERGE SORT

#include<stdlib.h>

#include<stdio.h>

#include<string.h>

void merge(int arr[], int l, int m, int r)

{

int i, j, k;

int n1 = m - l + 1;

int n2 = r - m;

 

int L[n1], R[n2];

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

L[i] = arr[l + i];

for (j = 0; j < n2; j++)

R[j] = arr[m + 1+ j];

i = 0;

j = 0;

k = l;

while (i < n1 && j < n2)

{

if (L[i] <= R[j])

{

arr[k] = L[i];

i++;

}

else

{

arr[k] = R[j];

j++;

}

k++;

}

while (i < n1)

{

arr[k] = L[i];

i++;

k++;

}

while (j < n2)

{

arr[k] = R[j];

j++;

k++;

}

}

void mergeSort(int arr[], int l, int r)

{

if (l < r)

{

int m = l+(r-l)/2;

mergeSort(arr, l, m);

mergeSort(arr, m+1, r);

merge(arr, l, m, r);

}

}

void printArray(int A[], int size)

{

int i;

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

printf("%d ", A[i]);

printf("\n");

}

int main()

{

int arr[1000] = {0};

int arr_size =0;

int data;

char file1[20];

strcpy(file1,"data.txt");

FILE *fp;

fp = fopen(file1,"r+");

if (fp == NULL) // if file not opened return error

{

perror("Unable to open file");

return -1;

}

else

{

fscanf (fp, "%d", &data);    

arr[arr_size]=data;

arr_size++;

while (!feof (fp))

{  

fscanf (fp, "%d", &data);  

arr[arr_size]=data;

arr_size++;    

}

}

printf("Given array is \n");

printArray(arr, arr_size);

mergeSort(arr, 0, arr_size - 1);

printf("\nSorted array Using MERGE SORT is \n");

printArray(arr, arr_size);

return 0;

}

3 0
3 years ago
How many grams is one molecule of calcium oxide?
MakcuM [25]

Answer:

Molar mass -56.0774 g/mol

There is a way to calculate this

atomic number for calcium is 20

atomic number for oxygen is 8

The molar mass for calcium is 40

The molar mass for oxygen is 16

CALCIUM OXIDE

40. +. 16

=56g/mol

1 molecule = 1×56=56g/mol

2 molecules=2×56 =112g/mol

5 0
2 years ago
What do the cells and tissues of the endocrine system release to help maintain homeostasis in the body?
kaheart [24]
Glands. hope this helps!!
4 0
3 years ago
There are little to no benefits to supplementary field identification programs
VashaNatasha [74]

Answer:

True, supplementary field identification programs tend to limit the use of routine programs that target service delivery using routine systems.

Explanation:

When supplementary field identification programs are applied in a study, they have damaging effects to other systems and programs already in progress targeting certain/similar variables in a study group.Such programs are initiated to boost the already existing systems of programs that are in continuous application( routine basis). As a supplement , we expect more positive results in the rates per the variables included in a study.However, results has proved the opposite.For example, supplementary immunization activities applied in programs targeting demographic and health systems services reveled that such programs reduce the probability of receiving the services provided by other routine health systems conducting continuous vaccination programs to the target groups.

4 0
4 years ago
Other questions:
  • 3. Write down the total thermal resistance for a double-pipe heat exchanger. Show how to convert from total resistance to an ove
    12·2 answers
  • Consider a variant of the thermostat of example 3.5. In this variant, there is only one temperature threshold, and to avoid chat
    6·2 answers
  • The creation of designer drugs is outpacing the ability of society to enact laws to prohibit them. Many of these substances have
    11·1 answer
  • Give two advantages of a four-high rolling mill opposed to a two-high rolling mill for the same output diameter.
    9·1 answer
  • When you receive a vertical promotion, you are more likely to _______ than when you receive a horizontal promotion. a. Deal with
    9·1 answer
  • State 3 advantages and 3 disadvantages of unit rate contract​
    10·1 answer
  • If an employer agrees to give you constructive criticism of your interview performance, you need to listen carefully and take no
    8·2 answers
  • What are the three primary factors on which encryption is based?.
    8·1 answer
  • Rear axles are usually lubricated by the same gear oil that lubricates the differential. True or false
    12·1 answer
  • error: request for member 'setcursor' in 'oled', which is of non-class type 'adafruit ssd1306(int, int)' oled.setcursor(x, accel
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!