Question: Separate the item class and the user class, into 2 files file.cpp and file.h and how to enter it in the main menu User class

Separate the item class and the user class, into 2 files
file.cpp and file.h and how to enter it in the main menu
User class
#include
#include
#include
using namespace std;
class User {
private:
string username;
string password;
public:
User(const string & user, const string & pass) : username(user), password(pass){}
bool authenticate(const string & inputUser, const string & inputPass) const {
return (username == inputUser) && (password == inputPass);
}
static bool validateUser(const string & inputUser, const string & inputPass){
ifstream file("user.txt");
if (!file.is_open()){
cerr << "Error opening file" << endl;
return false;
}
string storedUser, storedPass;
while (file >> storedUser >> storedPass){
if (storedUser == inputUser && storedPass == inputPass){
return true;
}
}
return false;
}
};
Item class
#include
using namespace std;
class Item {
private:
string name;
double price;
int quantity;
public:
Item(const string & name, double price, int quantity =0) : name(name), price(price), quantity(quantity){}
string getName() const {
return name;
}
double getPrice() const {
return price;
}
void setQuantity(int newQuantity){
quantity = newQuantity;
}
int getQuantity() const {
return quantity;
}
};

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!