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 Ntds. dit file is a database that stores Active Directory data, including information about user objects, groups, and group
vladimir2022 [97]

Answer:

I hate it

Explanation:

Mark it as the brainliest if u love god

8 0
2 years ago
Define function print_popcorn_time() with parameter bag_ounces. If bag_ounces is less than 3, print "Too small". If greater than
Lynna [10]

Answer:

def print_popcorn_time(bag_ounces):

 if bag_ounces<3:

   print("Too Small")

 elif bag_ounces>10:

   print("Too Large")

 else:

   bag_ounces = bag_ounces*6

   print("%s Seconds\n" % bag_ounces)    

Explanation:

  • Using Python Programming Language
  • The function is defined to accept an int parameter
  • Within the function body, if...elif and else statements are used to print the desired output
  • note the use of the %s placeholder (formated output) and \n for a new line in the final print statement
4 0
3 years ago
When pointed over a text within a paragraph, the cursor takes the shape of a/an
Crank
I type of shape, or a pointing index finger
5 0
3 years ago
___________ is a mass-produced, copyrighted software that meets the needs of a wide variety of users, not just a single user or
GaryK [48]

Answer: Package software

Explanation:

Packaged software is the software that contains the functions and programs that are similar in the nature and features.

It is designed in such a way so that it can attract the customers and user by providing the benefit of the selling of the collection of programs rather than buying individual software programs which costs higher.

Thus, it produced at a large scale as well as bought by numerous users.

4 0
3 years ago
A driving school uses this rule to estimate how many lessons a learner will require.
HACTEHA [7]

Answer:

This is correct. And to remove the confusion, I am adding the meaning of the Pseudocode. You need to begin with the algo that you are working upon, and then you need it to phrase the algo with the words which are easy to be transcribed in the form of the computer instructions. Now you need to indent the instructions properly inside the loop or within the conditional clauses. And while doing this, you need to not use the words which are used in certain forms of computer language. However, IF and THEN and ELSE and ENDIF are very frequently used as pseudo-code. Hence, your answer is correct.

Explanation:

Please check the answer section.

8 0
2 years ago
Other questions:
  • I have been trying to work on this for a while now, and this is on excel
    11·1 answer
  • During the charging of a storage battery, what is the temperature that the electrolyte solution must never exceed?
    6·1 answer
  • The INC and Dec instruction do not effect the__________ flag
    6·1 answer
  • What will the following program display?
    15·1 answer
  • Your friend Suzy calls to ask for help with her computer. She says when she first turns on the computer, she doesn’t hear a spin
    10·1 answer
  • PreparedStatement ps = connection.prepareStatement("select firstName, mi, lastName from Student where lastName = ?"; ps.setStrin
    5·1 answer
  • An organization is conducting a study to see if hazardous waste sites pose health risks for cancer or other conditions, such as
    12·1 answer
  • Add Try/Catch error checking To make sure that the user enters valid values in your program. To catch negative values passed to
    9·1 answer
  • * what is an electronic mail ?
    13·1 answer
  • Consider the following method, which is intended to count the number of times the letter "A" appears in the string str.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!