Question

Goals: Write your own class. Instantiate an object of your class. Interact with the object's public...

Goals:

  • Write your own class.
  • Instantiate an object of your class.
  • Interact with the object's public interface.

Requirements:

Design a class that has an array of floating-point numbers. The constructor should accept an integer argument and dynamically allocate 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 - accepts an integer and floating point number as it's only arguments. Uses the integer to select the array element to store the floating point number argument into.
  • Retrieve a number from any element of the array - accepts an integer as it's only argument and uses this to select the element to return.
  • Return the highest value stored in the array - accepts no arguments.
  • Return the lowest value stored in the array - accepts no arguments.
  • Return the average of all the numbers stored in the array - accepts no arguments.

    Demonstrate the class in a program. The class does not interact with the user in any way. All interactions with the user are done in the main function. Make sure all accessors are correctly marked const.

Implement your class according to this UML class diagram:

Sample Run:

Values in the Numbers object: 88.6 3.14 2.77 90.5

High Value in Numbers object: 90.5

Low Value in numbers object: 2.77

Average value in Numbers Object: 46.2525

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer;

Program

#include <iostream>
#include <string>

using namespace std;

class FloatingProblem
{
private:
float * ar;//array pointer

public:
FloatingProblem(int size)
{
ar = new float[size];//initializing array
}

setElement(int index, float num)
{
ar[index-1] = num;//setting array elements
}

float getElement(int index)
{
return ar[index-1];//getting array elements
}

float highest()
{
float high = ar[0];
int n = sizeof(ar)+1;
for(int i=1; i<n; i++)
{
if(high<ar[i])//finding highest
{
high = ar[i];
}
}
return high;
}

float lowest()
{
float low = ar[0];
int n = sizeof(ar)+1;
for(int i=1; i<n; i++)
{
if(low>ar[i])//finding lowest
{
low = ar[i];
}
}
return low;
}

float average()
{
float sum = 0;
int n = sizeof(ar)+1;
for(int i=1; i<n; i++)
{
sum+= ar[i];
}
return sum/n;
}

~FloatingProblem()
{
delete[] ar;//deconstructor
}
};

int main()
{
FloatingProblem obj(5);

//loading the array
obj.setElement(1, 10.2);
obj.setElement(2, 20.4);
obj.setElement(3, 14.6);
obj.setElement(4, 15.8);
obj.setElement(5, 13.8);

//testing all functions
cout<<"Array value at index 3: "<<obj.getElement(3)<<endl;
cout<<"Highest: "<<obj.highest()<<endl;
cout<<"Lowest: "<<obj.lowest()<<endl;
cout<<"Average: "<<obj.average(

Add a comment
Know the answer?
Add Answer to:
Goals: Write your own class. Instantiate an object of your class. Interact with the object's public...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to...

    (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class- the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should store the fraction in reduced form. The fraction 2/4 is equivalent to h and would be stored in the object as 1 in the numerator...

  • Please use Java language. Thanks in advance. HOME WORK due 09. 18.2019 (Rational Numbers) Create a...

    Please use Java language. Thanks in advance. HOME WORK due 09. 18.2019 (Rational Numbers) Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class- the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should store the fraction in reduced form. The fraction 2/4 is equivalent to 2...

  • Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...

    Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...

  • In C++. Define a class Country that stores the name of the country, its population, and...

    In C++. Define a class Country that stores the name of the country, its population, and its area. Store the country name as a C-string. Write a main function that initializes an array with at least 5 objects of this class and sorts and prints this array in three different ways: By population By population density (people per square kilometer) Do not ask the user to enter country data. Use qsort to sort the array. Also sort alphabetically by country...

  • Antique Class Each Antique object being sold by a Merchant and will have the following attributes:...

    Antique Class Each Antique object being sold by a Merchant and will have the following attributes: name (string) price (float) And will have the following member functions: mutators (setName, setPrice) accessors (getName, getPrice) default constructor that sets name to "" (blank string) and price to 0 when a new Antique object is created a function toString that returns a string with the antique information in the following format <Antique.name>: $<price.2digits> Merchant Class A Merchant class will be able to hold...

  • In C++ syntax please Write a program that implements and demonstrates a linked list using functions....

    In C++ syntax please Write a program that implements and demonstrates a linked list using functions. Your program should first dehne a node that stores an integer and then your program will include the following functions appendo- This function accepts the head pointer (by reference) of a linked list and an integer as it's only arguments. It then creates a node, stores the integer argument in the node, and adds it to the end of the list. findo-This function accepts...

  • PLEASE USE OBJECT ORIENTED PROGRAMMING IN C# USING MICROSOFT VISUAL. *****PLEASE USE C#(C SHARP)*...

    PLEASE USE OBJECT ORIENTED PROGRAMMING IN C# USING MICROSOFT VISUAL. *****PLEASE USE C#(C SHARP)***** Also please dont use BigInteger thanks it's really appreciated for all the help PLEASE MAKE IT SO ITS USER INPUT Create a class called Rational for prforming arithmetie with fractions. Write an app to test your class Use integer variables to represent the private instance variables of the class-the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized...

  • Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers...

    Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers from user and stores all the numbers in the array intArray. Now, read another integer number N from the user, find the total number of array elements that are greater or equal to the number N, and the total number of array elements that are lower than the number N You must have two procedures: i. ReadIntegerArray: this procedure should read integer array elements...

  • CSE/EEE230 Assignment11 Due Date Thursday, April 25th, 5pm Note: the lowest scored assignment wil...

    CSE/EEE230 Assignment11 Due Date Thursday, April 25th, 5pm Note: the lowest scored assignment will be dropped. Important: This is an individual assignment. Please do not collaborate. It must be submitted on-line (Blackboard). No late assignment will be accepted Minimal Submitted Files You are required to turn in the following source file: assignment11.s Objectives: -write assembly language programs to:             -perform arithmetic on floating point numbers             -use syscall operations to display floating point numbers and strings on the console window             -use syscall...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT