Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Course: CS 12 spring 2011
- //
- // First Name: Chris
- // Last Name: Sides
- // Course username: cside001
- // email address: cside001@ucr.edu
- //
- // Lecture Section: 001
- // Lab Section: 022
- // TA: Muzo Akabay
- //
- // Assignment: assn4
- //
- // I hereby certify that the code in this file
- // is ENTIRELY my own original work.
- //
- // =================================================================
- #include <iostream>
- #include "bboard.h"
- #include "user.h"
- #include "message.h"
- #include <cstdlib>
- using namespace std;
- //Start of private functions
- /** Diplays all messages to the user. If there are no messages, "Nothing to
- * Diplay" will be show, */
- void Bboard:: message_display()
- {
- if (message_list.size() == 0)
- {
- cout <<"\nNothing to Display.\n";
- }
- else
- {
- cout << "\n------------------------------------\n";
- for (unsigned x = 0; x < message_list.size(); x++)
- {
- cout << "Message #" << x+1 << ": ";
- message_list[x].display();
- }
- }
- }
- /** Asks the user for the subject name and body of the message. Once the user
- * has entered the subject and body, the message gets stored in a vector. */
- void Bboard:: add_message()
- {
- char sub[256], body[256];
- const string author = current_user.get_username();
- cout << "\nEnter Subject: ";
- cin.getline(sub, 256);
- cin.getline(sub, 256);
- cout << "Enter Body: ";
- cin.getline(body, 256);
- Message msg(author, sub, body); //Creates a new message named msg
- message_list.push_back(msg);
- cout << "Message Recorded!\n";
- }
- //Start of public functions
- /** default bboard constructor. */
- Bboard:: Bboard()
- :title("The Most Epic Board of All Boards"), user_list(), current_user(User()),
- message_list()
- {
- }
- /** bboard constructor that takes in the name of the board as the parameter */
- Bboard:: Bboard(const string& ttl)
- :title(ttl), user_list(), current_user(User()), message_list()
- {
- }
- /** reads in a text file with usernames and passwords and stores them in
- * in a vector. The text file must have a username, space, and a password
- * on each line. When there are no more users, add "end" under the last
- * username. */
- void Bboard:: setup()
- {
- string usr;
- string pw;
- cin >> usr;
- while (usr != "end")
- {
- cin >> pw;
- User new_user(usr, pw);
- user_list.push_back(new_user);
- cin >> usr;
- }
- }
- /** prompts the user to enter thair username and password. If one of them is
- * invalid, the user will have to enter their username and password again. */
- void Bboard:: login()
- {
- string usr;
- string pw;
- bool real_user = false; //Will become true if the user is valid.
- cout << "Enter your username (\'Q\' or \'q\' to quit): ";
- cin >> usr;
- if (usr == "Q" || usr == "q")
- {
- cout << "Bye!" << endl;
- exit(0);
- }
- cout << "Enter your password: ";
- cin >> pw;
- for (unsigned x = 0; x < user_list.size(); x++)
- {
- if (user_list[x].check(usr, pw))
- {
- current_user = user_list[x];
- cout << "\nWelcome back " << current_user.get_username() << "!\n";
- real_user = true;
- }
- }
- if (!real_user)
- {
- cout << "Invalid Username or Password!\n" << endl;
- login();
- }
- }
- /** prompts the user with the menu of the board. The user can quit, add a new
- * message, or display all messages. */
- void Bboard:: run()
- {
- char choice;
- cout << "\nMenu\n";
- cout << " - Display Messages (\'D\' or \'d\')\n";
- cout << " - Add New Message (\'N\' or \'n\')\n";
- cout << " - Quit (\'Q\' or \'q\')\n";
- cout << "Choose an action: ";
- cin >> choice;
- if (choice == 'D' || choice == 'd')
- {
- message_display();
- run();
- }
- else if (choice == 'N' || choice == 'n')
- {
- add_message();
- run();
- }
- else if (choice == 'Q' || choice == 'q')
- {
- cout << "Bye!\n";
- exit(0);
- }
- else
- {
- cout << "\nInvalid entry\n";
- run();
- }
- }
- /** returns the title of the bboard */
- string Bboard:: get_title()
- {
- return title;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement