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]
3 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]3 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
Which type of software is primarily used to organize a collection of information for easy access?
weeeeeb [17]
Database - you could also use a spreadsheet but you can't ask questions that you can with a database
4 0
3 years ago
In the ____ category, the cloud service provider offers the capability to build and deploy consumer-created applications using t
Nikolay [14]

Answer:

Platform as a Service (PaaS)

Explanation:

In cloud computing, PaaS called platform as a service refers to the provision of a computing platform for developers to create their own custom application. Other two categories of cloud computing are IaaS (Infrastructure as a service) and SaaS (Software as a Service). In the PaaS the servers, cloud storage and network  are automatically handled by the platform only the software and application code are to be managed.

7 0
3 years ago
How to delay sending an email in office 365
expeople1 [14]
You can’t it’s impossible unless your a hackers
3 0
3 years ago
How does confidentiality protect people and their online activity?
zlopas [31]
The answer is C Explanation: process of elimination
5 0
3 years ago
Which of the following memories would NOT be an example of long-term memory? a. acknowledging that you just sat down b. remember
Sati [7]

Answer: the following memories would NOT be an example of long-term memory are the letter  a) and c)

<em> -acknowledging that you just sat down </em>

-recollecting what you had for breakfast an hour ago

Explanation:

as the Long-term memory, also called inactive memory or secondary memory, is a type of memory that stores memories for a period of time greater than five o six months

6 0
3 years ago
Other questions:
  • To employ an access key, press and hold down the ____ key as you tap the access key.
    14·1 answer
  • Using Amdahl’s Law, calculate the speedup gain of an application that has a 60 percent parallel component for (a) two processing
    11·1 answer
  • Write a program that implements the FIFO and LRU page-replacement algorithms learned in class. First, generate a random page ref
    9·1 answer
  • The integrity of a program's output is only as good as the integrity of its input. For this reason, the program should discard i
    6·1 answer
  • An example of hardware is a(n) _____.
    9·2 answers
  • Please please help I don’t understand this
    7·2 answers
  • A(n) ____ tells the compiler or interpreter that the character that follows it has a special purpose.
    14·1 answer
  • You are the system administrator for Precision Accounting Services, which employs 20 accountants and 25 accounting assistants. T
    13·1 answer
  • What is the role of the computer in banking system?
    10·1 answer
  • Clara works behind a computer all day. She gets a lot of headaches, and her eyes have been hurting her lately. Her doctor diagno
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!