Je dois concevoir et mettre en œuvre un programme pour accomplir l'adaptation du bâton de tambour (pas celui de manger). Il y a deux paramètres que je dois vérifier: i.e Poids et Hauteur (propriété acoustique) pour les deux pilons différents et trouver la paire de pilon correspondant. J'ai créé trois classes i.e Bin, Sorter et Stick et dans la description du projet, la classe Robot est donnée et c'est la classe stub.Stubs et le programme principal
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
Je veux passer toute ma logique à la classe principale, puisque mon professeur m'a dit que cette classe de robot est fausse classe (de talons), donc je créé quelques-uns des load_sticks méthode int (nombre int) mais je J'ai une erreur dans la déclaration
my_sorter = new Sorter();
my_bin = new Bin();
dans la classe principale. Je ne sais pas comment je peux instancier ces objets dans la classe principale. Quelqu'un pourrait-il me dire ce que je devrais faire avec cela?
Ceci est mon code pour le fichier source de la classe Robot. Je peux aussi poster mes autres cours mais je veux juste travailler sur ce problème. J'espère que l'on peut comprendre avec cette classe seulement.
#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();
}
Je supprimé toutes les autres méthodes afin qu'il soit lisible à tous
// 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 - Il n'est pas «cool» de générer un nouvel ID SO chaque fois que vous postez une question –
Je ne l'ai pas fait intentionnellement, je ne sais pas comment ouvrir mon compte. – cool
Donc, cette fois, je me suis inscrit. Désolé pour le dérangement. – cool