I NEED TO KNOW HOW TO ACCESS EACH INDIVIDUAL SQUIRRELS ATTRIBUTES SUCH AS SKIP FACTOR AND LOCATION ON EACH ROUND!
Ok I think the header files and cpp files are correct. The program is compiling as-is right.
Odd round: squirrel goes to tree and gets a nut unless there is a another squirrel, then no nut.
Even round: squirrel goes to hoard and deposits nuts.
I need to be able to display----
Round 1:
Squirrel 1 went to tree 3 and got 1 nut
squirrel 2 went to .......
squirrel 3 went to. ... . ..
Tree 1 has 19 nuts left
Tree 2 has .....
Round 2:
Squirrel 1 has deposited
squirrel 2 didnt deposit due to fighting
.....
This is why I need to be able to access the values inside of each Squirrel
#include <iostream>
#include <iomanip>
#include <cstddef>
#include"squirrel.h"
#include"tree.h"
#include"hoard.h"
#include"nut.h"
usingnamespace std;
int main(){
int num_of_squirrels;
int num_of_trees;
int skip_factor;
Squirrel squirrel;
Tree nut;
cout << "Please enter the number of squirrels: ";
cin >> num_of_squirrels;
cout << "Please enter the number of trees: ";
cin >> num_of_trees;
//Creating the correct amount
Squirrel *squirrels = new Squirrel[num_of_squirrels];
Hoard *hoards = new Hoard [num_of_squirrels];
Tree *trees = new Tree[num_of_trees];
//Getting and setting skip factor
for(int i=1;i<num_of_squirrels+1;++i){
cout << "Please enter the skip factor " <<"for squirrel # "<<i<<": ";
cin >> skip_factor;
int *location=newint[num_of_squirrels - i];
squirrel.set_skip_factor(skip_factor);
}
}
#pragma once
#include <iostream>
#include "hoard.h"
#include "nut.h"
#include "squirrel.h"
class Tree;
class Nut;
class Squirrel;
class Hoard;
class Tree{
Nut *nuts;
public:
Nut* remove_nut();
int get_nuts_left();
int nuts_left;
~Tree();
Tree();
};
#pragma once
#include <iostream>
#include "tree.h"
#include "nut.h"
#include "squirrel.h"
class Hoard;
class Squirrel;
class Tree;
class Nut;
class Hoard{
Squirrel* owner;
Nut *nuts;
int number_of_nuts;
public:
int add_nut(Nut *nut);
int get_number_of_nuts();
Hoard();
~Hoard();
};
nut.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#pragma once
#include <iostream>
#include "hoard.h"
#include "tree.h"
#include "squirrel.h"
class Nut;
class Nut
{
public:
Nut();
};
By all means. It is all right there so you can copy and paste I guess. I really need help accessing and setting the attributes of the squirrel. It compiles as is though.
Ok I think the header files and cpp files are correct.
main(){???
Better to explicitly type int as some compilers will flag this as error, even though int may be a default return type.
In line 30(main.cpp) change to: squirrel[i-1].set_skip_factor(skip_factor); as your previous code deals only with squirrel[0].
Also, in C++, arrays are zero-based, so I think you would want to revisit the for loop in main.cpp(also for other problems).
What's with the pointer location? for your info, this wastes memory as it is created and uses new memory each time the loop iterates. Consider using the keyword static.