Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1115501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:09:53+00:00 2026-05-17T03:09:53+00:00

I have to design and implement a program to accomplish drum stick matching (not

  • 0

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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T03:09:54+00:00Added an answer on May 17, 2026 at 3:09 am

    I suggest you create yourself a minimal test case without most of the infrastructure, just concentrating on why the my_sorter = new Sorter(); statement fails.

    #include <Sorter.h>
    void dummy(void)
    {
        Sorter *my_sorter = new Sorter();
        delete my_sorter;
    }
    

    Does this compile? If not, fix it. If so, complicate it:

    #include <Sorter.h>
    struct x { Sorter *my_sorter; };
    void dummy(void)
    {
        x dummy;
        x.my_sorter = new Sorter();
        delete x.my_sorter;
    }
    

    Etc.

    I note that Sorter.h should be self-contained – someone using the class defined in the header should not need any other headers pre-included.

    Repeat for the Bin class if the problem isn’t already self-evident. And progress from there. Make sure you’re using a VCS so that you don’t lose track of where you are and can retreat if you find yourself headed down a blind alley.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.