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 answer is family and friends
nadya68 [22]
Family and Friends



you said the answer was that, soooooo
5 0
3 years ago
Read 2 more answers
Now, we’re ready to program! Leave the visualizer and go back to https://repl.it/ to write your program. Here is the pseudocode
svlad2 [7]

Answer:

here

Explanation:

6 0
2 years ago
What is the best way to limit a google search and get the most specific information possible?
Marrrta [24]
You go into settings on the google search and click advanced search. The rest you do on your own.
6 0
3 years ago
In what ways are computers being used to improve our quality of life
serg [7]

Explanation:

makes info easy to get

improves communication

enhances education

etc

plsss mark me brainliesttt

3 0
3 years ago
What is your first step in developing the database?
barxatty [35]

The first step in developing a database is simply to have a conversation (talk) to the employees or end users who will be using the database.

<h3>What is a database?</h3>

A database can be defined as an organized and structured collection of data that are stored on a computer system as a backup and are usually accessed electronically.

As a general rule, having a conversation (talk) to the employees or end users who will be using the database is the first step in developing a database.

Read more on database here: brainly.com/question/13179611

#SPJ12

8 0
2 years ago
Other questions:
  • Using Python
    14·1 answer
  • considering that two variables counters and accumulators are important in loop design. What would be their purpose?
    9·1 answer
  • Set numMatches to the number of elements in userValues (having NUM_VALS elements) that equal matchValue. Ex: If matchValue = 2 a
    6·1 answer
  • Will upvote all answers
    7·1 answer
  • You are asked to write an app to keep track of a relatively small music library. The app should load song information from a dat
    14·1 answer
  • When you are given a set of tables and asked to create a database to store their data, the first step is to ________?
    8·1 answer
  • i set up an account and paid the yearly fee, now it's asking me to join. i've tried to log in and brainly isn't accepting my ema
    8·1 answer
  • Ciscon Telecom is a mobile operator in the European Union. The company provides personalized services to its customers, and its
    8·2 answers
  • Which of the following statements are true?
    11·1 answer
  • Which task can be completed with the Template Organizer?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!