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
tatiyna
3 years ago
5

Number Array Class

Computers and Technology
1 answer:
UNO [17]3 years ago
4 0

Answer:

Here is the Array class named Number:

#include <iostream>

#include <iomanip>

using namespace std;

class Number {

private:                            

   int size;                      

   float *ptr;                

   float num;                

   

public:                                          

   Number(){

       cout<<"Enter size of array: ";

        cin>>size;                            

   ptr = new float[size];  

   cout<<"Enter elements"<<endl;

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

       cin>>ptr[i];     }     }

   

   void getNumbers(){

        cout << "{ ";                    

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

       cout <<ptr[i] <<setprecision(2)<< " ";             }

   cout << "}";            }

   

   Number(int s){

       ptr = new float[s];          

       size = s;      

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

       cout << "Enter elements : ";    

       cin >> num;                          

       ptr[i] = num;         }  }

   

   ~Number(){

        delete [] ptr;    }

   void storeNumber(int input, float num){

        while (input < 0 || input > size-1)  {

       cout << "array size exceeded! Enter an element again " << endl;    

       cin >> input;    

       if (input >= 0 && input < size)  {

           ptr[input] = num;  

           break;       }   }

     if (input >= 0 && input < size)  {

       ptr[input] = num;   }  }

   

   void retrieveNumber(int position){

        while (position < 0 || position > size-1)  {

       cout << "array size exceeded! Enter an element again " << endl;    

       cin >> position;      

        if (position >= 0 && position < size)  {

           cout << "The number at "<<position<<"is: " << ptr[position];  

           break;           }     }      

   if (position >= 0 && position < size)     {

      cout << "The number at "<<position<<" is: " << ptr[position];     }   }    

 

   float HighestNumber(){

       float highest = ptr[0];      

   for (int i = 1; i < size; i++)     {

       if (ptr[i] > highest)         {

           highest = ptr[i];              }     }      

   return highest;      }

   

   float LowestNumber(){

       float lowest = ptr[0];      

   for (int i = 1; i < size; i++)     {

       if (ptr[i] < lowest)         {

           lowest = ptr[i];              }     }      

   return lowest;      }

   

   float AverageNumber(){

       float avg = 0.0;        

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

       avg += ptr[i];         }      

   return avg/size;     }    

};

int main() {

   Number array;    

   array.getNumbers();    

   cout << endl;    

   int pos;        

   float no;    

   cout << "Choose an element to replace: ";  

   cin >> pos;    

   cout << "What number do you want to replace element with?" << endl;  

   cin >> no;    

   array.storeNumber(pos, no);

   array.getNumbers();  

   cout << endl;    

   int pos1;  

   cout << "Enter an element to retrieve the number: ";  

   cin >> pos1;    

   cout << endl;  

   array.retrieveNumber(pos1);  

   cout << endl;    

   cout << endl;    

   cout << "The highest number is: " << array.HighestNumber() << endl;    

   cout << "The lowest number is : " << array.LowestNumber() << endl;      

   cout << "Average of all numbers is : " << array.AverageNumber() << endl;    

    cout << endl;    

   return 0;        }

Explanation:

The program is well explained in the comments mentioned with each line of code in the attached document.

The screenshot of the program along with its output is attached.

You might be interested in
Draw a flow chart except the principle, time and date from the user. and display the simple interest and amount as output.​
timama [110]

Answer:

See attachment for flowchart

Explanation:

The explanation is as follows

1. Start

2. Get input for principal, time and rate

3. Calculate Interest using Interest = Principal * Rate * Time/100

4. Print Interest

5. Stop

7 0
3 years ago
Which is the correct option?
Murljashka [212]

Answer:

C

Explanation:

Key logging is when a hacker can track every key u have clicked.

3 0
3 years ago
Information taken directly from an existing classified source and stated verbatim in a new or different document is an example o
kvv77 [185]

This is known as information extraction.

4 0
3 years ago
1. The goals of the Safety Office of the Department of Transportation include______.
Lesechka [4]
The correct answer is D
5 0
3 years ago
Se dau 2 numere de 5 cifre fiecare. sa se afiseze acel numar care are cifra din mijloc mai mare. daca cifra este aceeasi, sa se
Aleks04 [339]
There are 2 5-digit numbers each. To display the number that has the larger figure. If the figure is the same, both numbers should be displayed.

How do you answer this?
6 0
3 years ago
Other questions:
  • The _____ layer of the Open Systems Interconnection (OSI) model generates a receiver’s address andensures the integrity of messa
    6·1 answer
  • 1. What should you do if your computer is shared by your entire family and you install a plugin that saves user names and passwo
    5·2 answers
  • What is the function of the Status bar in Outlook 2010?
    9·1 answer
  • Circular errors are caused by adding the cell name of a/an _______ cell to a formula.
    8·1 answer
  • Describing Editing Task
    6·1 answer
  • if you play creative destruction and if u have a mic and if u play it 24/7 and would like to form a team tell me your name or yo
    7·1 answer
  • Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards
    9·1 answer
  • Select the one that uses the heading tag correctly. <br><br>a. <br><br><br>b. <br><br>c. <br><br>d.
    12·2 answers
  • A(n) _____ is a computerized system by which subscribers are able to communicate to all other subscribers by sending a transmiss
    5·1 answer
  • You are looking for a computer to provide a central location for online game play. What kind of computer do you need
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!