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
The command to delete all the files that have filenames that starts with letter c or c and ends with a letter z or z is
dimaraw [331]
The command is : <span>rm [Aa]*[Zz] </span>
4 0
3 years ago
Which path needs to be followed to change the currency settings of Windows Operating System?
PIT_PIT [208]

Answer:

To configure operating system settings, in Control Panel, click Performance And Maintenance. To view operating system performance configuration options, in the Performance And Maintenance window, click System, and then click the Advanced tab.

4 0
3 years ago
 How does critically analyzing technology add value to interactions with people in personal and professional contexts?
AysviL [449]

Answer:

Critically analyzing technology helps realize the need for improvement, extension and creativity that technology can bring towards advancement basically both for personal interactions and in professional settings.

Explanation:

It's helps build the need of Technological inclusion for productivity. Thank you.

8 0
3 years ago
Read 2 more answers
What is the iterative procedure of recursive and nonrecursive?
DanielleElmas [232]

Answer:

nonrecursive

Explanation:

3 0
2 years ago
Write the code for invoking a method named sendObject. There is one argument for this method which is of type Customer. Assume t
kodGreya [7K]

Answer:

sendObject(John_Doe);

Explanation:

The above code has been written in Java.

Since the calling class is the same that declares it, to invoke the method, simply call its name with its argument(s) in a pair parentheses. The name of the method is "sendObject" and its argument is a reference to an object of type Customer saved in a variable called "John_Doe". This can be written as follows:

sendObject(John_Doe);

Hope this helps!

3 0
3 years ago
Other questions:
  • When using a template to compose a memorandum which key on the keyboard moves the cursor to the next field
    15·1 answer
  • When reading a ____ language, we use our understanding of the richness of the language's vocabulary to extract the meaning. geop
    10·1 answer
  • Match the spreadsheet features with their respective descriptions.
    7·2 answers
  • A hub or ____ is a central point that connects several devices in a network together.
    11·1 answer
  • What is the windows server 2012 r2 feature that enables you to maintain previous versions of files on a server, so that if users
    10·1 answer
  • "Managers and department heads across the nation strategize on a weekly, if not daily, basis. For the past three quarters, telep
    6·1 answer
  • Which of the following statements is correct?
    11·1 answer
  • Create a program that generates a report that displays a list of students, classes they are enrolled in and the professor who te
    11·1 answer
  • Rain forests clean the air by producing oxygen. Some rain forest plants have healing properties, and can be used as medicine. Ra
    12·1 answer
  • True or False? A website for a certain political party or candidate is likely to have unbiased information.
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!