c++ Problems with operator overloading [duplicate]










-2















This question already has an answer here:



  • What are the basic rules and idioms for operator overloading?

    7 answers



My assignment is to use operator overloading to



  1. create a random number array

  2. get lowest number

  3. get highest number

  4. get average

  5. get total and

  6. get standard deviation.

It is just a mess. Here is my code:



#ifndef ASSIGNMENT6_HEAD6_H
#define ASSIGNMENT6_HEAD6_H

#include <iostream>
using namespace std;

class Analyzer

//Private Member
private:
int numbers;

//Public Member
public:
Analyzer();//default constructor
~Analyzer();//destructor
Analyzer operator+(const Analyzer &a) const;

friend numbers operator+();


;//end of class

#endif //ASSIGNMENT6_HEAD6_H

//Class math with overloading operator and friends
#include "head6.h"
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;

vector<int> numbers;
int min = numbers[0];
int max = numbers[0];
int sizeofArray;
Analyzer::Analyzer()


int getLowest(const int, int);
//Random number member
void randNumbers(int sizeofArray, int* numbers)
for (int index = 0; index < sizeofArray; index++)

numbers[index] = (numbers() % 499) + 100;

return;

//Setters
int lowest = getLowest(numbers, sizeofArray);
int highest = getHighest(numbers, sizeofArray);
float total = getTotal(numbers);
double average = getAverage(total, sizeofArray);
//Lowest number
void getLowest(const int numbers, int sizeofArray)
for (int i = 0; i < sizeofArray; i++)
if (min > numbers[i])
min = numbers[i];
min = lowest;


return;

//Highest number
void getHighest(const int numbers, int sizeofArray)
for (int i = 0; i < sizeofArray; i++)
if (max > numbers[i])
max = numbers[i];
max = lowest;


return;

//Total
float getTotal(const int numbers)
total = sum(numbers);
return total;

//Average
double getAverage(const float total, int sizeofArray)
double average = total / sizeofArray;
return average;

//standard deviation
float getStandardDeviation(int sizeofArray, float numbers)const

float deviation1;
for (int i = 0; i < sizeofArray; i++)
sum = (mean - numbers[i]) * (mean - numbers[i]);

deviation1 = sqrt(sum / sizeofArray - 1);
float deviation = deviation1;

return deviation;


string a()
stringstream sout;
sout << "STATISTICAL ANALYSIS OF RANDOMLY GENERATED NUMBERS" << endl;
sout << "====================================================" << endl;
sout << left << "Lowest Number:" << left << getLowest() << endl;
sout << left << "Highest Number:" << left << getHighest() << endl;
sout << left << "Numbers Total:" << left << getTotal() << endl;
sout << left << "Numbers Averge:" << left << getAverage() << endl;
sout << left << "Numbers of Standard Deviation:" << left <<
getStandardDeviation() << endl;
return sout.a();


int ​​main()

Analyzer a;

a + 100;
cout << a;

return 0;



Thank you for any assistance.










share|improve this question















marked as duplicate by Swordfish, JeJo, David C. Rankin, dandan78, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 10 at 9:32


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • What is the thing you pass to randNumbers() as 2nd parameter?
    – Swordfish
    Nov 10 at 6:14










  • Please provide a Minimal, Complete, and Verifiable example.
    – Swordfish
    Nov 10 at 6:15










  • What does numbers look like?
    – Ayxan
    Nov 10 at 6:16










  • everytime you use global variables, a kitty dies :(
    – Swordfish
    Nov 10 at 6:27






  • 3




    voting to close since it is unclear what you are asking. Your code has so many problems that it is allmost impossible to guess what it should be doing. Please ask specific quesitons.
    – Swordfish
    Nov 10 at 6:42















-2















This question already has an answer here:



  • What are the basic rules and idioms for operator overloading?

    7 answers



My assignment is to use operator overloading to



  1. create a random number array

  2. get lowest number

  3. get highest number

  4. get average

  5. get total and

  6. get standard deviation.

It is just a mess. Here is my code:



#ifndef ASSIGNMENT6_HEAD6_H
#define ASSIGNMENT6_HEAD6_H

#include <iostream>
using namespace std;

class Analyzer

//Private Member
private:
int numbers;

//Public Member
public:
Analyzer();//default constructor
~Analyzer();//destructor
Analyzer operator+(const Analyzer &a) const;

friend numbers operator+();


;//end of class

#endif //ASSIGNMENT6_HEAD6_H

//Class math with overloading operator and friends
#include "head6.h"
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;

vector<int> numbers;
int min = numbers[0];
int max = numbers[0];
int sizeofArray;
Analyzer::Analyzer()


int getLowest(const int, int);
//Random number member
void randNumbers(int sizeofArray, int* numbers)
for (int index = 0; index < sizeofArray; index++)

numbers[index] = (numbers() % 499) + 100;

return;

//Setters
int lowest = getLowest(numbers, sizeofArray);
int highest = getHighest(numbers, sizeofArray);
float total = getTotal(numbers);
double average = getAverage(total, sizeofArray);
//Lowest number
void getLowest(const int numbers, int sizeofArray)
for (int i = 0; i < sizeofArray; i++)
if (min > numbers[i])
min = numbers[i];
min = lowest;


return;

//Highest number
void getHighest(const int numbers, int sizeofArray)
for (int i = 0; i < sizeofArray; i++)
if (max > numbers[i])
max = numbers[i];
max = lowest;


return;

//Total
float getTotal(const int numbers)
total = sum(numbers);
return total;

//Average
double getAverage(const float total, int sizeofArray)
double average = total / sizeofArray;
return average;

//standard deviation
float getStandardDeviation(int sizeofArray, float numbers)const

float deviation1;
for (int i = 0; i < sizeofArray; i++)
sum = (mean - numbers[i]) * (mean - numbers[i]);

deviation1 = sqrt(sum / sizeofArray - 1);
float deviation = deviation1;

return deviation;


string a()
stringstream sout;
sout << "STATISTICAL ANALYSIS OF RANDOMLY GENERATED NUMBERS" << endl;
sout << "====================================================" << endl;
sout << left << "Lowest Number:" << left << getLowest() << endl;
sout << left << "Highest Number:" << left << getHighest() << endl;
sout << left << "Numbers Total:" << left << getTotal() << endl;
sout << left << "Numbers Averge:" << left << getAverage() << endl;
sout << left << "Numbers of Standard Deviation:" << left <<
getStandardDeviation() << endl;
return sout.a();


int ​​main()

Analyzer a;

a + 100;
cout << a;

return 0;



Thank you for any assistance.










share|improve this question















marked as duplicate by Swordfish, JeJo, David C. Rankin, dandan78, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 10 at 9:32


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • What is the thing you pass to randNumbers() as 2nd parameter?
    – Swordfish
    Nov 10 at 6:14










  • Please provide a Minimal, Complete, and Verifiable example.
    – Swordfish
    Nov 10 at 6:15










  • What does numbers look like?
    – Ayxan
    Nov 10 at 6:16










  • everytime you use global variables, a kitty dies :(
    – Swordfish
    Nov 10 at 6:27






  • 3




    voting to close since it is unclear what you are asking. Your code has so many problems that it is allmost impossible to guess what it should be doing. Please ask specific quesitons.
    – Swordfish
    Nov 10 at 6:42













-2












-2








-2








This question already has an answer here:



  • What are the basic rules and idioms for operator overloading?

    7 answers



My assignment is to use operator overloading to



  1. create a random number array

  2. get lowest number

  3. get highest number

  4. get average

  5. get total and

  6. get standard deviation.

It is just a mess. Here is my code:



#ifndef ASSIGNMENT6_HEAD6_H
#define ASSIGNMENT6_HEAD6_H

#include <iostream>
using namespace std;

class Analyzer

//Private Member
private:
int numbers;

//Public Member
public:
Analyzer();//default constructor
~Analyzer();//destructor
Analyzer operator+(const Analyzer &a) const;

friend numbers operator+();


;//end of class

#endif //ASSIGNMENT6_HEAD6_H

//Class math with overloading operator and friends
#include "head6.h"
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;

vector<int> numbers;
int min = numbers[0];
int max = numbers[0];
int sizeofArray;
Analyzer::Analyzer()


int getLowest(const int, int);
//Random number member
void randNumbers(int sizeofArray, int* numbers)
for (int index = 0; index < sizeofArray; index++)

numbers[index] = (numbers() % 499) + 100;

return;

//Setters
int lowest = getLowest(numbers, sizeofArray);
int highest = getHighest(numbers, sizeofArray);
float total = getTotal(numbers);
double average = getAverage(total, sizeofArray);
//Lowest number
void getLowest(const int numbers, int sizeofArray)
for (int i = 0; i < sizeofArray; i++)
if (min > numbers[i])
min = numbers[i];
min = lowest;


return;

//Highest number
void getHighest(const int numbers, int sizeofArray)
for (int i = 0; i < sizeofArray; i++)
if (max > numbers[i])
max = numbers[i];
max = lowest;


return;

//Total
float getTotal(const int numbers)
total = sum(numbers);
return total;

//Average
double getAverage(const float total, int sizeofArray)
double average = total / sizeofArray;
return average;

//standard deviation
float getStandardDeviation(int sizeofArray, float numbers)const

float deviation1;
for (int i = 0; i < sizeofArray; i++)
sum = (mean - numbers[i]) * (mean - numbers[i]);

deviation1 = sqrt(sum / sizeofArray - 1);
float deviation = deviation1;

return deviation;


string a()
stringstream sout;
sout << "STATISTICAL ANALYSIS OF RANDOMLY GENERATED NUMBERS" << endl;
sout << "====================================================" << endl;
sout << left << "Lowest Number:" << left << getLowest() << endl;
sout << left << "Highest Number:" << left << getHighest() << endl;
sout << left << "Numbers Total:" << left << getTotal() << endl;
sout << left << "Numbers Averge:" << left << getAverage() << endl;
sout << left << "Numbers of Standard Deviation:" << left <<
getStandardDeviation() << endl;
return sout.a();


int ​​main()

Analyzer a;

a + 100;
cout << a;

return 0;



Thank you for any assistance.










share|improve this question
















This question already has an answer here:



  • What are the basic rules and idioms for operator overloading?

    7 answers



My assignment is to use operator overloading to



  1. create a random number array

  2. get lowest number

  3. get highest number

  4. get average

  5. get total and

  6. get standard deviation.

It is just a mess. Here is my code:



#ifndef ASSIGNMENT6_HEAD6_H
#define ASSIGNMENT6_HEAD6_H

#include <iostream>
using namespace std;

class Analyzer

//Private Member
private:
int numbers;

//Public Member
public:
Analyzer();//default constructor
~Analyzer();//destructor
Analyzer operator+(const Analyzer &a) const;

friend numbers operator+();


;//end of class

#endif //ASSIGNMENT6_HEAD6_H

//Class math with overloading operator and friends
#include "head6.h"
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;

vector<int> numbers;
int min = numbers[0];
int max = numbers[0];
int sizeofArray;
Analyzer::Analyzer()


int getLowest(const int, int);
//Random number member
void randNumbers(int sizeofArray, int* numbers)
for (int index = 0; index < sizeofArray; index++)

numbers[index] = (numbers() % 499) + 100;

return;

//Setters
int lowest = getLowest(numbers, sizeofArray);
int highest = getHighest(numbers, sizeofArray);
float total = getTotal(numbers);
double average = getAverage(total, sizeofArray);
//Lowest number
void getLowest(const int numbers, int sizeofArray)
for (int i = 0; i < sizeofArray; i++)
if (min > numbers[i])
min = numbers[i];
min = lowest;


return;

//Highest number
void getHighest(const int numbers, int sizeofArray)
for (int i = 0; i < sizeofArray; i++)
if (max > numbers[i])
max = numbers[i];
max = lowest;


return;

//Total
float getTotal(const int numbers)
total = sum(numbers);
return total;

//Average
double getAverage(const float total, int sizeofArray)
double average = total / sizeofArray;
return average;

//standard deviation
float getStandardDeviation(int sizeofArray, float numbers)const

float deviation1;
for (int i = 0; i < sizeofArray; i++)
sum = (mean - numbers[i]) * (mean - numbers[i]);

deviation1 = sqrt(sum / sizeofArray - 1);
float deviation = deviation1;

return deviation;


string a()
stringstream sout;
sout << "STATISTICAL ANALYSIS OF RANDOMLY GENERATED NUMBERS" << endl;
sout << "====================================================" << endl;
sout << left << "Lowest Number:" << left << getLowest() << endl;
sout << left << "Highest Number:" << left << getHighest() << endl;
sout << left << "Numbers Total:" << left << getTotal() << endl;
sout << left << "Numbers Averge:" << left << getAverage() << endl;
sout << left << "Numbers of Standard Deviation:" << left <<
getStandardDeviation() << endl;
return sout.a();


int ​​main()

Analyzer a;

a + 100;
cout << a;

return 0;



Thank you for any assistance.





This question already has an answer here:



  • What are the basic rules and idioms for operator overloading?

    7 answers







c++






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 6:25









Swordfish

1




1










asked Nov 10 at 6:00









Scientist

12




12




marked as duplicate by Swordfish, JeJo, David C. Rankin, dandan78, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 10 at 9:32


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Swordfish, JeJo, David C. Rankin, dandan78, πάντα ῥεῖ c++
Users with the  c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Nov 10 at 9:32


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.













  • What is the thing you pass to randNumbers() as 2nd parameter?
    – Swordfish
    Nov 10 at 6:14










  • Please provide a Minimal, Complete, and Verifiable example.
    – Swordfish
    Nov 10 at 6:15










  • What does numbers look like?
    – Ayxan
    Nov 10 at 6:16










  • everytime you use global variables, a kitty dies :(
    – Swordfish
    Nov 10 at 6:27






  • 3




    voting to close since it is unclear what you are asking. Your code has so many problems that it is allmost impossible to guess what it should be doing. Please ask specific quesitons.
    – Swordfish
    Nov 10 at 6:42
















  • What is the thing you pass to randNumbers() as 2nd parameter?
    – Swordfish
    Nov 10 at 6:14










  • Please provide a Minimal, Complete, and Verifiable example.
    – Swordfish
    Nov 10 at 6:15










  • What does numbers look like?
    – Ayxan
    Nov 10 at 6:16










  • everytime you use global variables, a kitty dies :(
    – Swordfish
    Nov 10 at 6:27






  • 3




    voting to close since it is unclear what you are asking. Your code has so many problems that it is allmost impossible to guess what it should be doing. Please ask specific quesitons.
    – Swordfish
    Nov 10 at 6:42















What is the thing you pass to randNumbers() as 2nd parameter?
– Swordfish
Nov 10 at 6:14




What is the thing you pass to randNumbers() as 2nd parameter?
– Swordfish
Nov 10 at 6:14












Please provide a Minimal, Complete, and Verifiable example.
– Swordfish
Nov 10 at 6:15




Please provide a Minimal, Complete, and Verifiable example.
– Swordfish
Nov 10 at 6:15












What does numbers look like?
– Ayxan
Nov 10 at 6:16




What does numbers look like?
– Ayxan
Nov 10 at 6:16












everytime you use global variables, a kitty dies :(
– Swordfish
Nov 10 at 6:27




everytime you use global variables, a kitty dies :(
– Swordfish
Nov 10 at 6:27




3




3




voting to close since it is unclear what you are asking. Your code has so many problems that it is allmost impossible to guess what it should be doing. Please ask specific quesitons.
– Swordfish
Nov 10 at 6:42




voting to close since it is unclear what you are asking. Your code has so many problems that it is allmost impossible to guess what it should be doing. Please ask specific quesitons.
– Swordfish
Nov 10 at 6:42












2 Answers
2






active

oldest

votes


















1














Your assignment is to use operator overloading to solve the issues - but you actually don't do so anywhere (apart from the operator+ for your Analyzer class – which is meaningless, though).



Reading your lines, I'd rather assume that you're supposed to write separate classes for each task:



class Minimum

std::vector<int> const& values
public:
Minimum(std::vector<int> const& values) : values(values)
// calculates minimum / lowest value from member:
int operator()();
;
class Maximum

public:
//Maximum(); not needed in this variant

// calculates maximum from parameter
int operator()(std::vector<int> const& values);
;

void test()

std::vector<int> values(10, 12, 7);
int min = Minimum(values)();
int max = Maximum()(values);



These are two different patterns, for consistency, you should select one and implement all classes alike. In first approach, you can access the vector from any member function without having to pass it around as parameter, in second approach, you can re-use one and the same object to calculate the value on several different vectors (you could still maintain a pointer to the vector to avoid passing it around via parameters...).



Coming back to your original code, unfortunately it is full of errors



vector<int> numbers;
int min = numbers[0]; // vector is yet empty! undefined behaviour!
int max = numbers[0];


Actually, you might want not to use globals at all, see later...



//int sizeofArray; // use numbers.size() instead!

// not an error, but questionable: you have a std::vector already, why do you
// fall back to C-style raw arrays?
void randNumbers(int sizeofArray, int* numbers)
// ^ array of pointers???

for (int index = 0; index < sizeofArray; index++)

numbers[index] = (numbers() % 499) + 100;
// you certainly intended to use rand function

// return; // just plain obsolete


// vector variant:
void randNumbers(unsigned int numberOfValues, std::vector<int>& destination)
// ^ not how many numbers ARE in,
// but how many SHALL be inserted

// assuming we want to re-use this function and guarantee that EXACTLY
// 'numberOfValues' values are contained:
destination.clear(); // there might have been some values in already...

// assure sufficently internal memory pre-allocated to prevent
// multiple re-allocations during filling the vector:
destination.reserve(numberOfValues);

while(numberOfValues--)

numbers.push_back(rand() * 500 / RAND_MAX + 100);
// modulus is unprecise; this calculation will give you better
// distribution
// however, rather prefer modern C++ random number generators!
// IF you use rand: assure that you call srand, too, but exactly ONCE,
// best right when entering main function



// C++ random number generator:
void randNumbers(unsigned int numberOfValues, std::vector<int>& destination)

static std::uniform_int_distribution<> d(100, 599);
static std::mt19937 g;

destination.clear();
destination.reserve(numberOfValues);
while(numberOfValues--)

numbers.push_back(d(g));




Now you have contradicting function declarations:



int getLowest(const int, int);
void getLowest(const int numbers, int sizeofArray) /* ... */

int lowest = getLowest(numbers, sizeofArray);
// again: the vector is yet empty!
// so you certainly won't get the result desired
// however, this won't compile at all: numbers is a std::vector,
// but parameter type is array, so you need:
int lowest = getLowest(numbers.data(), numbers.size());
// ^ replaced the redundant global as well
// move this into your main function AFTER having filled the vector!

// picking int as return value:
int getLowest(const int numbers, unsigned int sizeofArray)

// you'd now have to initialize the global first; better, though:
// return a local variable:

// this assumes that there is at least one element in! check before usage
// and decide what would be the appropriate error handling if the vector
// is empty (return 0? return INT_MIN? throw an execption?)
int min = numbers[0];

for (int i = 1; i < sizeofArray; i++)

if (min > numbers[i])

min = numbers[i];
// min = lowest; // don't overwrite the minimum again!



// returning at end of void function is obsolete, don't do that explicitly
// well, with int as return value, as is NOW, you NEED to return:
return min;



Maximum analogously, be aware that you did not change the comparison from > to <! Be aware that there are already std::min_element, std::max_element and std::minmax_element which do the same (if not prohibited by the assignment, you should rather use these instead of re-inventing the wheel).



// prefere double! float (on typical machines at least) has same size as int
// and it is quite likely that you will lose precision due to rounding; I
// personally would rather use int64_t instead, so you won't run into rounding
// issues even with double and you'd need quite a large amount of summands
// before overflow can occur...
float getTotal(const int numbers) // just one single number???

total = sum(numbers);
// index operator cannot be applied on a single int; additionally, you need
// to provide an argument; where is 'sum' function defined at all???

return total;


// prefer double again
double getStandardDeviation(int sizeofArray, float numbers) // const
// (free standing functions cannot be const)

// mean isn't declared/defined anywhere (average instead?)!
// and you need to declare and initialize the sum appropriately:
double sum = 0.0;

float deviation1;
for (int i = 0; i < sizeofArray; i++)
sum += (mean - numbers[i]) * (mean - numbers[i]);
// ^ you need to add, if you want to build sum

// why two variables, even both of same type???
deviation1 = sqrt(sum / sizeofArray - 1);
float deviation = deviation1;

return deviation;

// simplest: drop both deviation and deviation 1 and just do:
return sqrt(sum / sizeofArray - 1);



Finally: I don't think that you'd use the resulting string (below) for anything else than printing out to console again, so I'd output to std::cout directly (naming the function 'print'); if at all, I'd provide a std::ostream as parameter to be more flexible:



void print(std::ostream& sout)

sout << "STATISTICAL ANALYSIS OF RANDOMLY GENERATED NUMBERS" << endl;
sout << "====================================================" << endl;
sout << left << "Lowest Number:" << left << getLowest() << endl;
sout << left << "Highest Number:" << left << getHighest() << endl;
sout << left << "Numbers Total:" << left << getTotal() << endl;
sout << left << "Numbers Averge:" << left << getAverage() << endl;
sout << left << "Numbers of Standard Deviation:" << left
<< getStandardDeviation() << endl;



Now you could pass std::cout to, a std::ostringstream object or even write to file via a std::ofstream...



int ​​main()

Analyzer a, b, c; // b, c added by me for illustration only

a + 100;
// the operator accepts another Analyzer object, so you could do
c = a + b;

cout << a; // there's no operator<< overload for Analyzer class


// it is HERE where you'd call all your getXZY functions!

return 0;






share|improve this answer






























    0














    You are passing a pointer to an array of integers:



    void randNumbers(int sizeofArray, int* numbers)


    where you really just want to pass numbers as an array. And since all arrays degrade to pointers when passed as a parameter, your function is simply this:



    void randNumbers(int sizeofArray, int* numbers) 

    for(int index = 0; index < sizeofArray; index++)
    numbers[index]= (rand() % 499) + 100;
    ;




    The result is that the items in numbers will be integers in the range of [100..599] inclusive.






    share|improve this answer




















    • I personally prefer int numbers syntax in given case, makes more obvious that really an array is expected...
      – Aconcagua
      Nov 10 at 6:35










    • @Aconcagua I detest the usage of when it is used to "hide" a pointer.
      – Swordfish
      Nov 10 at 6:38










    • @Swordfish Fine (not meant ironically!), now we are complete: pro (distinguish array from simple pointer, e. g. as additional return value) and contra (hiding pointer nature). Now up to the reader which one he/she wants to weigh stronger...
      – Aconcagua
      Nov 10 at 7:10










    • @Aconcagua i don't get your point.
      – Swordfish
      Nov 10 at 7:13










    • @Swordfish int set(int* target) target = 7; void iterate(unsigned int num, int values) while(num--) ++values; . If applied consistently (I do so with exception of C-strings), the syntax difference can be used to indicate which kind of pointer is expected (to single element or to first of array), additionally a hint what the function might do. Maybe marginal, but still...
      – Aconcagua
      Nov 10 at 7:42


















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Your assignment is to use operator overloading to solve the issues - but you actually don't do so anywhere (apart from the operator+ for your Analyzer class – which is meaningless, though).



    Reading your lines, I'd rather assume that you're supposed to write separate classes for each task:



    class Minimum

    std::vector<int> const& values
    public:
    Minimum(std::vector<int> const& values) : values(values)
    // calculates minimum / lowest value from member:
    int operator()();
    ;
    class Maximum

    public:
    //Maximum(); not needed in this variant

    // calculates maximum from parameter
    int operator()(std::vector<int> const& values);
    ;

    void test()

    std::vector<int> values(10, 12, 7);
    int min = Minimum(values)();
    int max = Maximum()(values);



    These are two different patterns, for consistency, you should select one and implement all classes alike. In first approach, you can access the vector from any member function without having to pass it around as parameter, in second approach, you can re-use one and the same object to calculate the value on several different vectors (you could still maintain a pointer to the vector to avoid passing it around via parameters...).



    Coming back to your original code, unfortunately it is full of errors



    vector<int> numbers;
    int min = numbers[0]; // vector is yet empty! undefined behaviour!
    int max = numbers[0];


    Actually, you might want not to use globals at all, see later...



    //int sizeofArray; // use numbers.size() instead!

    // not an error, but questionable: you have a std::vector already, why do you
    // fall back to C-style raw arrays?
    void randNumbers(int sizeofArray, int* numbers)
    // ^ array of pointers???

    for (int index = 0; index < sizeofArray; index++)

    numbers[index] = (numbers() % 499) + 100;
    // you certainly intended to use rand function

    // return; // just plain obsolete


    // vector variant:
    void randNumbers(unsigned int numberOfValues, std::vector<int>& destination)
    // ^ not how many numbers ARE in,
    // but how many SHALL be inserted

    // assuming we want to re-use this function and guarantee that EXACTLY
    // 'numberOfValues' values are contained:
    destination.clear(); // there might have been some values in already...

    // assure sufficently internal memory pre-allocated to prevent
    // multiple re-allocations during filling the vector:
    destination.reserve(numberOfValues);

    while(numberOfValues--)

    numbers.push_back(rand() * 500 / RAND_MAX + 100);
    // modulus is unprecise; this calculation will give you better
    // distribution
    // however, rather prefer modern C++ random number generators!
    // IF you use rand: assure that you call srand, too, but exactly ONCE,
    // best right when entering main function



    // C++ random number generator:
    void randNumbers(unsigned int numberOfValues, std::vector<int>& destination)

    static std::uniform_int_distribution<> d(100, 599);
    static std::mt19937 g;

    destination.clear();
    destination.reserve(numberOfValues);
    while(numberOfValues--)

    numbers.push_back(d(g));




    Now you have contradicting function declarations:



    int getLowest(const int, int);
    void getLowest(const int numbers, int sizeofArray) /* ... */

    int lowest = getLowest(numbers, sizeofArray);
    // again: the vector is yet empty!
    // so you certainly won't get the result desired
    // however, this won't compile at all: numbers is a std::vector,
    // but parameter type is array, so you need:
    int lowest = getLowest(numbers.data(), numbers.size());
    // ^ replaced the redundant global as well
    // move this into your main function AFTER having filled the vector!

    // picking int as return value:
    int getLowest(const int numbers, unsigned int sizeofArray)

    // you'd now have to initialize the global first; better, though:
    // return a local variable:

    // this assumes that there is at least one element in! check before usage
    // and decide what would be the appropriate error handling if the vector
    // is empty (return 0? return INT_MIN? throw an execption?)
    int min = numbers[0];

    for (int i = 1; i < sizeofArray; i++)

    if (min > numbers[i])

    min = numbers[i];
    // min = lowest; // don't overwrite the minimum again!



    // returning at end of void function is obsolete, don't do that explicitly
    // well, with int as return value, as is NOW, you NEED to return:
    return min;



    Maximum analogously, be aware that you did not change the comparison from > to <! Be aware that there are already std::min_element, std::max_element and std::minmax_element which do the same (if not prohibited by the assignment, you should rather use these instead of re-inventing the wheel).



    // prefere double! float (on typical machines at least) has same size as int
    // and it is quite likely that you will lose precision due to rounding; I
    // personally would rather use int64_t instead, so you won't run into rounding
    // issues even with double and you'd need quite a large amount of summands
    // before overflow can occur...
    float getTotal(const int numbers) // just one single number???

    total = sum(numbers);
    // index operator cannot be applied on a single int; additionally, you need
    // to provide an argument; where is 'sum' function defined at all???

    return total;


    // prefer double again
    double getStandardDeviation(int sizeofArray, float numbers) // const
    // (free standing functions cannot be const)

    // mean isn't declared/defined anywhere (average instead?)!
    // and you need to declare and initialize the sum appropriately:
    double sum = 0.0;

    float deviation1;
    for (int i = 0; i < sizeofArray; i++)
    sum += (mean - numbers[i]) * (mean - numbers[i]);
    // ^ you need to add, if you want to build sum

    // why two variables, even both of same type???
    deviation1 = sqrt(sum / sizeofArray - 1);
    float deviation = deviation1;

    return deviation;

    // simplest: drop both deviation and deviation 1 and just do:
    return sqrt(sum / sizeofArray - 1);



    Finally: I don't think that you'd use the resulting string (below) for anything else than printing out to console again, so I'd output to std::cout directly (naming the function 'print'); if at all, I'd provide a std::ostream as parameter to be more flexible:



    void print(std::ostream& sout)

    sout << "STATISTICAL ANALYSIS OF RANDOMLY GENERATED NUMBERS" << endl;
    sout << "====================================================" << endl;
    sout << left << "Lowest Number:" << left << getLowest() << endl;
    sout << left << "Highest Number:" << left << getHighest() << endl;
    sout << left << "Numbers Total:" << left << getTotal() << endl;
    sout << left << "Numbers Averge:" << left << getAverage() << endl;
    sout << left << "Numbers of Standard Deviation:" << left
    << getStandardDeviation() << endl;



    Now you could pass std::cout to, a std::ostringstream object or even write to file via a std::ofstream...



    int ​​main()

    Analyzer a, b, c; // b, c added by me for illustration only

    a + 100;
    // the operator accepts another Analyzer object, so you could do
    c = a + b;

    cout << a; // there's no operator<< overload for Analyzer class


    // it is HERE where you'd call all your getXZY functions!

    return 0;






    share|improve this answer



























      1














      Your assignment is to use operator overloading to solve the issues - but you actually don't do so anywhere (apart from the operator+ for your Analyzer class – which is meaningless, though).



      Reading your lines, I'd rather assume that you're supposed to write separate classes for each task:



      class Minimum

      std::vector<int> const& values
      public:
      Minimum(std::vector<int> const& values) : values(values)
      // calculates minimum / lowest value from member:
      int operator()();
      ;
      class Maximum

      public:
      //Maximum(); not needed in this variant

      // calculates maximum from parameter
      int operator()(std::vector<int> const& values);
      ;

      void test()

      std::vector<int> values(10, 12, 7);
      int min = Minimum(values)();
      int max = Maximum()(values);



      These are two different patterns, for consistency, you should select one and implement all classes alike. In first approach, you can access the vector from any member function without having to pass it around as parameter, in second approach, you can re-use one and the same object to calculate the value on several different vectors (you could still maintain a pointer to the vector to avoid passing it around via parameters...).



      Coming back to your original code, unfortunately it is full of errors



      vector<int> numbers;
      int min = numbers[0]; // vector is yet empty! undefined behaviour!
      int max = numbers[0];


      Actually, you might want not to use globals at all, see later...



      //int sizeofArray; // use numbers.size() instead!

      // not an error, but questionable: you have a std::vector already, why do you
      // fall back to C-style raw arrays?
      void randNumbers(int sizeofArray, int* numbers)
      // ^ array of pointers???

      for (int index = 0; index < sizeofArray; index++)

      numbers[index] = (numbers() % 499) + 100;
      // you certainly intended to use rand function

      // return; // just plain obsolete


      // vector variant:
      void randNumbers(unsigned int numberOfValues, std::vector<int>& destination)
      // ^ not how many numbers ARE in,
      // but how many SHALL be inserted

      // assuming we want to re-use this function and guarantee that EXACTLY
      // 'numberOfValues' values are contained:
      destination.clear(); // there might have been some values in already...

      // assure sufficently internal memory pre-allocated to prevent
      // multiple re-allocations during filling the vector:
      destination.reserve(numberOfValues);

      while(numberOfValues--)

      numbers.push_back(rand() * 500 / RAND_MAX + 100);
      // modulus is unprecise; this calculation will give you better
      // distribution
      // however, rather prefer modern C++ random number generators!
      // IF you use rand: assure that you call srand, too, but exactly ONCE,
      // best right when entering main function



      // C++ random number generator:
      void randNumbers(unsigned int numberOfValues, std::vector<int>& destination)

      static std::uniform_int_distribution<> d(100, 599);
      static std::mt19937 g;

      destination.clear();
      destination.reserve(numberOfValues);
      while(numberOfValues--)

      numbers.push_back(d(g));




      Now you have contradicting function declarations:



      int getLowest(const int, int);
      void getLowest(const int numbers, int sizeofArray) /* ... */

      int lowest = getLowest(numbers, sizeofArray);
      // again: the vector is yet empty!
      // so you certainly won't get the result desired
      // however, this won't compile at all: numbers is a std::vector,
      // but parameter type is array, so you need:
      int lowest = getLowest(numbers.data(), numbers.size());
      // ^ replaced the redundant global as well
      // move this into your main function AFTER having filled the vector!

      // picking int as return value:
      int getLowest(const int numbers, unsigned int sizeofArray)

      // you'd now have to initialize the global first; better, though:
      // return a local variable:

      // this assumes that there is at least one element in! check before usage
      // and decide what would be the appropriate error handling if the vector
      // is empty (return 0? return INT_MIN? throw an execption?)
      int min = numbers[0];

      for (int i = 1; i < sizeofArray; i++)

      if (min > numbers[i])

      min = numbers[i];
      // min = lowest; // don't overwrite the minimum again!



      // returning at end of void function is obsolete, don't do that explicitly
      // well, with int as return value, as is NOW, you NEED to return:
      return min;



      Maximum analogously, be aware that you did not change the comparison from > to <! Be aware that there are already std::min_element, std::max_element and std::minmax_element which do the same (if not prohibited by the assignment, you should rather use these instead of re-inventing the wheel).



      // prefere double! float (on typical machines at least) has same size as int
      // and it is quite likely that you will lose precision due to rounding; I
      // personally would rather use int64_t instead, so you won't run into rounding
      // issues even with double and you'd need quite a large amount of summands
      // before overflow can occur...
      float getTotal(const int numbers) // just one single number???

      total = sum(numbers);
      // index operator cannot be applied on a single int; additionally, you need
      // to provide an argument; where is 'sum' function defined at all???

      return total;


      // prefer double again
      double getStandardDeviation(int sizeofArray, float numbers) // const
      // (free standing functions cannot be const)

      // mean isn't declared/defined anywhere (average instead?)!
      // and you need to declare and initialize the sum appropriately:
      double sum = 0.0;

      float deviation1;
      for (int i = 0; i < sizeofArray; i++)
      sum += (mean - numbers[i]) * (mean - numbers[i]);
      // ^ you need to add, if you want to build sum

      // why two variables, even both of same type???
      deviation1 = sqrt(sum / sizeofArray - 1);
      float deviation = deviation1;

      return deviation;

      // simplest: drop both deviation and deviation 1 and just do:
      return sqrt(sum / sizeofArray - 1);



      Finally: I don't think that you'd use the resulting string (below) for anything else than printing out to console again, so I'd output to std::cout directly (naming the function 'print'); if at all, I'd provide a std::ostream as parameter to be more flexible:



      void print(std::ostream& sout)

      sout << "STATISTICAL ANALYSIS OF RANDOMLY GENERATED NUMBERS" << endl;
      sout << "====================================================" << endl;
      sout << left << "Lowest Number:" << left << getLowest() << endl;
      sout << left << "Highest Number:" << left << getHighest() << endl;
      sout << left << "Numbers Total:" << left << getTotal() << endl;
      sout << left << "Numbers Averge:" << left << getAverage() << endl;
      sout << left << "Numbers of Standard Deviation:" << left
      << getStandardDeviation() << endl;



      Now you could pass std::cout to, a std::ostringstream object or even write to file via a std::ofstream...



      int ​​main()

      Analyzer a, b, c; // b, c added by me for illustration only

      a + 100;
      // the operator accepts another Analyzer object, so you could do
      c = a + b;

      cout << a; // there's no operator<< overload for Analyzer class


      // it is HERE where you'd call all your getXZY functions!

      return 0;






      share|improve this answer

























        1












        1








        1






        Your assignment is to use operator overloading to solve the issues - but you actually don't do so anywhere (apart from the operator+ for your Analyzer class – which is meaningless, though).



        Reading your lines, I'd rather assume that you're supposed to write separate classes for each task:



        class Minimum

        std::vector<int> const& values
        public:
        Minimum(std::vector<int> const& values) : values(values)
        // calculates minimum / lowest value from member:
        int operator()();
        ;
        class Maximum

        public:
        //Maximum(); not needed in this variant

        // calculates maximum from parameter
        int operator()(std::vector<int> const& values);
        ;

        void test()

        std::vector<int> values(10, 12, 7);
        int min = Minimum(values)();
        int max = Maximum()(values);



        These are two different patterns, for consistency, you should select one and implement all classes alike. In first approach, you can access the vector from any member function without having to pass it around as parameter, in second approach, you can re-use one and the same object to calculate the value on several different vectors (you could still maintain a pointer to the vector to avoid passing it around via parameters...).



        Coming back to your original code, unfortunately it is full of errors



        vector<int> numbers;
        int min = numbers[0]; // vector is yet empty! undefined behaviour!
        int max = numbers[0];


        Actually, you might want not to use globals at all, see later...



        //int sizeofArray; // use numbers.size() instead!

        // not an error, but questionable: you have a std::vector already, why do you
        // fall back to C-style raw arrays?
        void randNumbers(int sizeofArray, int* numbers)
        // ^ array of pointers???

        for (int index = 0; index < sizeofArray; index++)

        numbers[index] = (numbers() % 499) + 100;
        // you certainly intended to use rand function

        // return; // just plain obsolete


        // vector variant:
        void randNumbers(unsigned int numberOfValues, std::vector<int>& destination)
        // ^ not how many numbers ARE in,
        // but how many SHALL be inserted

        // assuming we want to re-use this function and guarantee that EXACTLY
        // 'numberOfValues' values are contained:
        destination.clear(); // there might have been some values in already...

        // assure sufficently internal memory pre-allocated to prevent
        // multiple re-allocations during filling the vector:
        destination.reserve(numberOfValues);

        while(numberOfValues--)

        numbers.push_back(rand() * 500 / RAND_MAX + 100);
        // modulus is unprecise; this calculation will give you better
        // distribution
        // however, rather prefer modern C++ random number generators!
        // IF you use rand: assure that you call srand, too, but exactly ONCE,
        // best right when entering main function



        // C++ random number generator:
        void randNumbers(unsigned int numberOfValues, std::vector<int>& destination)

        static std::uniform_int_distribution<> d(100, 599);
        static std::mt19937 g;

        destination.clear();
        destination.reserve(numberOfValues);
        while(numberOfValues--)

        numbers.push_back(d(g));




        Now you have contradicting function declarations:



        int getLowest(const int, int);
        void getLowest(const int numbers, int sizeofArray) /* ... */

        int lowest = getLowest(numbers, sizeofArray);
        // again: the vector is yet empty!
        // so you certainly won't get the result desired
        // however, this won't compile at all: numbers is a std::vector,
        // but parameter type is array, so you need:
        int lowest = getLowest(numbers.data(), numbers.size());
        // ^ replaced the redundant global as well
        // move this into your main function AFTER having filled the vector!

        // picking int as return value:
        int getLowest(const int numbers, unsigned int sizeofArray)

        // you'd now have to initialize the global first; better, though:
        // return a local variable:

        // this assumes that there is at least one element in! check before usage
        // and decide what would be the appropriate error handling if the vector
        // is empty (return 0? return INT_MIN? throw an execption?)
        int min = numbers[0];

        for (int i = 1; i < sizeofArray; i++)

        if (min > numbers[i])

        min = numbers[i];
        // min = lowest; // don't overwrite the minimum again!



        // returning at end of void function is obsolete, don't do that explicitly
        // well, with int as return value, as is NOW, you NEED to return:
        return min;



        Maximum analogously, be aware that you did not change the comparison from > to <! Be aware that there are already std::min_element, std::max_element and std::minmax_element which do the same (if not prohibited by the assignment, you should rather use these instead of re-inventing the wheel).



        // prefere double! float (on typical machines at least) has same size as int
        // and it is quite likely that you will lose precision due to rounding; I
        // personally would rather use int64_t instead, so you won't run into rounding
        // issues even with double and you'd need quite a large amount of summands
        // before overflow can occur...
        float getTotal(const int numbers) // just one single number???

        total = sum(numbers);
        // index operator cannot be applied on a single int; additionally, you need
        // to provide an argument; where is 'sum' function defined at all???

        return total;


        // prefer double again
        double getStandardDeviation(int sizeofArray, float numbers) // const
        // (free standing functions cannot be const)

        // mean isn't declared/defined anywhere (average instead?)!
        // and you need to declare and initialize the sum appropriately:
        double sum = 0.0;

        float deviation1;
        for (int i = 0; i < sizeofArray; i++)
        sum += (mean - numbers[i]) * (mean - numbers[i]);
        // ^ you need to add, if you want to build sum

        // why two variables, even both of same type???
        deviation1 = sqrt(sum / sizeofArray - 1);
        float deviation = deviation1;

        return deviation;

        // simplest: drop both deviation and deviation 1 and just do:
        return sqrt(sum / sizeofArray - 1);



        Finally: I don't think that you'd use the resulting string (below) for anything else than printing out to console again, so I'd output to std::cout directly (naming the function 'print'); if at all, I'd provide a std::ostream as parameter to be more flexible:



        void print(std::ostream& sout)

        sout << "STATISTICAL ANALYSIS OF RANDOMLY GENERATED NUMBERS" << endl;
        sout << "====================================================" << endl;
        sout << left << "Lowest Number:" << left << getLowest() << endl;
        sout << left << "Highest Number:" << left << getHighest() << endl;
        sout << left << "Numbers Total:" << left << getTotal() << endl;
        sout << left << "Numbers Averge:" << left << getAverage() << endl;
        sout << left << "Numbers of Standard Deviation:" << left
        << getStandardDeviation() << endl;



        Now you could pass std::cout to, a std::ostringstream object or even write to file via a std::ofstream...



        int ​​main()

        Analyzer a, b, c; // b, c added by me for illustration only

        a + 100;
        // the operator accepts another Analyzer object, so you could do
        c = a + b;

        cout << a; // there's no operator<< overload for Analyzer class


        // it is HERE where you'd call all your getXZY functions!

        return 0;






        share|improve this answer














        Your assignment is to use operator overloading to solve the issues - but you actually don't do so anywhere (apart from the operator+ for your Analyzer class – which is meaningless, though).



        Reading your lines, I'd rather assume that you're supposed to write separate classes for each task:



        class Minimum

        std::vector<int> const& values
        public:
        Minimum(std::vector<int> const& values) : values(values)
        // calculates minimum / lowest value from member:
        int operator()();
        ;
        class Maximum

        public:
        //Maximum(); not needed in this variant

        // calculates maximum from parameter
        int operator()(std::vector<int> const& values);
        ;

        void test()

        std::vector<int> values(10, 12, 7);
        int min = Minimum(values)();
        int max = Maximum()(values);



        These are two different patterns, for consistency, you should select one and implement all classes alike. In first approach, you can access the vector from any member function without having to pass it around as parameter, in second approach, you can re-use one and the same object to calculate the value on several different vectors (you could still maintain a pointer to the vector to avoid passing it around via parameters...).



        Coming back to your original code, unfortunately it is full of errors



        vector<int> numbers;
        int min = numbers[0]; // vector is yet empty! undefined behaviour!
        int max = numbers[0];


        Actually, you might want not to use globals at all, see later...



        //int sizeofArray; // use numbers.size() instead!

        // not an error, but questionable: you have a std::vector already, why do you
        // fall back to C-style raw arrays?
        void randNumbers(int sizeofArray, int* numbers)
        // ^ array of pointers???

        for (int index = 0; index < sizeofArray; index++)

        numbers[index] = (numbers() % 499) + 100;
        // you certainly intended to use rand function

        // return; // just plain obsolete


        // vector variant:
        void randNumbers(unsigned int numberOfValues, std::vector<int>& destination)
        // ^ not how many numbers ARE in,
        // but how many SHALL be inserted

        // assuming we want to re-use this function and guarantee that EXACTLY
        // 'numberOfValues' values are contained:
        destination.clear(); // there might have been some values in already...

        // assure sufficently internal memory pre-allocated to prevent
        // multiple re-allocations during filling the vector:
        destination.reserve(numberOfValues);

        while(numberOfValues--)

        numbers.push_back(rand() * 500 / RAND_MAX + 100);
        // modulus is unprecise; this calculation will give you better
        // distribution
        // however, rather prefer modern C++ random number generators!
        // IF you use rand: assure that you call srand, too, but exactly ONCE,
        // best right when entering main function



        // C++ random number generator:
        void randNumbers(unsigned int numberOfValues, std::vector<int>& destination)

        static std::uniform_int_distribution<> d(100, 599);
        static std::mt19937 g;

        destination.clear();
        destination.reserve(numberOfValues);
        while(numberOfValues--)

        numbers.push_back(d(g));




        Now you have contradicting function declarations:



        int getLowest(const int, int);
        void getLowest(const int numbers, int sizeofArray) /* ... */

        int lowest = getLowest(numbers, sizeofArray);
        // again: the vector is yet empty!
        // so you certainly won't get the result desired
        // however, this won't compile at all: numbers is a std::vector,
        // but parameter type is array, so you need:
        int lowest = getLowest(numbers.data(), numbers.size());
        // ^ replaced the redundant global as well
        // move this into your main function AFTER having filled the vector!

        // picking int as return value:
        int getLowest(const int numbers, unsigned int sizeofArray)

        // you'd now have to initialize the global first; better, though:
        // return a local variable:

        // this assumes that there is at least one element in! check before usage
        // and decide what would be the appropriate error handling if the vector
        // is empty (return 0? return INT_MIN? throw an execption?)
        int min = numbers[0];

        for (int i = 1; i < sizeofArray; i++)

        if (min > numbers[i])

        min = numbers[i];
        // min = lowest; // don't overwrite the minimum again!



        // returning at end of void function is obsolete, don't do that explicitly
        // well, with int as return value, as is NOW, you NEED to return:
        return min;



        Maximum analogously, be aware that you did not change the comparison from > to <! Be aware that there are already std::min_element, std::max_element and std::minmax_element which do the same (if not prohibited by the assignment, you should rather use these instead of re-inventing the wheel).



        // prefere double! float (on typical machines at least) has same size as int
        // and it is quite likely that you will lose precision due to rounding; I
        // personally would rather use int64_t instead, so you won't run into rounding
        // issues even with double and you'd need quite a large amount of summands
        // before overflow can occur...
        float getTotal(const int numbers) // just one single number???

        total = sum(numbers);
        // index operator cannot be applied on a single int; additionally, you need
        // to provide an argument; where is 'sum' function defined at all???

        return total;


        // prefer double again
        double getStandardDeviation(int sizeofArray, float numbers) // const
        // (free standing functions cannot be const)

        // mean isn't declared/defined anywhere (average instead?)!
        // and you need to declare and initialize the sum appropriately:
        double sum = 0.0;

        float deviation1;
        for (int i = 0; i < sizeofArray; i++)
        sum += (mean - numbers[i]) * (mean - numbers[i]);
        // ^ you need to add, if you want to build sum

        // why two variables, even both of same type???
        deviation1 = sqrt(sum / sizeofArray - 1);
        float deviation = deviation1;

        return deviation;

        // simplest: drop both deviation and deviation 1 and just do:
        return sqrt(sum / sizeofArray - 1);



        Finally: I don't think that you'd use the resulting string (below) for anything else than printing out to console again, so I'd output to std::cout directly (naming the function 'print'); if at all, I'd provide a std::ostream as parameter to be more flexible:



        void print(std::ostream& sout)

        sout << "STATISTICAL ANALYSIS OF RANDOMLY GENERATED NUMBERS" << endl;
        sout << "====================================================" << endl;
        sout << left << "Lowest Number:" << left << getLowest() << endl;
        sout << left << "Highest Number:" << left << getHighest() << endl;
        sout << left << "Numbers Total:" << left << getTotal() << endl;
        sout << left << "Numbers Averge:" << left << getAverage() << endl;
        sout << left << "Numbers of Standard Deviation:" << left
        << getStandardDeviation() << endl;



        Now you could pass std::cout to, a std::ostringstream object or even write to file via a std::ofstream...



        int ​​main()

        Analyzer a, b, c; // b, c added by me for illustration only

        a + 100;
        // the operator accepts another Analyzer object, so you could do
        c = a + b;

        cout << a; // there's no operator<< overload for Analyzer class


        // it is HERE where you'd call all your getXZY functions!

        return 0;







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 11 at 7:51

























        answered Nov 10 at 8:38









        Aconcagua

        11.6k32143




        11.6k32143























            0














            You are passing a pointer to an array of integers:



            void randNumbers(int sizeofArray, int* numbers)


            where you really just want to pass numbers as an array. And since all arrays degrade to pointers when passed as a parameter, your function is simply this:



            void randNumbers(int sizeofArray, int* numbers) 

            for(int index = 0; index < sizeofArray; index++)
            numbers[index]= (rand() % 499) + 100;
            ;




            The result is that the items in numbers will be integers in the range of [100..599] inclusive.






            share|improve this answer




















            • I personally prefer int numbers syntax in given case, makes more obvious that really an array is expected...
              – Aconcagua
              Nov 10 at 6:35










            • @Aconcagua I detest the usage of when it is used to "hide" a pointer.
              – Swordfish
              Nov 10 at 6:38










            • @Swordfish Fine (not meant ironically!), now we are complete: pro (distinguish array from simple pointer, e. g. as additional return value) and contra (hiding pointer nature). Now up to the reader which one he/she wants to weigh stronger...
              – Aconcagua
              Nov 10 at 7:10










            • @Aconcagua i don't get your point.
              – Swordfish
              Nov 10 at 7:13










            • @Swordfish int set(int* target) target = 7; void iterate(unsigned int num, int values) while(num--) ++values; . If applied consistently (I do so with exception of C-strings), the syntax difference can be used to indicate which kind of pointer is expected (to single element or to first of array), additionally a hint what the function might do. Maybe marginal, but still...
              – Aconcagua
              Nov 10 at 7:42
















            0














            You are passing a pointer to an array of integers:



            void randNumbers(int sizeofArray, int* numbers)


            where you really just want to pass numbers as an array. And since all arrays degrade to pointers when passed as a parameter, your function is simply this:



            void randNumbers(int sizeofArray, int* numbers) 

            for(int index = 0; index < sizeofArray; index++)
            numbers[index]= (rand() % 499) + 100;
            ;




            The result is that the items in numbers will be integers in the range of [100..599] inclusive.






            share|improve this answer




















            • I personally prefer int numbers syntax in given case, makes more obvious that really an array is expected...
              – Aconcagua
              Nov 10 at 6:35










            • @Aconcagua I detest the usage of when it is used to "hide" a pointer.
              – Swordfish
              Nov 10 at 6:38










            • @Swordfish Fine (not meant ironically!), now we are complete: pro (distinguish array from simple pointer, e. g. as additional return value) and contra (hiding pointer nature). Now up to the reader which one he/she wants to weigh stronger...
              – Aconcagua
              Nov 10 at 7:10










            • @Aconcagua i don't get your point.
              – Swordfish
              Nov 10 at 7:13










            • @Swordfish int set(int* target) target = 7; void iterate(unsigned int num, int values) while(num--) ++values; . If applied consistently (I do so with exception of C-strings), the syntax difference can be used to indicate which kind of pointer is expected (to single element or to first of array), additionally a hint what the function might do. Maybe marginal, but still...
              – Aconcagua
              Nov 10 at 7:42














            0












            0








            0






            You are passing a pointer to an array of integers:



            void randNumbers(int sizeofArray, int* numbers)


            where you really just want to pass numbers as an array. And since all arrays degrade to pointers when passed as a parameter, your function is simply this:



            void randNumbers(int sizeofArray, int* numbers) 

            for(int index = 0; index < sizeofArray; index++)
            numbers[index]= (rand() % 499) + 100;
            ;




            The result is that the items in numbers will be integers in the range of [100..599] inclusive.






            share|improve this answer












            You are passing a pointer to an array of integers:



            void randNumbers(int sizeofArray, int* numbers)


            where you really just want to pass numbers as an array. And since all arrays degrade to pointers when passed as a parameter, your function is simply this:



            void randNumbers(int sizeofArray, int* numbers) 

            for(int index = 0; index < sizeofArray; index++)
            numbers[index]= (rand() % 499) + 100;
            ;




            The result is that the items in numbers will be integers in the range of [100..599] inclusive.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 10 at 6:23









            selbie

            53.9k961121




            53.9k961121











            • I personally prefer int numbers syntax in given case, makes more obvious that really an array is expected...
              – Aconcagua
              Nov 10 at 6:35










            • @Aconcagua I detest the usage of when it is used to "hide" a pointer.
              – Swordfish
              Nov 10 at 6:38










            • @Swordfish Fine (not meant ironically!), now we are complete: pro (distinguish array from simple pointer, e. g. as additional return value) and contra (hiding pointer nature). Now up to the reader which one he/she wants to weigh stronger...
              – Aconcagua
              Nov 10 at 7:10










            • @Aconcagua i don't get your point.
              – Swordfish
              Nov 10 at 7:13










            • @Swordfish int set(int* target) target = 7; void iterate(unsigned int num, int values) while(num--) ++values; . If applied consistently (I do so with exception of C-strings), the syntax difference can be used to indicate which kind of pointer is expected (to single element or to first of array), additionally a hint what the function might do. Maybe marginal, but still...
              – Aconcagua
              Nov 10 at 7:42

















            • I personally prefer int numbers syntax in given case, makes more obvious that really an array is expected...
              – Aconcagua
              Nov 10 at 6:35










            • @Aconcagua I detest the usage of when it is used to "hide" a pointer.
              – Swordfish
              Nov 10 at 6:38










            • @Swordfish Fine (not meant ironically!), now we are complete: pro (distinguish array from simple pointer, e. g. as additional return value) and contra (hiding pointer nature). Now up to the reader which one he/she wants to weigh stronger...
              – Aconcagua
              Nov 10 at 7:10










            • @Aconcagua i don't get your point.
              – Swordfish
              Nov 10 at 7:13










            • @Swordfish int set(int* target) target = 7; void iterate(unsigned int num, int values) while(num--) ++values; . If applied consistently (I do so with exception of C-strings), the syntax difference can be used to indicate which kind of pointer is expected (to single element or to first of array), additionally a hint what the function might do. Maybe marginal, but still...
              – Aconcagua
              Nov 10 at 7:42
















            I personally prefer int numbers syntax in given case, makes more obvious that really an array is expected...
            – Aconcagua
            Nov 10 at 6:35




            I personally prefer int numbers syntax in given case, makes more obvious that really an array is expected...
            – Aconcagua
            Nov 10 at 6:35












            @Aconcagua I detest the usage of when it is used to "hide" a pointer.
            – Swordfish
            Nov 10 at 6:38




            @Aconcagua I detest the usage of when it is used to "hide" a pointer.
            – Swordfish
            Nov 10 at 6:38












            @Swordfish Fine (not meant ironically!), now we are complete: pro (distinguish array from simple pointer, e. g. as additional return value) and contra (hiding pointer nature). Now up to the reader which one he/she wants to weigh stronger...
            – Aconcagua
            Nov 10 at 7:10




            @Swordfish Fine (not meant ironically!), now we are complete: pro (distinguish array from simple pointer, e. g. as additional return value) and contra (hiding pointer nature). Now up to the reader which one he/she wants to weigh stronger...
            – Aconcagua
            Nov 10 at 7:10












            @Aconcagua i don't get your point.
            – Swordfish
            Nov 10 at 7:13




            @Aconcagua i don't get your point.
            – Swordfish
            Nov 10 at 7:13












            @Swordfish int set(int* target) target = 7; void iterate(unsigned int num, int values) while(num--) ++values; . If applied consistently (I do so with exception of C-strings), the syntax difference can be used to indicate which kind of pointer is expected (to single element or to first of array), additionally a hint what the function might do. Maybe marginal, but still...
            – Aconcagua
            Nov 10 at 7:42





            @Swordfish int set(int* target) target = 7; void iterate(unsigned int num, int values) while(num--) ++values; . If applied consistently (I do so with exception of C-strings), the syntax difference can be used to indicate which kind of pointer is expected (to single element or to first of array), additionally a hint what the function might do. Maybe marginal, but still...
            – Aconcagua
            Nov 10 at 7:42




            Popular posts from this blog

            𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

            Edmonton

            Crossroads (UK TV series)