Define and implement the class array representing an array of real numbers with the following public methods:
-the constructor with the size of the array as a parameter,
-the destructor,
-size-returning the current size of the array from the user,
-read-reading the contents of the array from the user,
-print-printing the contents of the array,
-avg- returning the arithmetic mean of the values in the array,
-min- returning the smallest values in the array,
-max- returning the smallest values in the array,
reverse- reversing the order of the values in the array,
sort- returning a sorted copy of the array of the sorting
order depending on the value of the boolean parameter(true means the ascending orde).
This is not a homework site. We won't do your homework for you. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.
We didn't see your attempts to solve this problem yourself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again. As it is impossible to find derivative of function without knowledge in arithmetic, you cannot do more complex tasks in programming without clear understanding of basics
#include <iostream>
#include "ExamArray.h"
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
This is the main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
[code]int main(int argc, char** argv) {
//int size;
int classSize;
//cout<<"Please specify the size of the array"<<endl;
//cin>>size;
ExamArray array1(6);
classSize = array1.getSize();
cout <<"The elements of your array are: "<<endl;
array1.readContent(6);
// array1.displayContent(6);
return 0;
[/code]
This is exam array.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[code]#include <iostream>
usingnamespace std;
class ExamArray {
int arraySize;
ExamArray();
public:
ExamArray(int arraysize);
//int ExamArray[arraySize];
void setSize (int ssize);
int getSize();
void readContent (int ssize);
void displayContent (int ssize);
};
I asked you to please use code tags. Please see the link I provided above and edit your post.
I will not respond further until you apply code tags.
What I will tell you at this point is that you've made array a local variable within readContent and your constructor. As such, the content of the array goes out of scope when those functions exit. array should be a member variable of your class. The catch is that you can't declare a member variable (array) with a variable size. You have a couple of choices. Make array bigger that any possible input value, or dynamically allocate array.
i have used the code tags now.
please any assitance , still stuck with displaying the contents of the array in the function void ExamArray.
And i don't know how to go about with:
Define and implement the class array representing an array of real numbers with the public methods.
-the constructor with the size of the array as a parameter,
-the destructor
// examarray.h
class ExamArray
{ int arraySize;
int * array; // dynamically allocated
ExamArray();
public:
ExamArray (int arraysize);
~ExamArray (); // We need a destructor
void setSize (int ssize);
int getSize();
void readContent (); // Don't need size as an argument
void displayContent (); // Don't need size as an argument
};
i have done all, but i still have some problem with:
sort- returning a sorted copy of the array of the sorting
order depending on the value of the boolean parameter(true means the ascending order).