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
Reil [10]
2 years ago
7

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. 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.
Computers and Technology
1 answer:
Anastasy [175]2 years ago
6 0

Answer:

// Program written in C++

// Comments are used to explain some lines

#include <iostream>

#include <iomanip>

using namespace std;

// Functions

void getData(double *, int);

void selectionSort(double *, int);

double getAverage(double *, int);

void displayData(double *, int, double);

int main() //Main Method

{

double *ToTest, // To dynamically allocate an array

Average; // To hold the average of the scores

int Scores; // To hold number of scores

// Get number of scores

cout << "Number of average to find? ";

cin >> Scores;

// Allocate an array to number of scores

ToTest = new double[Scores];

getData(ToTest, Scores);

selectionSort(ToTest, Scores);

Average = getAverage(ToTest, Scores);

printData(ToTest, Scores, Average);

return 0;

}

//Get Data

void getData(double *ToTest, int Scores)

{

cout << "Enter each scores.\n";

for (int i = 0; i < Scores; i++)

{

do

{

cout << "Score #" << (i + 1) << ": ";

cin >> *(ToTest + i);

if (*(ToTest + i) < 0)

{

cout << "Scores must be greater than 0.\n"

<< "Re-enter ";

}

} while (*(Test + i) < 0);

}

}

// Selection Sort

void selectionSort(double *ToTest, int Scores)

{

int startscan, minIndex;

double minValue;

for (startscan = 0; startscan < (Scores - 1); startscan++)

{

minIndex = startscan;

minValue = *(ToTest + startscan);

for (int i = startscan + 1; i < Scores; i++)

{

if (*(ToTest + i) < minValue)

{

minValue = *(Test + i);

minIndex = i;

}

}

*(ToTest + minIndex) = *(ToTest + startscan);

*(ToTest + startscan) = minValue;

}

}

// Calculate Average

double getAverage(double *ToTest, int Scores)

{

double Total;

for (int i = 0; i < Scores; i++)

{

Total += *(ToTest + i);

}

return Total / Scores;

}

// Print Data

void printData(double *ToTest, int Scores, double Avg)

{

cout << "\n Test scores\n";

cout << "Number of scores: " << Scores << endl;

cout << "Scores in ascending-order:\n";

for (int i = 0; i < Scores; i++)

{

cout << "#" << (i + 1) << ": " << *(ToTest + i) << endl;

}

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

cout << "Average score: " << Avg << endl;

}

You might be interested in
The following SQL statement uses a(n) _____. SELECT P_CODE, P_DESCRIPT, P_PRICE, V_NAME FROM PRODUCT, VENDOR WHERE PRODUCT.V_COD
Trava [24]

Answer:

The answer is c. “old-style” join.

Explanation:

SELECT P_CODE, P_DESCRIPT, P_PRICE, V_NAME

FROM PRODUCT, VENDOR

WHERE PRODUCT.V_CODE = VENDOR.V_CODE;

The SELECT clause represents all the columns to be displayed.

The FROM clause represents the tables which are used to extract the columns.

The WHERE clause shows the common column that exists in both the tables. This represents the old-style join when JOIN keyword was not used.

The tables are joined in two ways.

1. Using JOIN keyword

The syntax for this is given as

SELECT column1, column2

FROM table1 JOIN table2

ON table1.column3 = table2.column3;

This returns all rows from two tables having the same value of common column.

Two tables are taken at a time when JOIN keyword is used.

If more tables are to be used, they are mentioned as follows.

SELECT column1, column2

FROM table1 JOIN table2

ON table1.column3 = table2.column3

JOIN table3

ON table3.column4 = table1.column4

( ON table3.column5 = table2.column5 )  

The part in italics shows that the third table can either share the same column with table1 or table2.

The given query can be re-written using JOIN as shown.

SELECT P_CODE, P_DESCRIPT, P_PRICE, V_NAME

FROM PRODUCT JOIN VENDOR

ON PRODUCT.V_CODE = VENDOR.V_CODE;

2. Equating common column in WHERE clause

SELECT column1, column2

FROM table1, table2

WHERE table1.column3 = table2.column3;

This returns all rows from two tables having the same value of the common column.

Here, no keyword is used except the general syntax of the query. ON keyword as shown in the above example is replaced with WHERE.

Tables to be used are mentioned in FROM clause separated by commas.

Tables are joined based on the same column having same values.

Multiple tables can be joined using this style as follows.

SELECT column1, column2

FROM table1, table2, table3, table4

WHERE table1.column3 = table2.column3

AND table3.column5=table1.column5

AND table3.column4 = table2.column4;

5 0
3 years ago
Write a function transpose(matrix) that returns the transpose of the input matrix, which is represented as a list of lists. Reca
mariarad [96]

Answer:you eat

Explanation:yea

4 0
2 years ago
What would be the result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna']
denis23 [38]

Answer:

This code will no get executed properly.It will give keyerror Brianna.

Explanation:

In this dictionary we defined in the code the there is no key Brianna hence there is no corresponding value to Brianna.So assigning ages['Brianna] to value will obviously give error since there exits no key with this name.So the code will give error.

7 0
3 years ago
In most operating systems what is running application called?
Likurg_2 [28]

Answer:

I believe it is just a task. Since there exists(on windows) the Task Manager application, where you can stop any running <em>task, </em>I think that they are called tasks

Explanation:

5 0
3 years ago
The femur is _____.<br><br> part of a cell<br> the thigh bone<br> a hair follicle<br> a muscle
MA_775_DIABLO [31]

Its the Thigh Bone. Hope this helps. =^-^=

7 0
2 years ago
Other questions:
  • Which of these is an on-site metric for social media marketing?
    13·1 answer
  • How to download music to your mp3 player off computer
    6·1 answer
  • a ____ consists of wires connecting the cpu and other parts of the computer. The _____ transfers data between CPU and memory uni
    6·1 answer
  • The performance of a client-server system is strongly influenced by two major network characteristics: the bandwidth of the netw
    6·1 answer
  • Please help ASAP, will mark brainliest!
    13·1 answer
  • Order the steps to use a logical argument as a rule type.
    15·2 answers
  • The create_python_script function creates a new python script in the current working directory, adds the line of comments to it
    6·1 answer
  • What kind of block do you need to check whether a sprite is touching another sprite?
    10·1 answer
  • 2. How does the internet give us the ability to communicate?
    15·1 answer
  • In the following shell scripting extract, the initial values of variables s, c and p are 0, 1, 1 respectively. What will be the
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!