I have to design and implement a program to accomplish drum stick matching (not the eating one). There are two parameters I have to check i.e Weight and Pitch (acoustical property) for the two different drumstick and find pair of matching drumstick. I created three classes i.e Bin, Sorter and Stick and in project description Robot class is given and this is stub class.
Robot
+WEIGHT_TOLERANCE: int
+PITCH_TOLERANCE: int
+get_new_bin(void): bool
+is_bin_empty(void):bool
+load_sticks(number:int):int
+test_stick(location: int, pitch: int, weight: int): bool
+pair_sticks(first_location: int, second_location: int): bool
+return_sticks(void): bool
I want to shift all my logic to the main class, since my professor told me that this Robot class is fake class (stubs), so I created some of the method int load_sticks(int number) but I am having error in declaring
my_sorter = new Sorter();
my_bin = new Bin();
in the main class. I do not know how can I instantiate these object in main class. Could any one tell me what should I do with this?
This is my code for Robot class source file. I can post my other classes also but I just want to work on this problem. I hope one can understand with this class only.
#include "Robot.h"
#include<iostream>
#include <string>
#include "Sorter.h"
#include "Bin.h"
#include "Stick.h"
using namespace std;
// Default constructor
Robot::Robot(void)
{
WEIGHT_TOLERANCE = 3;
PITCH_TOLERANCE = 20;
my_sorter = new Sorter();
my_bin = new Bin();
}
I removed all other methods so that it will be readable to all
// Load sticks into the sorter from the bin
int Robot::load_sticks(int number){
// Declare and initialize the int sticks_loaded to be returned
int sticks_loaded = 0;
// Verify the number of sticks requested to be loaded doesn't exceed the number in the bin
//if(number < my_bin->get_size()){
/* If the number of sticks requested plus the current size of the sorter is less than the sorter's maximum
* capacity, add the number of sticks requested
*/
if((my_sorter->get_size() + number) <= 200)
{
sticks_loaded = number;
// Load the number of sticks requested
for(int i = 0; i < number; i++)
{
// Call the load() method in the sorter class to add each stick to the sorter
my_sorter->load(my_bin->get(i));
}
// Remove the sticks that have been added to the sorter from the bin
my_bin->remove(0, number);
// After the sticks have been loaded, sort the sticks in the sorter
my_sorter->sort_sticks();
// Print out the contents of the sorter after loading
cout << *my_sorter << endl;
}
/* If the number requested plus the current size of the sorter exceeds the sorter's capacity,
* add sticks to the sorter until it has reached it's capacity
*/
if((my_sorter->get_size() + number) > 200)
{
cout << "Requested too many!" << endl;
// sticks_loaded = the maximum capacity of the sorter minus it's current size
sticks_loaded = 200-(my_sorter->get_size());
cout << "Sticks can load: " << sticks_loaded << endl;
for(int i = 0; i < sticks_loaded; i++)
{
// Load the sticks from the bin into the sorter
my_sorter->load(my_bin->get(i));
}
// Remove the sticks which were added to the sorter from the bin
my_bin->remove(0, sticks_loaded);
// Sort the sticks after loading
my_sorter->sort_sticks();
// Output the contents of the sorter after loading
cout << *my_sorter << endl;
}
return sticks_loaded;
}