|
|
Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.
Temas - Hypocrisy
Páginas: [1]
1
« en: Martes 21 de Abril de 2009, 00:52 »
Hola...ya estoy de nuevo aqui...Al compilar un programa me sale un constante error que no consigo quitar. Se que el programa esta bien pero igualmente sale el maldito error. El error que sale es el siguiente: expected unqualified-id before "namespace" expected `,' or `;' before "namespace" [Build Error] [main.o] Error 1 El codigo es este: #include <iostream> #include <string> #include <sstream> #include <vector> #include "PaintShop.h" #include "Paint.h" #include "Tool.h" #include "PaintShopException.h" using namespace std; ---> AQUI ME MARCA EL ERROR void addPaint(PaintShop *ps, Paint* paint); void addTool(PaintShop *ps, Tool* tool); void paintInfo(PaintShop* ps, string id); int main(int argc, char *argv[]) { // Creating a PaintShop object // ------------------------- PaintShop *ps = new PaintShop(); // Creating Paint objects and adding them to the paints list of object ps // ---------------------------------------------------------------------- Paint *paintObj1 = new Paint("P1", "Plastic", "Red"); Paint *paintObj2 = new Paint("P2", "Acrylic", "Green"); Paint *paintObj3 = new Paint("P1", "Plastic", "Red"); // repeated object <---- ps->addPaint(paintObj1); ps->addPaint(paintObj2); ps->addPaint(paintObj3); // Creating Tool objects and adding them to the tools list of object ps // -------------------------------------------------------------------- Tool *toolObj1 = new Tool("T1", "Paintbrush"); Tool *toolObj2 = new Tool("T2", "Paintroller"); Tool *toolObj3 = new Tool("T1", "Paintbrusch"); // repeated object <---- ps->addTool(toolObj1); ps->addTool(toolObj2); ps->addTool(toolObj3); // Listing Paint objects Information // --------------------------------- cout << "--------------" << endl; cout << "List of paints" << endl; cout << "--------------" << endl; cout << ps->listPaints() << endl; // Listing Tool objects Information // -------------------------------- cout << "-------------" << endl; cout << "List of tools" << endl; cout << "-------------" << endl; cout << ps->listTools() << endl; // Searching Paints by its id // -------------------------- cout << "-- Information related to Paint with id = P1:" << endl; paintInfo(ps,"P1"); cout << "-- Information related to Paint with id = P3:" << endl; paintInfo(ps,"P3");// This object does not exists <---- // Comparing objects // ----------------- cout << paintObj1->equals(paintObj2) << endl; cout << paintObj1->equals(paintObj3) << endl; cout << "End of the exercise" << endl; } void addPaint(PaintShop *ps, Paint* paint) { try { ps->addPaint(paint); } catch(PaintShopException e) { cout << e.str() << endl; } } void addTool(PaintShop *ps, Tool* tool) { try { ps->addTool(tool); } catch(PaintShopException e) { cout << e.str() << endl; } } void paintInfo(PaintShop *ps, string id) { try { cout << ps->paintInfo(id) << endl; } catch(PaintShopException e) { cout << e.str() << endl; } }
Me he mirado el codigo 20 millones de veces y nose porque sale . Me he mirado las otras clases y todas estan bien..que ocurre? es un problema del dev c++¿??
2
« en: Miércoles 8 de Abril de 2009, 13:45 »
Hola de nuevo, tengo un problema bastante tonto, tengo este codigo: Cruiser *UOCTA::addCruiser(string name, int nights, float price, string departure, Ship *ship, vector<Scale*> scales) { Cruiser *ret=NULL; if (this->baseCurrency !=""){ Cruiser *scx= new Cruiser(name,nights,price,departure,*ship,Scale); cruisers.push_back(scx); return (scx); } return ret;
Para crear una nueva "lista" necesito poner "Ship *ship, vector<Scale*> scales" en Cruiser *scx= new Cruiser(name,nights,price,departure,Ship,Scale); pero nose como pasar el vector scale a la nueva instancia. Que deberia poner? :S
3
« en: Lunes 6 de Abril de 2009, 19:55 »
Buenas...tengo un problema bastante tonto...llevo dias y dias dandolo vueltas y nada...A ver si me podeis hechar una mano Tngo este codigo : int main(int argc, char *argv[]) { // Creation of a list of cars vector<Car *> cars; // Adding cars to the list Car *c1= new Car("AAA1111", "Leon"); cars.push_back(c1); Car *c2= new Car("BBB2222", "Sierra"); cars.push_back(c2); Car *c3= new Car("ZZZ8888", "Alhambra"); cars.push_back(c3); Car *c4= new Car("FFF4444", "Mondeo"); cars.push_back(c4); Car *c5= new Car("NNN0000", "Avensis");
// Let's print to the console all the cars in the list cout << listCars(cars) << endl; Tengo que hacer la parte de codigo que se encargue de hacer la lista y lo maximo que he conseguido hacer es esto : string listCars(vector<Car*> cars) { stringstream res; int suma; for (int i = 0; i<5; i++){ suma+= cars;
res<< cars->str(); }
return (res.str()); }
str es esto:: string Car::str() { stringstream res; res << "plate:" << this->getPlate(); res << " model:" << getModel(); return res.str(); }
El codigo que crea la lista no funciona.... y nose porque...me podeis dar alguna pista --_--''
4
« en: Viernes 20 de Marzo de 2009, 15:49 »
Hola...Tengo otro problemilla  Antes de todo, he estado probando la libreria Time.h pero nada... El problema que tengo es que tengo la siguiente cadena: StudentCraft *player1 = new StudentCraft("user1","Sandra","Varillas","19920323"); y despues tengo que pasar el 19920323 a fecha: 23 mar 1992 y no consigo pasarla. El codigo es este: } string StudentCraft::str(){ cout<< "****************************" << endl; cout << "PlayerSummary:" << getUsername()<< endl; cout << "Name:" << getName()<<endl; cout << "Surname:" << getSurname()<<endl; cout << "Birthdate:" << getBirthdate()<<endl;<--linea que me da problemas. cout << "Classroom:" << getClassRoom()<<endl; cout << "Practices:" << getPractices()<<endl; cout << "Energy:" << getEnergy()<<endl; cout << "Knowledge:"<< getKnowledge()<<endl; cout << "*****************************" <<endl; } Como podria solucionar el problemilla¿?
5
« en: Jueves 19 de Marzo de 2009, 00:00 »
Buenas!!Soy nuevo en la pagina y estoy intentando encontrar algo de ayuda ya que no se que hacer mas con este maldito codigo. Estoy haciendo un pequeño juego pero tengo el problema de que ve que esta el codigo perfecto pero cuando lo ejecuto no hace nada. El juego es un trabajo de la uni y el tema trata de atributos, metodos, herencia y poliformismo. Creo que la parte de la constructora esta perfecto pero despues es como si no hiciese nada de caso de ella. Os pongo el codigo a ver que os parece.. Este es el Studentcraft.cpp #include "StudentCraft.h" #include <string> using namespace std; StudentCraft::StudentCraft(string username,string name,string surname,string birthdate){} string StudentCraft::getName(){return name;} string StudentCraft::getSurname(){ return surname;} string StudentCraft::getUsername(){ return username;} string StudentCraft::getBirthdate(){return birthdate;} int StudentCraft::getClassRoom(){return classroom=0;} int StudentCraft::getEnergy(){return energy = MAX_ENERGY;} int StudentCraft::getKnowledge(){return knowledge=0;} void StudentCraft::assignClassroom(int idClassroom){ classroom= idClassroom; knowledge= INITIAL_KNOWLEDGE; } void StudentCraft::studyModule(){ knowledge=knowledge + (INCREASE_KNOWLEDGE_MO); energy= energy - (DECREASE_ENERGY_MO); } void StudentCraft::realizeAC(){ knowledge=knowledge + (INCREASE_KNOWLEDGE_AC); energy= energy -(DECREASE_ENERGY_AC); } void StudentCraft::increaseEnergy(){ energy=MAX_ENERGY; } StudentCraft::~StudentCraft() {} int StudentCraft::MAX_ENERGY = 1000; int StudentCraft::OVERLOAD_INITIAL_ENERGY = 100; int StudentCraft::INITIAL_KNOWLEDGE = 50; int StudentCraft::INCREASE_KNOWLEDGE_AC = 70; int StudentCraft::DECREASE_ENERGY_AC = 100; int StudentCraft::INCREASE_KNOWLEDGE_MO = 50; int StudentCraft::DECREASE_ENERGY_MO = 70;
Este es el StudentCraft.h #ifndef STUDENTCRAFT_H_ #define STUDENTCRAFT_H_
#include <string>
using namespace std;
class StudentCraft
{ private: /** Identifies the user on World of UocCraft (WoU) */ string username; /** Real player's name */ string name; /** player's surname */ string surname; /** player's birthdate. Must follow YYYYMMDD format */ string birthdate; /** actual energy level of the player */ int energy; /** actual knowledge level of the player */ int knowledge; /** classroom code of the player-student */ int classroom;
static int MAX_ENERGY; static int OVERLOAD_INITIAL_ENERGY ;
static int INITIAL_KNOWLEDGE;
static int INCREASE_KNOWLEDGE_AC; static int DECREASE_ENERGY_AC;
static int INCREASE_KNOWLEDGE_MO; static int DECREASE_ENERGY_MO;
public: /** Constructor method. * Creates a new instance of StudentCraft * @param username of the player * @param name of the player * @param surname of the player * @param birthdate of the player */ StudentCraft(string username, string name, string surname, string birthdate); /**getter of classroom*/ int getClassRoom(); /**getter of getEnergy*/ int getEnergy(); /**getter of Knowledge*/ int getKnowledge(); /**getter of name*/ string getName(); /**getter of surname*/ string getSurname(); /**getter of username*/ string getUsername(); string getBirthdate(); /** assigns a new classrom to the student * @param idClassroom the classroom code */ void assignClassroom (int idClassroom); /**Increments the knowledge of the player in INCREASE_KNOWLEDGE_MO and decreases his energy DECREASE_ENERGY_MO */ void studyModule(); /**Increments the knowledge of the player in INCREASE_KNOWLEDGE_AC and decreases his energy DECREASE_ENERGY_AC */ void realizeAC(); /**Increments the energy of the player to the maximum */ void increaseEnergy();
virtual ~StudentCraft(); };
#endif /*STUDENTCRAFT_H_*/
Y este es UOCCraft.cpp que es el que me esta dando problemas, es la parte que se encarga de ejecutar todo el programa. #include <iostream> #include "StudentCraft.h"
using namespace std;
/** * AirUOC class demo program */
int main(int argc, char *argv[]) { StudentCraft *player1 = new StudentCraft("user1","Sandra","Varillas","19920223"); StudentCraft *player2 = new StudentCraft("user2","Federico","Taulet","197010,15"); StudentCraft *player3 = new StudentCraft("user3","Feliciano","Vargas","19800709");
// Display what we've got-> cout << "Player " << player1->getUsername() << ": name -> " << player1->getName() << " | surname -> " << player1->getSurname() << " | energy -> " << player1->getEnergy() << " | knowledge -> " << player1->getKnowledge() << " | classroom -> " << player1->getClassRoom() << endl; cout << "Player " << player2->getUsername() << ": name -> " << player2->getName() << " | surname -> " << player2->getSurname() << " | energy -> " << player2->getEnergy() << " | knowledge -> " << player2->getKnowledge() << " | classroom -> " << player1->getClassRoom() << endl; cout << "Player " << player3->getUsername() << ": name -> " << player3->getName() << " | surname -> " << player3->getSurname() << " | energy -> " << player3->getEnergy() << " | knowledge -> " << player3->getKnowledge() << " | classroom -> " << player1->getClassRoom() << endl;
player1->assignClassroom(327); player2->assignClassroom(327); player3->assignClassroom(327);
player1->studyModule(); player1->studyModule(); player1->studyModule();
player1->realizeAC(); player1->realizeAC(); player1->increaseEnergy();
player2->realizeAC(); player2->realizeAC(); player2->realizeAC();
player3->increaseEnergy(); player3->increaseEnergy();
player3->studyModule(); player3->studyModule(); player3->studyModule();
// Display what we've got-> cout << "Player " << player1->getUsername() << ": name -> " << player1->getName() << " | surname -> " << player1->getSurname() << " | energy -> " << player1->getEnergy() << " | knowledge -> " << player1->getKnowledge() << " | classroom -> " << player1->getClassRoom() << endl; cout << "Player " << player2->getUsername() << ": name -> " << player2->getName() << " | surname -> " << player2->getSurname() << " | energy -> " << player2->getEnergy() << " | knowledge -> " << player2->getKnowledge() << " | classroom -> " << player1->getClassRoom() << endl; cout << "Player " << player3->getUsername() << ": name -> " << player3->getName() << " | surname -> " << player3->getSurname() << " | energy -> " << player3->getEnergy() << " | knowledge -> " << player3->getKnowledge() << " | classroom -> " << player1->getClassRoom() << endl; }
Bueno...a ver que os parece, y a ver que podeis decir...muchas gracias de antemano.
Páginas: [1]
|
|
|