I\'m working in C++. I\'m getting an error running my driver file saying \"no ma
ID: 3852464 • Letter: I
Question
I'm working in C++. I'm getting an error running my driver file saying "no matching class Roster::Roster". I'm trying to get my driver file to work with the header file I have implemented. Ill post both files below. Can somebody help me get my header file to print execution code like in the screenshot.
// Driver File
// driver.cpp
// Testing driver for Assignment 3
#include <iostream>
#include <string>
#include "guild.h"
using std::cin;
using std::getline;
using std::cout;
using std::endl;
using std::string;
int main()
{
string name;
cout << "What is your guild's name? " << endl;
getline(cin, name);
Roster guild = Roster(name);
string prompt;
do
{
string charName;
cout << "What is the character's name? ";
getline(cin, charName);
int level;
cout << "What is the character's level? ";
cin >> level;
guild.add(Character(charName, level));
cout << "Are there more members (Y/N)? " << endl;
cin.ignore(std::numeric_limits<std::streamsize>::max(), ' '); // Flush newlines
getline(cin, prompt);
}
while(prompt[0] == 'y' || prompt[1] == 'Y');
guild.print();
}
// Header File
// Header file for guild roster
#ifndef __GUILD_H__
#define __GUILD_H__
using namespace std;
// Guild Roster will store the name and level of characters
// It will also order them based on level from high to low
// Character class
class Character
{
// private members of the class
private:
string name;
int level;
public:
// Default constructor
Character();
//Parameter constructor
Character(string name, int level)
{
name;
level;
}
// Accessor function to retrieve name
string returnName()
{
return name;
}
// Accessor function to retrieve the level
int returnLevel()
{
return level;
}
};
// Roster Class
class Roster
{
// Instance of the Character class
Character* charInst;
// Link to the next node
Roster* next;
// Default constructor
Roster()
{
}
// Function to insert into list sort
void insertSort(Roster* headRoster, Roster* newChar)
{
Roster* temp = new Roster();
if(headRoster == nullptr || ((headRoster) ->charInst->returnLevel()) >= newChar->charInst->returnLevel())
{
newChar->next = headRoster;
headRoster = newChar;
}
else
{
temp = headRoster;
while(temp->next != nullptr && temp->next->charInst->returnLevel() < newChar->charInst->returnLevel())
{
temp = temp->next;
}
newChar->next = temp->next;
temp->next = newChar;
}
}
// Function to print the list
void printList(Roster* head)
{
Roster* temp = head;
while(temp != nullptr)
{
cout << temp->charInst->returnName();
cout << " " << temp->charInst->returnLevel() << endl;
}
}
};
#endif // __GUILD_H__
// Execution should look like this
Document anguage: English (U.5.) Change What is your guild's name? Savage Tide What is the character's name? Col Tobinson What is the character's level? 21 Are there more members (Y/N)? y What is the character's name? Lyddie What is the character's level? 20 Are there more members (Y/N)? y What is the character's name? Bin What is the character's level? 20 Are there more members (Y/N)? y What is the character's name? Churtle What is the character's level? 18 Are there more members (Y/N)? y What is the character's name? Roundabout What is the character's level? 19 Are there more members (Y/N)? n Guild Name: Savage Tide Convert Create PDF Comment Combine Files organize Pages aill & Sign Send for Signature Send & Track More Tools Col Tobinson, Level 21 Bin, Level 20 le, Leve Roundabout, Level 19 Churtle, Level 18 Store and share files in the Document Cloud Lean More Type here to search 657 AM 6/26/2017 q:Explanation / Answer
// Driver File
// driver.cpp
// Testing driver for Assignment 3
#include <iostream>
#include <string>
#include "guild.h"
using std::cin;
using std::getline;
using std::cout;
using std::endl;
using std::string;
int main()
{
string name;
cout << "What is your guild's name? " << endl;
getline(cin, name);
Roster guild = Roster(name);
string prompt;
do
{
string charName;
cout << "What is the character's name? ";
getline(cin, charName);
int level;
cout << "What is the character's level? ";
cin >> level;
guild.add(Character(charName, level));
cout << "Are there more members (Y/N)? " << endl;
cin.ignore(std::numeric_limits<std::streamsize>::max(), ' '); // Flush newlines
getline(cin, prompt);
}
while(prompt[0] == 'y' || prompt[1] == 'Y');
guild.print();
}
// Header File
// Header file for guild roster
#ifndef __GUILD_H__
#define __GUILD_H__
using namespace std;
// Guild Roster will store the name and level of characters
// It will also order them based on level from high to low
// Character class
class Character
{
// private members of the class
private:
string name;
int level;
public:
// Default constructor
Character();
//Parameter constructor
Character(string name, int level)
{
name;
level;
}
// Accessor function to retrieve name
string returnName()
{
return name;
}
// Accessor function to retrieve the level
int returnLevel()
{
return level;
}
};
// Roster Class
class Roster
{
// Instance of the Character class
Character* charInst;
// Link to the next node
Roster* next;
// Default constructor
Roster()
{
}
// Function to insert into list sort
void insertSort(Roster* headRoster, Roster* newChar)
{
Roster* temp = new Roster();
if(headRoster == nullptr || ((headRoster) ->charInst->returnLevel()) >= newChar->charInst->returnLevel())
{
newChar->next = headRoster;
headRoster = newChar;
}
else
{
temp = headRoster;
while(temp->next != nullptr && temp->next->charInst->returnLevel() < newChar->charInst->returnLevel())
{
temp = temp->next;
}
newChar->next = temp->next;
temp->next = newChar;
}
}
// Function to print the list
void printList(Roster* head)
{
Roster* temp = head;
while(temp != nullptr)
{
cout << temp->charInst->returnName();
cout << " " << temp->charInst->returnLevel() << endl;
}
}
};
#endif