Question

C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will...

C++ programming question, please help! Thank you so much in advance!!!

In this exercise, you will work with 2 classes to be used in a RPG videogame.

The first class is the class Character. The Character class has two string type properties: name and race. The Character class also has the following methods:

  • a constructor Character(string Name, string Race), that will set the values for the name and the race variables
  • set/get functions for the two attributes
  • a function print(), that will print the name and the race in the following format:
Character Name: <name>
Character Race: <race>

The Character class is already implemented.

You will have to implement another class, called Wizard, which inherits from the Character class. The Wizard class has two attributes: an array of strings called listOfSpell and an integer amountOfSpell. The array of string is of fixed size 10, which is the maximum number of spells a Wizard can know. The amountOfSpell variable indicates how many spells the Wizard knows. The Wizard class has the following methods:

  • a constructor that will receive two string parameters (name and race). A new Wizard knows 0 spells.
  • a method AddSpell, which takes a spell (string) as parameter and adds it to the listOfSpell. The method also increases amountOfSpell and returns its updated value.
  • a method CastSpell, which takes an integer parameter and returns the spell at the given position.
  • an overloaded method Print() to print wizard name, race and all the spells if they are greater than zero, in the following format
Wizard information:
Character Name: <name>
Character Race: <race>
Spells:
<spell1>
<spell2>
...

When the Wizard class is complete, uncomment the main to complete all tests.

main.cpp:

#include <iostream>
//Add headers!

int main() {

// Uncomment when ready to test Wizard class
/*
string name, race, spell;
getline(cin,name);
getline(cin,race);

Wizard wiz(name,race);

getline(cin,spell);
int numberSpell=wiz.AddSpell(spell);

getline(cin,spell);
numberSpell = wiz.AddSpell(spell);

getline(cin,spell);
numberSpell = wiz.AddSpell(spell);

cout << "Wizard information:" << endl;
wiz.Print();

cout << "Number of spells available: " << numberSpell << endl;

int no;
cin >> no;
cout << "Spell casted: " << wiz.CastSpell(no) << endl;
*/

return 0;
}

character.h:

#ifndef CHARACTER_H
#define CHARACTER_H

#include <iostream>
#include <string>
using namespace std;

class Character {
private:
string name;
string race;
public:
Character(string name, string race);
void SetName(string name);
string getName() const;
void SetRace(string name);
string getRace() const;
void Print();
};

#endif

character.cpp:

#include <iostream>
#include "character.h"
using namespace std;

Character::Character(string Name,string Race){
name=Name;
race=Race;
}

void Character::SetName(string Name){
name=Name;
}

string Character::getName()const {
return name;
}

void Character::SetRace(string Race){
race=Race;
}

wizard.h:

#ifndef WIZARD_H
#define WIZARD_H

#include <iostream>
#include <string>
#include "character.h"
using namespace std;

class Wizard : public Character {
private:
//...
public:
//...
};

#endif

wizard.cpp:

#include <iostream>
#include "wizard.h"
using namespace std;

//Constructor:
//...


string Wizard::CastSpell(int num){
//...
}

int Wizard::AddSpell(string spell){
//...
}

void Wizard:: Print(){
//...
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I’ve completed the Wizard class in wizard.h and wizard.cpp and also completed the remaining functions in character.cpp.

Run main.cpp, character.cpp and wizard.cpp simultaneously.

Code:

//main.cpp:

#include <iostream>

#include "character.h"

#include "wizard.h"

using namespace std;

int main() {

// Uncomment when ready to test Wizard class

string name, race, spell;

getline(cin,name);

getline(cin,race);

Wizard wiz(name,race);

getline(cin,spell);

int numberSpell=wiz.AddSpell(spell);

getline(cin,spell);

numberSpell = wiz.AddSpell(spell);

getline(cin,spell);

numberSpell = wiz.AddSpell(spell);

cout << "Wizard information:" << endl;

wiz.Print();

cout << "Number of spells available: " << numberSpell << endl;

int no;

cin >> no;

cout << "Spell casted: " << wiz.CastSpell(no) << endl;

return 0;

}

//character.h:

#ifndef CHARACTER_H

#define CHARACTER_H

#include <iostream>

#include <string>

using namespace std;

class Character {

private:

    string name;

string race;

public:

    Character(string name, string race);

void SetName(string name);

string getName() const;

void SetRace(string name);

string getRace() const;

void Print();

};

#endif

//character.cpp:

#include <iostream>

#include "character.h"

using namespace std;

Character::Character(string Name, string Race) {

name = Name;

race = Race;

}

void Character::SetName(string Name) {

name = Name;

}

string Character::getName() const {

return name;

}

void Character::SetRace(string Race) {

race = Race;

}

string Character::getRace() const {

return race;

}

void Character::Print() {

cout << "Character Name: " << this -> getName();

cout << "\tCharacter Race: " << this -> getRace() << endl;

}

//wizard.h:

#ifndef WIZARD_H

#define WIZARD_H

#include <iostream>

#include <string>

#include "character.h"

using namespace std;

class Wizard: public Character {

private:

string listOfSpells[10];

int amountOfSpells;

public:

Wizard(string name, string race);

int AddSpell(string spell);

string CastSpell(int num);

void Print();

};

#endif

//wizard.cpp:

#include <iostream>

#include "wizard.h"

using namespace std;

Wizard::Wizard(string name, string race):Character(name,race){

amountOfSpells = 0;

for(int i = 0; i < 10; i++)

    listOfSpells[i] = "";

}

string Wizard::CastSpell(int num) {

return listOfSpells[num-1];

}

int Wizard::AddSpell(string spell) {

listOfSpells[amountOfSpells++] = spell;

return amountOfSpells;

}

void Wizard::Print() {

cout << "Wizard information: Character Name: " << this -> getName();

cout << "\tCharacter Race: " << this -> getRace() << endl;

cout << "Spells:" << endl;

for(int i = 0; i < amountOfSpells; i++)

    cout <<"Spell " << i + 1 << ".\t" << listOfSpells[i] << endl;

cout << endl;

}

Output:

Add a comment
Know the answer?
Add Answer to:
C++ programming question, please help! Thank you so much in advance!!! In this exercise, you will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

  •       C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for...

          C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for this part Add on to the lab12a solution(THIS IS PROVIDED BELOW). You will add an overload operator function to the operator << and a sort function (in functions.h and functions.cpp)    Print out the customer’s name, address, account number and balance using whatever formatting you would like    Sort on account balance (hint: you can overload the < operator and use sort from the...

  • I need help with this assignment, can someone HELP ? This is the assignment: Online shopping...

    I need help with this assignment, can someone HELP ? This is the assignment: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by...

  • Write a C++ Program. You have a following class as a header file (dayType.h) and main()....

    Write a C++ Program. You have a following class as a header file (dayType.h) and main(). #ifndef H_dayType #define H_dayType #include <string> using namespace std; class dayType { public:     static string weekDays[7];     void print() const;     string nextDay() const;     string prevDay() const;     void addDay(int nDays);     void setDay(string d);     string getDay() const;     dayType();     dayType(string d); private:     string weekDay; }; #endif /* // Name: Your Name // ID: Your ID */ #include <iostream>...

  • Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string;...

    Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...

  • #ifndef PROCESSREQUESTRECORD_CLASS #define PROCESSREQUESTRECORD_CLASS #include <iostream> #include <string> using namespace std; class procReqRec { public: //...

    #ifndef PROCESSREQUESTRECORD_CLASS #define PROCESSREQUESTRECORD_CLASS #include <iostream> #include <string> using namespace std; class procReqRec { public: // default constructor procReqRec() {} // constructor procReqRec(const string& nm, int p); // access functions int getPriority(); string getName(); // update functions void setPriority(int p); void setName(const string& nm); // for maintenance of a minimum priority queue friend bool operator< (const procReqRec& left, const procReqRec& right); // output a process request record in the format // name: priority friend ostream& operator<< (ostream& ostr, const procReqRec&...

  • hello there. can you please help me to complete this code. thank you. Lab #3 -...

    hello there. can you please help me to complete this code. thank you. Lab #3 - Classes/Constructors Part I - Fill in the missing parts of this code #include<iostream> #include<string> #include<fstream> using namespace std; class classGrades      {      public:            void printlist() const;            void inputGrades(ifstream &);            double returnAvg() const;            void setName(string);            void setNumStudents(int);            classGrades();            classGrades(int);      private:            int gradeList[30];            int numStudents;            string name;      }; int main() {          ...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT