In need of immediate help!
Dec 6, 2014 at 4:16am UTC
I cannot figure out what I am supposed to increment in my aHistogram class since it is a vector itself through inheritance, this is the only thing I cannot figure out, I have completed the rest of the project successfully I just cannot figure this one part out. Any assistance would be great, since it is due in an hour :(
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#ifndef AHISTOGRAM_H
#define AHISTOGRAM_H
#include <iostream>
#include <vector>
using namespace std;
class aHistogram : public aDie
{
public :
aHistogram(); // default constructor
void update(int face); // update histogram counts
void display(int maxLengthOfLine); // displays histogram
void clear(); // clears counts
vector<int > graph;
private :
int i;
int face;
int maxLengthOfLine;
};
#endif
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include "aDie.h"
#include "aHistogram.h"
using namespace std;
aHistogram::aHistogram() // default constructor
{
face = ((rand() % 6) + 1);
maxLengthOfLine = 60;
graph.resize(6);
}
void aHistogram::update(int face) // updates roll count
{
this -> ; //NEED HELP HERE
}
void aHistogram::display(int maxLengthOfLine) // displays results
{
int i;
cout << "Face Appearances" << endl; // displays the appearances of each face
cout << endl;
for (i = 0; i < graph.size(); ++i)
{
cout << i + 1 << "---" << graph.at(i) << endl;
}
cout << endl;
cout << "Histogram" << endl; // displays the histogram count
cout << endl;
for (i = 0; i < graph.size(); ++i)
{
cout << i + 1 << " - " ;
while (graph.at(i) > maxLengthOfLine)
{
cout << "X" ;
graph.at(i) -= maxLengthOfLine;
}
cout << endl;
}
}
void aHistogram::clear() // clears the counts for the appearances of each face
{
face = 0;
maxLengthOfLine = 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include "aDie.h"
#include "aHistogram.h"
using namespace std;
int main()
{
int i;
srand(time(0)); // seeding RNG
aDie* Die1;
aHistogram* Die2;
vector<aDie*> DiceRoll(12000);
Die1 = new aDie;
Die2 = new aHistogram;
for (i = 0; i < DiceRoll.size(); ++i) //rolls die and updates 12000 times
{
Die2->Roll();
Die2->update(6);
}
Die2->display(60);
cin.ignore();
return 0;
}
Last edited on Dec 6, 2014 at 4:25am UTC
Topic archived. No new replies allowed.