Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ PLEASE DO NOT CHANGE ANY OF THE CODE AT ALL. ONLY USE THE REQUIRED FUNCTIONS. DO NOT MAKE NEW PRIVATE FUNCTIONS OR USE THE

C++ PLEASE DO NOT CHANGE ANY OF THE CODE AT ALL. ONLY USE THE REQUIRED FUNCTIONS. DO NOT MAKE NEW PRIVATE FUNCTIONS OR USE THE RECOMMENDED PRIVATE FUNCTIONS Thanks.

9.25. PROGRAM 3: BBoard (Part 1)

In this assignment you will create an extremely rudimentary bulletin board with a simple command-line interface (like in the old days!).

This will require three collaborating classes - BBoard, User, and Message. For the moment, the bulletin board will exist only inside the test harness (i.e. we won't store it to the file system yet), so you will construct a single BBoard object (giving it an appropriate title - e.g. "Jack's Amazing Bulletin Board"), and then invoke its methods.

First, you will "load it up" with a set of authorized Users (read in from a file);

then you will ask the user to log in with a username and password, which you will check against the list you just read in;

and then you will "run" the board: the program will enter a sentinel-controlled loop asking the user to choose from a menu of actions (corresponding, obviously, to BBoard's other public methods)

list all current posts

create a new post

quit the system

Incremental Programming Steps

Create and fully unit test the classes User and Message. Here are the specifications for these 2 classes: User & Message Headers

Once you have completed and fully unit tested the User and Message class, then you should begin work on the BBoard class. Here are the specifications for the BBoard class: BBoard Header

main.cpp

//includes int main() { string userfile;

cout << "User file?" << endl;

cin >> userfile;

cout << endl;

BBoard bb("CS12 Bulletin Board");

// load users from file

if (!bb.loadUsers(userfile)) {

cout << "Error loading users from file " << userfile << endl;

return 1;

}

if (!bb.login()) {

cout << "Login not successful" << endl;

return 1;

}

bb.run();

return 0;

}

BBoard.h

Don't forget inclusion guard!!

//BBoard.h

#include

#include

using namespace std;

#include "Message.h"

#include "User.h"

class BBoard {

private:

string title;

vector userList;

User currentUser;

vector messageList;

public:

// Constructs a board with a default title,

// empty user & message lists,

// and the "default" User

BBoard();

// Same as the default constructor except

// it sets the title of the board

BBoard(const string &);

// Imports all the authorized users from an input file,

// storing them as User objects in the vector userList

// The name of the input file is passed in as a parameter to this function.

// Returns true if the file opened, false if it did not.

// See specifications for file format.

bool loadUsers(const string &);

// Asks for and validates a user/password.

// Always asks for both user and password combo unless 'q' or 'Q' entered.

// Checks userList to validate user and password.

// If valid, sets currentUser to this User, outputs welcome message,

// then returns true.

// Otherwise outputs error message and then repeats request

// for username/password.

// Continues until valid user/password

// or until 'q' or 'Q' is entered for username.

// If 'q' or 'Q' is entered, does not ask for password, outputs "Bye!"

// and then returns false.

bool login();

// Contains main loop of Bulletin Board.

// First verifies a User has been logged in.

// Exits **function** immediately if no User logged in (Default User).

// Continues to display menu options to user and performs requested action

// until user chooses to quit.

// See output samples for exact format of menu.

void run();

Private:

// These are only suggestions, not required helper functions.

// Feel free to make your own private helper functions as you see fit.

void display() const;

void addMessage();

bool userExists(const string &, const string &) const;

};

Message.h

Don't forget inclusion guards!!

//Message.h

#include

using namespace std;

class Message {

private:

string author;

string subject;

string body;

public:

// default constructor

Message();

// Parameterized constructor;

Message(const string &athr,

const string &sbjct,

const string &body);

// Displays the Message using the following format:

//

// subject

// from author: body

void display() const;

};

User.h

//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 getUsername() const;

// returns true if the stored username/password matches with the

// parameters. Otherwise returns false.

// Note that, even though a User with empty name and password is

// actually a valid User object (it is the default User), this

// function must still return false if given a empty uname string.

bool check(const string &uname, const string &pass) const;

// sets a new password.

// This function should only set the new password if the current (old)

// password is passed in. Also, a default User cannot have its

// password changed.

// returns true if password changed, false if not.

bool setPassword(const string &oldpass, const string &newpass);

};

The following is the main function you should turn in for the final compare output tests once you have finished all unit testing. You can use this main function to unit test your BBoard functions if you want. Just comment out the functions you are not currently testing.

main function

User File Specifications

 user1 pass1 user2 pass2 user3 pass3 ... end 

One user and password per line. Can be any number of users. Last line will have the word "end" followed by a newline.

The output samples below use a file named users1.txt that contains the following:

ali87 8422 ricq7 bjk1903 messi buneyinnessi mike ini99ou jenny Y00L11A09 end 

Output Specifications

Read the examples below and make sure your output matches exactly with the sample runs below (given the same inputs).

This is what your output will look like in cloud9:

Sample run 1

$ ./a.out User file? users1.txt Welcome to CS12 Bulletin Board Enter your username ('Q' or 'q' to quit): ali87 Enter your password: 8422 Welcome back ali87! Menu - Display Messages ('D' or 'd') - Add New Message ('N' or 'n') - Quit ('Q' or 'q') Choose an action: D Nothing to Display. Menu - Display Messages ('D' or 'd') - Add New Message ('N' or 'n') - Quit ('Q' or 'q') Choose an action: q Bye! 

Sample run 2

$./a.out User file? users1.txt Welcome to CS12 Bulletin Board Enter your username ('Q' or 'q' to quit): messi Enter your password: buneyinessi Invalid Username or Password! Enter your username ('Q' or 'q' to quit): messi Enter your password: buneyinnessi Welcome back messi! Menu - Display Messages ('D' or 'd') - Add New Message ('N' or 'n') - Quit ('Q' or 'q') Choose an action: N Enter Subject: Thanks a bunch!! Enter Body: Thanks for this amazing board! Message Recorded! Menu - Display Messages ('D' or 'd') - Add New Message ('N' or 'n') - Quit ('Q' or 'q') Choose an action: n Enter Subject: Chelsea vs Arsenal Enter Body: Have you seen the game from Wed yet? Better than El Clasico! Message Recorded! Menu - Display Messages ('D' or 'd') - Add New Message ('N' or 'n') - Quit ('Q' or 'q') Choose an action: n Enter Subject: Output Specifications Enter Body: So we just have to make our output look like the samples? Message Recorded! Menu - Display Messages ('D' or 'd') - Add New Message ('N' or 'n') - Quit ('Q' or 'q') Choose an action: D --------------------------------------------------------- Message #1: Thanks a bunch!! from messi: Thanks for this amazing board! --------------------------------------------------------- Message #2: Chelsea vs Arsenal from messi: Have you seen the game from Wed yet? Better than El Clasico! --------------------------------------------------------- Message #3: Output Specifications from messi: So we just have to make our output look like the samples? --------------------------------------------------------- Menu - Display Messages ('D' or 'd') - Add New Message ('N' or 'n') - Quit ('Q' or 'q') Choose an action: q Bye! 

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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago

Question

2. Define identity.

Answered: 1 week ago

Question

1. Identify three communication approaches to identity.

Answered: 1 week ago

Question

4. Describe phases of majority identity development.

Answered: 1 week ago