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
svet-max [94.6K]
2 years ago
7

Design a class that has an array of floating-point numbers. The constructor should accept an integer argument and dynamically al

locate the array to hold that many numbers. The destructor should free the memory held by the array. In addition, there should be member functions to perform the following operations: • Store a number in any element of the array • Retrieve a number from any element of the array • Return the highest value stored in the array • Return the lowest value stored in the array • Return the average of all the numbers stored in the array Demonstrate the class in a main program. All methods should be implemented and called.
Computers and Technology
1 answer:
attashe74 [19]2 years ago
6 0

Answer:

See explaination for the code

Explanation:

Here is the code

class NumberArray

{

private:

float *aptr; // Pointer to the array

int arraySize; // Holds the array size

float max,min,avg;

public:

NumberArray(int); // Constructor

~NumberArray(); // Destructor

int size() const // Returns the array size

{ return arraySize; }

void storeNumber(float num,int ele);

float retrieveNumber(int ele);

float getHighest();

float getLowest();

float getAverage();

};

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

// Constructor for IntArray class. Sets the size of the *

// array and allocates memory for it. *

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

NumberArray::NumberArray(int s)

{

arraySize = s;

aptr = new float [s];

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

*(aptr + count) = 0;

}

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

// Destructor for IntArray class. *

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

NumberArray::~NumberArray()

{

if (arraySize > 0)

delete [] aptr;

}

void NumberArray::storeNumber(float num,int ele)

{

if(ele<arraySize)

*(aptr+ele)=num;

}

float NumberArray::retrieveNumber(int ele)

{

return *(aptr+ele);

}

float NumberArray::getHighest()

{

float high=*(aptr+0);

for(int i=1;i<arraySize;i++)

if(high<*(aptr+i))

high=*(aptr+i);

return high;

}

float NumberArray::getLowest()

{

float low=*(aptr+0);

for(int i=1;i<arraySize;i++)

if(low>*(aptr+i))

low=*(aptr+i);

return low;

}

float NumberArray:: getAverage()

{

float ag=0;

for(int i=1;i<arraySize;i++)

ag+=*(aptr+i);

ag=ag/arraySize;

return ag;

}

//Header file section

#include <iostream>

using namespace std;

int main()

{

const int SIZE = 10; // Array size

// Define an IntArray with 10 elements.

NumberArray table(SIZE);

//function call to store values

table.storeNumber(1,0);

table.storeNumber(3,1);

table.storeNumber(7,2);

table.storeNumber(2,3);

//display values

cout<<"Highest value:"<<table.getHighest()<<endl;

cout<<"Lowest Value:"<<table.getLowest()<<endl;

cout<<"Average:"<<table.getAverage()<<endl;

///pause system for a while

system("pause");

return 0;

}

You might be interested in
18 Select the correct answer.
Elden [556K]

A string for sure, so answer B.

6 0
2 years ago
This week you will learn about basic code structure. The term structure, as it relates to programming, refers to the decisions y
GenaCL600 [577]
Instead of having to write multiple pieces of code for different outcomes, you can use an elseif statement and make your code easier to read and easier to understand.
8 0
3 years ago
Film’s importance in today’s economy?
RSB [31]

Answer:

When a movie or television show shoots on location, it brings jobs, revenue, and related infrastructure development, providing an immediate boost to the local economy. ... The film and television industry supports 2.5 million jobs, pays out $188 billion in total wages, and comprises over 93,000 businesses.

Explanation:

<em>The film industry is estimated to be worth of billions of dollars. Various kinds of people are employed to work as actors, actresses, cameramen, producers, directors, managers and company representatives. It also provides secondary jobs for persons as props, costume designers, caterers, sound, lighting and electronics.</em>

8 0
3 years ago
Who invented the ENIAC? More than one answer may apply.
andriy [413]

Answer:John Mauchly and Presper Eckert

Explanation:

3 0
2 years ago
Which is NOT an example of a "Serious Game"?
Allisa [31]

Answer:

My answer to the question is Sport Activity

4 0
3 years ago
Other questions:
  • What can a folder on a computer contain?
    13·2 answers
  • With a _____ network connection, the computers and other devices on the network are physically connected via cabling to the netw
    10·2 answers
  • 1. What is the difference between a learner’s license and an operator’s license?
    10·1 answer
  • Which of the following is a malicious program that can replicate and spread from computer to computer?
    13·2 answers
  • Betrand Meyer developed the ______ programming language which is not type-safe because it violates the law of contravariance.
    9·1 answer
  • Write a program to read a list of exam scores given as integer percentages in the range O to 100. Display the total number of gr
    11·1 answer
  • Gabriel's sister called him about a message that suddenly appeared on her screen that says her software license has expired and
    11·1 answer
  • Implement a metho d to nd the k-th largest element in an array of size N using a minimum priority queue (MinPQ). Assume that the
    8·1 answer
  • Use the drop-down menus to complete the statements about changing mail options in Outlook.
    10·1 answer
  • How do you get off of the comments after you look at them wit out going all the way off the app?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!