Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Please The user must be prompted to enter their username and password to log in After the user successfully logs in, the main

In C++ Please

The user must be prompted to enter their username and password to log in

After the user successfully logs in, the main menu must be displayed

#include #include #include #include #include

#include "ReadData.h"

int main() { // The user's response to the request for another search. //The user may enter a string instead of one character, so we need to compensate std::string searchAgainResponse;

bool isValidLogin; bool validResponse; bool searchAgain;

// Let the user know that book data is being retrieved. Ask them to wait as this could take some time std::cout << "Retrieving book inventory. Please wait... ";

// Put data from CSVs into vectors std::vector books = readInventory("inventory.csv"); std::vector users = readUsers("users.csv");

// Let the user know that the book data retrieval has completed std::cout << "Book inventory retrieved. ";

do { std::cout << " Please log in "; std::cout << "----------------";

std::string username; std::string password; std::cout << " Enter username: "; std::cin >> username; std::cout << " Enter password: "; std::cin >> password; std::cout << "---------------- ";

// Determine if login credentials are valid. If they are, continue if (validateLogin(users, username, password)) { isValidLogin = true;

do { // Prompt the user to enter a search term to be used against book data std::string searchTerm; std::cout << " Enter search term: "; std::cin >> searchTerm;

// Iterate through book data and print the info of the books that match the search for (Book book : books) { if (book.title.find(searchTerm) != std::string::npos) { std::cout << "Book Title: " << book.title << std::endl; std::cout << "Book Author: " << book.author << std::endl; std::cout << "Publisher: " << book.publisher << std::endl; std::cout << "Publication Year: " << book.publicationYear << std::endl; std::cout << std::endl; } }

do { // Ask user if they would like to perform another search std::cout << "Would you like to perform another search? (Y/N) ";

std::cin >> searchAgainResponse;

// Determine if input matches an accepted answer if (searchAgainResponse == "Y" || searchAgainResponse == "y" || searchAgainResponse == "N" || searchAgainResponse == "n") { validResponse = true;

// Determine if the user would like to search again if (searchAgainResponse == "Y" || searchAgainResponse == "y") { searchAgain = true; } else { searchAgain = false; } } else { // Invalid input was entered. Set validResponse to false in order for the loop to run again std::cout << "Please enter a valid response of either Y or N "; validResponse = false; } } while (validResponse == false);

} while (searchAgain); } else { // User entered invalid login credentials. Set isValidLogin to false to force the user to attemp another login std::cout << "Invalid login" << std::endl; isValidLogin = false; } } while (!isValidLogin);

return 0; }

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

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

What does this public know about your organization?

Answered: 1 week ago