Question



eciare a class to represent sample data set of 150 elements called DataType. DataType has two member vari member functions an
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<stdlib.h>
using namespace std;
//class defination
class Datatype
{
    private:
        int a[150],size;
    public :
        Datatype(); //default constructor
   void generate(); //generate the numbers
   void calculate(); //calculate the mean,median etc...
   void show(); //display the elements
};
//default constructor
Datatype :: Datatype()
{
   size=150; //assign 150 to size
}
//generate method
void Datatype :: generate()
{
   int i;
   //loop to generate 150 random values
   for(i=0;i<size;i++)
   {
   //generate random number between 81 to 255 inclusive
   a[i]=(rand() % (255 + 1 - 81)) + 81;
   }
}
//calculate method
void Datatype :: calculate()
{
    int t,min,max;
    int i,j;
    double mean,median;
        int range,sum=0;
//sort the elements of array
    for(i=0;i<size;i++)
    {
        for(j=i+1;j<size;j++)
        {
           if(a[i]>a[j])
           {
              t=a[i];
              a[i]=a[j];
              a[j]=t;
               }
           }
   }
   //loop to find the sum of all the elements
   for(i=0;i<size;i++)
   sum+=a[i];
   min=a[0]; //assign a[0] to min
   max=a[size-1]; //assign a[149] to max
   range = max-min; //compute the range
   mean = (double)sum/size; //compute the mean
   median = (double)((size/2) + (size/2 +1))/2; //compute the median since it having even number of elements to median = sum of middle elements/2
   //display all the calculated data
   cout<<endl<<"Minimum element : "<<min;
   cout<<endl<<"Mamimum element : "<<max;
   cout<<endl<<"Mean : "<<mean;
   cout<<endl<<"Median : "<<median;
   cout<<endl<<"Range : "<<range;
}
//show method display the array elements
void Datatype :: show()
{
   int i;
   cout<<endl<<"Array elements are \n";
   for(i=0;i<size;i++)
   {
   if(i%10==0) //after 10 element generate a new line to print the data in a formatted manner
   cout<<endl;
  
   cout<<" "<<a[i];  
       }
     
   }
   //driver program
int main()
{
   Datatype dobj;
   dobj.generate();
   dobj.show();
   dobj.calculate();
   }

output

CAUsers ROZYnKRISHNA Desktoplmean median range.exe Array elements are 122 173 115 156 175 230 184 214 93 220 186 226 87 108 2

Add a comment
Know the answer?
Add Answer to:
eciare a class to represent sample data set of 150 elements called DataType. DataType has two member vari member functions and include the functions to generate a sample set of random numbers be...
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
  • Write a class called RandomIntegerArrayCreator that: upon its object instantiation: will generate a random integer arraySize...

    Write a class called RandomIntegerArrayCreator that: upon its object instantiation: will generate a random integer arraySize from the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, create a random integer array of size arraySize (15 OR LESS) with elements from the the set {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10} (integers can appear multiple times in this array, has two accessor methods: public int getArraySize() that will...

  • Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive...

    Lottery Game (15 Numbers). Design and implement a C++ program that generates 15 random non-repeating positive integer numbers from 1 to 999 (lottery numbers) and takes a single input from the user and checks the input against the 15 lottery numbers. The user wins if her/his input matches one of the lottery numbers. Your implementation must have a level of modularity (using functions) Functions you need to implement: Define function initialize() that takes array lotterNumbers[] as a parameter and assigns...

  • 15. Define a class called Point. It has two private data members: x and y with int type; and three public member functions: a constructor, setPoint(int, int) and printPoint0. The constructor init...

    15. Define a class called Point. It has two private data members: x and y with int type; and three public member functions: a constructor, setPoint(int, int) and printPoint0. The constructor initializes the data members to 0. You need to use the operator?: to test whether x and y are positive. If not, assign them to 0. The function printPoint prints the message "(X, Y)" where X and Y are two integers. In the main program, first input the number...

  • Using Java programming language, build a class called IntegerSet. Instructions - Create class IntegerSet An IntegerSet...

    Using Java programming language, build a class called IntegerSet. Instructions - Create class IntegerSet An IntegerSet object holds integers in the range 0-100 Represented by an array of booleans, such that array element a[i] is set to true if integer i is in the set, and false otherwise Create these constructors and methods for the class IntegerSet() public IntegerSet union(IntegerSet iSet) public IntegerSet intersection(IntegerSet iSet) public IntegerSet insertElement(int data) public IntegerSet deleteElement(int data) public boolean isEqualTo(IntegerSet iSet) public String toString()...

  • Please give an answer which works to print the answer given below. Please use the necessary...

    Please give an answer which works to print the answer given below. Please use the necessary header .h and .cpp files. Please give the right solution. "ITS MY HUMBLE REQUEST TO GIVE THE RIGHT SOLUTION" Question 2 – Creating and working with other Containers A Set is a data structure which contains information on whether a value belongs to that set or not. In this question, you have to implement an integer Set which is able to tell whether an...

  • You will write the following files: mystack.h - contains the class definition for the mystack class....

    You will write the following files: mystack.h - contains the class definition for the mystack class. mystack.cpp - contains the definitions for member functions of the mystack class. inpost.cpp - contains your convert() function. inpost.h - contains the function prototype for convert() so that the main() can call it. Each of the files (with the exception of inpost.h) is described in more detail below. All header files should contain header guards to prevent them from being included multiple times in...

  • In this problem you'll get to use one of Java's random number generators, java.util.Random (see the...

    In this problem you'll get to use one of Java's random number generators, java.util.Random (see the docs for Random). This class generates a random double precision number uniformly distributed in the range [0.0 ... 1.0). That is, the numbers go from 0 to 1, including 0 but excluding 1. It is a common need in Java programming to generate a random integer number that's uniformly distributed in the range of [0 ... n), such as we saw in the dice...

  • 1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class...

    1. (40’) In myStack.cpp, implement the member functions of the class myStack, which is the class for integer stacks. 2. (20’) In stackTest.cpp, complete the implementation of function postfixTest(), which use an integer stack to evaluate post-fix expressions. For simplicity, you can assume the post-fix expression is input character by character (i.e., not an entire string), and each operand is a non-negative, single-digit integer (i.e., 0,1,…,9). However, you are supposed to detect invalid/ illegal post-fix expression input, e.g., “4 5...

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