Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I fix these errors? (my code below) In file included from Message.cpp:1:0: Message.h:18:6: error: 'vector' does not name a type vector childList; //

How do I fix these errors? (my code below)

In file included from Message.cpp:1:0: Message.h:18:6: error: 'vector' does not name a type vector childList; // New !! ^~~~~~ Message.cpp: In member function 'void Message::print(unsigned int) const': Message.cpp:31:29: error: 'child_list' was not declared in this scope for( unsigned i = 0; i < child_list.size(); ++i ) ^~~~~~~~~~ Message.cpp: At global scope: Message.cpp:34:39: error: no 'const string& Message::get_subject() const' member function declared in class 'Message' const string & Message::get_subject() const{ ^~~~~ Message.cpp:37:28: error: no 'unsigned int Message::get_id() const' member function declared in class 'Message' unsigned Message::get_id() const{ ^~~~~ Message.cpp:40:39: error: no 'void Message::add_child(Message*)' member function declared in class 'Message' void Message::add_child(Message *child){ ^ Message.cpp: In destructor 'virtual Message::~Message()': Message.cpp:44:29: error: 'child_list' was not declared in this scope for( unsigned i = 0; i < child_list.size(); ++i ) ^~~~~~~~~~ In file included from Topic.h:3:0, from Topic.cpp:1: Message.h:18:6: error: 'vector' does not name a type vector childList; // New !! ^~~~~~ Topic.cpp: In member function 'std::string Topic::to_formatted_string() const': Topic.cpp:25:9: error: 'child_list' was not declared in this scope if( !child_list.empty() ){ ^~~~~~~~~~ In file included from Reply.h:3:0, from Reply.cpp:1: Message.h:18:6: error: 'vector' does not name a type vector childList; // New !! ^~~~~~ Reply.cpp: In member function 'std::string Reply::to_formatted_string() const': Reply.cpp:22:9: error: 'child_list' was not declared in this scope if( !child_list.empty() ){ ^~~~~~~~~~ BBoard.cpp: In member function 'bool BBoard::load_messages(const string&)': BBoard.cpp:86:66: error: invalid new-expression of abstract class type 'Topic' Message *mg = new Topic( author, subject, body, id); ^ In file included from BBoard.cpp:3:0: Topic.h:4:7: note: because the following virtual functions are pure within 'Topic': class Topic: public Message{ ^~~~~ In file included from BBoard.h:6:0, from BBoard.cpp:1: Message.h:40:19: note: virtual bool Message::isReply() const virtual bool isReply() const = 0; ^~~~~~~ Message.h:42:21: note: virtual std::string Message::toFormattedString() const virtual string toFormattedString() const = 0; // New!! ^~~~~~~~~~~~~~~~~ BBoard.cpp:93:67: error: invalid new-expression of abstract class type 'Reply' Message *mg = new Reply( author, subject, body, id); ^ In file included from BBoard.cpp:2:0: Reply.h:4:7: note: because the following virtual functions are pure within 'Reply': class Reply:public Message{ ^~~~~ In file included from BBoard.h:6:0, from BBoard.cpp:1: Message.h:40:19: note: virtual bool Message::isReply() const virtual bool isReply() const = 0; ^~~~~~~ Message.h:42:21: note: virtual std::string Message::toFormattedString() const virtual string toFormattedString() const = 0; // New!! ^~~~~~~~~~~~~~~~~ BBoard.cpp:103:37: error: 'class Message' has no member named 'add_child'; did you mean 'addChild'? message_list[ i ] -> add_child( message_list[ child - 1] ); ^~~~~~~~~ BBoard.cpp: In member function 'bool BBoard::save_messages(const string&)': BBoard.cpp:117:47: error: 'class Message' has no member named 'to_formatted_string'; did you mean 'toFormattedString'? fOut << endl << message_list[ i ]->to_formatted_string() ; ^~~~~~~~~~~~~~~~~~~ BBoard.cpp: In member function 'void BBoard::add_reply()': BBoard.cpp:167:55: error: 'class Message' has no member named 'get_subject'; did you mean 'getSubject'? subject = "Re: " + message_list[ message_id - 1 ]->get_subject(); ^~~~~~~~~~~ BBoard.cpp:179:77: error: invalid new-expression of abstract class type 'Reply' Message *mg = new Reply( current_user->get_username(), subject, body, id ); ^ BBoard.cpp:181:36: error: 'class Message' has no member named 'add_child'; did you mean 'addChild'? message_list[ message_id - 1 ]->add_child( mg ); ^~~~~~~~~ BBoard.cpp: In member function 'void BBoard::add_topic()': BBoard.cpp:198:77: error: invalid new-expression of abstract class type 'Topic' Message *mg = new Topic( current_user->get_username(), subject, body, id ); ^ BBoard.cpp: In member function 'void BBoard::display() const': BBoard.cpp:209:34: error: 'class Message' has no member named 'is_reply'; did you mean 'isReply'? if( !message_list[i]->is_reply() ){

Here is my code:

main.cpp

#include #include #include #include using namespace std; #include "BBoard.h" #include "User.h" #include "Message.h" #include "Reply.h" #include "Topic.h"

/*int main(int argc, char* argv[]) { string file = argv[argc - 1]; // Message m; // m.display(); // cout << endl; // Message m1("Zafir", "Great Subject", "THis is the body!!"); // m1.display(); BBoard board; board.setup(file); board.login(); return 0; }*/

int main(int argc, char **argv) { // check commandline arguments // if (argc != 3){ // cout << "ERROR: Invalid program call." << endl // << "Usage: userfile datafile" << endl; //return 1; //} string userfile("users1.txt"); string datafile("data.txt"); BBoard bb("Bulletin Board"); // load users from file if (!bb.load_users(userfile)) { cout << "ERROR: Cannot load users from " << userfile << endl; return 1; } // load messages if (!bb.load_messages(datafile)) { cout << "ERROR: Cannot load messages from " << datafile << endl; return 1; } bb.login(); //bool a = bb.save_messages("out.txt"); //a=a; bb.run();

// save messages if (!bb.save_messages(datafile)) { cout << "ERROR: Cannot save messages to " << datafile << endl; return 1; } // cout << "saved" << endl; return 0; }

BBoard.cpp

#include "BBoard.h" #include "Reply.h" #include "Topic.h" #include #include #include #include #include using namespace std; BBoard::BBoard(){ current_user=NULL; } BBoard::BBoard(const string &ttl){ title=ttl; current_user = NULL; } bool BBoard::load_users(const string &userfile){ ifstream fIn( userfile.c_str() ); if( fIn.is_open() ) { string temp1,temp2; fIn>>temp1; while(temp1!="end"){ fIn>>temp2; user_list.push_back(User(temp1,temp2)); fIn>>temp1; } fIn.close(); return true; } else return false; } bool BBoard::load_messages(const string& datafile){ ifstream fIn( datafile.c_str() ); if( fIn.is_open() ) { string tmp, strBegin; string author, subject; unsigned id = 0; vector< string > children; getline( fIn, tmp ); //pass over the first line , number of messages while( fIn.good() ){ getline( fIn, strBegin ); if( strBegin[ strBegin.size() -1 ] == ' ' ) strBegin.erase( strBegin.size() -1 );

getline( fIn, tmp ); //pass over the line with id information

getline( fIn, subject); if( subject[ subject.size() -1 ] == ' ' ) subject.erase( subject.size() -1 ); subject.erase( 0, 10);

getline( fIn, author); if( author[ author.size() -1 ] == ' ' ) author.erase( author.size() -1 ); author.erase( 0, 7);

string body; string str_children; getline( fIn, tmp ); //tmp may be children or body if( tmp[ tmp.size() -1 ] == ' ' ) tmp.erase( tmp.size() -1 ); if( tmp.find( "children", 0 ) != string::npos ){ tmp.erase( 0, 11); children.push_back(tmp); getline( fIn, tmp ); if( tmp[ tmp.size() -1 ] == ' ' ) tmp.erase( tmp.size() -1 ); } else children.push_back(""); while( tmp != "" ) { body = body + ' ' + tmp; getline( fIn, tmp ); if( tmp[ tmp.size() -1 ] == ' ' ) tmp.erase( tmp.size() -1 ); } ++id; //cout << id << endl; body.erase( 0, body.find_first_of(":", 1)); //remove the first ' ' body.erase( 0, body.find_first_of(":", 1) + 2 ); //remove :body: //cout << body << endl; if ( strBegin == "" ){ //cout << " strBegin :" << strBegin << endl; //cout << " size :" << strBegin.size() << endl; Message *mg = new Topic( author, subject, body, id); //cout << "topic added " << endl; message_list.push_back( mg ); } else { //cout << " strBegin :" << strBegin << endl; //cout << " size :" << strBegin.size() << endl; Message *mg = new Reply( author, subject, body, id); //cout << "reply added " << endl; message_list.push_back( mg ); } } fIn.close(); int child; for( unsigned i = 0; i < children.size(); ++i ){ stringstream iss( children[i] ); while( iss >> child ){ message_list[ i ] -> add_child( message_list[ child - 1] ); //cout << child << " is added" << endl; } } return true; } else return false; } bool BBoard::save_messages(const string& datafile){ ofstream fOut( datafile.c_str() ); if( fOut.is_open() ) { fOut << message_list.size(); for( unsigned i = 0; i < message_list.size(); ++i ) fOut << endl << message_list[ i ]->to_formatted_string() ; fOut.close(); return true; } else return false; } const User * BBoard::get_user(const string &name, const string &pw) const{ for( unsigned i = 0; i < user_list.size(); ++i ){ if( user_list[i].check(name,pw) ) return &user_list[i]; } return NULL; } void BBoard::login(){ string name, pass; cout << endl << "Welcome to Jack's Amazing Bulletin Board" << endl; while(true){ cout<<"Enter your username (\"Q\" or \"q\" to quit):"; getline(cin,name); if(name.compare("Q")==0 || name.compare("q")==0){ cout<<"Bye!"<

void BBoard::add_reply(){ string subject, body, tmp; int id; int message_id; while( true ){ cout << endl << "Enter Message ID (-1 for Menu): " ; getline( cin, tmp); stringstream ss( tmp ); ss >> message_id; //cin >> message_id; //****** use this will make getline( cin, tmp ) doesn't work if( message_id == -1 ) return; if( message_id > 0 && message_id <= (int)message_list.size() ) break; cout << "Invalid Message ID!!" << endl; } id = message_list.size() + 1; subject = "Re: " + message_list[ message_id - 1 ]->get_subject(); cout << "Enter Body: "; getline( cin, tmp); if( tmp == "" ){ body = body + ' '; getline( cin, tmp); } while ( tmp != "" ){ body = body + ' ' + tmp; getline( cin, tmp ); } body.erase( 0, 1 ); //remove the first character ' ' Message *mg = new Reply( current_user->get_username(), subject, body, id ); message_list.push_back( mg ); message_list[ message_id - 1 ]->add_child( mg ); } void BBoard::add_topic(){ string subject, body, tmp; int id; id = message_list.size() + 1; cout << "Enter Topic: "; getline( cin, subject ); cout << "Enter Body: "; getline( cin, tmp); if( tmp == "" ) getline( cin, tmp); while ( tmp != "" ){ body = body + ' ' + tmp; getline( cin, tmp ); } body.erase( 0, 1 ); //remove the first character ' ' Message *mg = new Topic( current_user->get_username(), subject, body, id ); message_list.push_back( mg ); } //display should be rewritten void BBoard::display() const{ if( message_list.size()==0 ) cout<is_reply() ){ message_list[i]->print( 0 ); cout<<"-------------------------------------------------------------------------------"<get_username()<<"!"<>c; string s; getline(cin,s); if(s=="N" || s=="n") add_topic(); else if(s=="R" || s=="r") add_reply(); else if(s=="D" || s=="d") display(); else if(s=="Q" || s=="q"){ cout<<"Bye!"<

BBoard.h

#ifndef _BBOARD_H #define _BBOARD_H #include #include #include "User.h" #include "Message.h" using namespace std; class BBoard{ private: string title; vector user_list; const User *current_user; vector message_list; const User * get_user(const string &name, const string &pw) const; void display() const; void add_topic(); void add_reply(); public: BBoard(); BBoard(const string& ttl); bool load_users(const string& userfile); bool load_messages(const string& datafile); bool save_messages(const string& datafile); void login(); void run(); ~BBoard( ); }; #endif

Message.cpp

#include "Message.h" #include #include #include using namespace std; Message::Message(){ } Message::Message(const string &athr,const string &sbjct,const string &b, unsigned i){ author = athr; subject = sbjct; body = b; id = i; } void Message::print(unsigned indentation) const{ if( indentation !=0 ) cout << endl; for( unsigned i = 0; i < indentation ; ++i ) cout << " "; cout << "Message #" << id << ": " << subject << endl; for( unsigned i = 0; i < indentation ; ++i ) cout << " "; string newbody(body); unsigned pos = newbody.find_first_of( ' ', 0 ); while( pos < newbody.size() ){ newbody.insert( pos + 1 , (int)indentation * 2, ' ' ); //insert before position pos + 1 pos = newbody.find_first_of( ' ', pos + 1 ); } cout << "from " << author << ": " << newbody << endl; //cout << child_list.size() << endl; ++indentation; for( unsigned i = 0; i < child_list.size(); ++i ) child_list[ i ]->print( indentation ); } const string & Message::get_subject() const{ return subject; } unsigned Message::get_id() const{ return id; } void Message::add_child(Message *child){ child_list.push_back( child ); } Message::~Message(){ for( unsigned i = 0; i < child_list.size(); ++i ) child_list[ i ] = NULL; }

Reply.cpp

#include "Reply.h" #include Reply::Reply(){ } Reply::Reply(const string &athr, const string &sbjct, const string &bdy, unsigned i){ author = athr; subject = sbjct; body = bdy; id = i; } bool Reply::is_reply() const{ return true; } string Reply::to_formatted_string() const{ string s(""); s +=' '; stringstream ss; ss << id; s += ":id: " + ss.str()+ ' '; s += ":subject: " + subject + ' '; s += ":from: " + author + ' '; if( !child_list.empty() ){ s += ":children:"; for( unsigned i = 0; i < child_list.size(); ++i ){ stringstream ssid; ssid << child_list[ i ]->get_id(); s += ' ' + ssid.str(); } s += ' '; } s += ":body: " + body + ' '; s += ""; return s; }

Reply.h

#ifndef REPLY_H #define REPLY_H #include "Message.h" class Reply:public Message{ public: //default constructor Reply(); Reply(const string &athr, const string &sbjct, const string &body, unsigned id); bool is_reply() const; string to_formatted_string() const; }; #endif

Topic.cpp

#include "Topic.h" #include Topic::Topic(){ } Topic::Topic(const string &athr, const string &sbjct, const string &bdy, unsigned i){ author = athr; subject = sbjct; body = bdy; id = i; } bool Topic::is_reply() const{ return false; } string Topic::to_formatted_string() const{ string s(""); s +=' '; stringstream ss; ss << id; s += ":id: " + ss.str()+ ' '; s += ":subject: " + subject + ' '; s += ":from: " + author + ' '; if( !child_list.empty() ){ s += ":children:"; for( unsigned i = 0; i < child_list.size(); ++i ){ stringstream ssid; ssid << child_list[ i ]->get_id(); s += ' ' + ssid.str(); } s += ' '; } s += ":body: " + body + ' '; s += ""; return s; }

Uesr.h

#ifndef _USER_H #define _USER_H #include using namespace std; class User { private: string username; string password; public: //creates a user with empty name and password. User(); // creates a user with given username and password. User(const string& uname, const string& pass); //returns the username string get_username() const; bool check(const string &uname, const string &pass) const; // sets a new password. This function will not be used in the // current assignment. //void set_password(const string &newpass); }; #endif

Topic.h

#ifndef TOPIC_H #define TOPIC_H #include "Message.h" class Topic: public Message{ public: Topic(); Topic(const string &athr, const string &sbjct, const string &bdy, unsigned id); bool is_reply() const; string to_formatted_string() const; }; #endif

User.cpp

#include "User.h" #include using namespace std; User::User(){ username=""; password=""; } // creates a user with given username and password. User::User(const string& uname, const string& pass){ username=uname; password=pass; } //returns the username string User::get_username() const{ return username; } bool User::check(const string &uname, const string &pass) const{ if(uname.empty()||pass.empty()) return false; return username==uname && password==pass; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

b. Compute the variance. Pg45

Answered: 1 week ago

Question

Rsa algorithm

Answered: 1 week ago

Question

Prepare for a successful job interview.

Answered: 1 week ago

Question

Describe barriers to effective listening.

Answered: 1 week ago

Question

List the guidelines for effective listening.

Answered: 1 week ago