Remove Address class and add Address attribute to class User

This commit is contained in:
Joel Thomas
2026-02-21 12:57:38 +05:30
parent 27dab16ae1
commit 08cdab9e43
10 changed files with 30 additions and 51 deletions
@@ -1 +0,0 @@
#include "Address.h"
@@ -1,28 +0,0 @@
/*
Author: Joel Mathew Thomas
Date: 18-12-2026
*/
#pragma once
#include <string>
class Address
{
private:
std::string m_street;
std::string m_city;
int m_pincode;
public:
Address() :
m_street(""),
m_city(""),
m_pincode(0)
{}
Address(const std::string& street, const std::string& city, int pincode):
m_street(street),
m_city(city),
m_pincode(pincode)
{}
std::string getAddress() const;
};
@@ -21,8 +21,9 @@ public:
const std::string& name, const std::string& name,
const std::string& phone, const std::string& phone,
const std::string& password, const std::string& password,
const std::string& email) : const std::string& email,
User(username, name, phone, password, email) const std::string& address) :
User(username, name, phone, password, email, address)
{} {}
void addOrder(std::shared_ptr<Order>); void addOrder(std::shared_ptr<Order>);
orders& getOrders(); orders& getOrders();
@@ -21,8 +21,9 @@ public:
const std::string& name, const std::string& name,
const std::string& phone, const std::string& phone,
const std::string& password, const std::string& password,
const std::string& email) : const std::string& email,
User(username, name, phone, password, email) const std::string& address) :
User(username, name, phone, password, email, address)
{} {}
void acceptDeliveryAssignment(std::shared_ptr<DeliveryAssignment>); void acceptDeliveryAssignment(std::shared_ptr<DeliveryAssignment>);
deliveryAssignments& getAssignedDeliveries(); deliveryAssignments& getAssignedDeliveries();
@@ -252,7 +252,7 @@ void FoodDeliveryController::registerUser()
{ {
try try
{ {
std::string username, password, phone, name, email; std::string username, password, phone, name, email, address;
util::clear(); util::clear();
std::cout << "Enter Username: "; std::cout << "Enter Username: ";
util::readString(username); util::readString(username);
@@ -269,6 +269,8 @@ void FoodDeliveryController::registerUser()
util::readString(phone); util::readString(phone);
std::cout << "Enter Email: "; std::cout << "Enter Email: ";
util::readString(email); util::readString(email);
std::cout << "Enter Address: ";
util::readString(address);
while (true) while (true)
{ {
int choice; int choice;
@@ -282,13 +284,13 @@ void FoodDeliveryController::registerUser()
switch (choice) switch (choice)
{ {
case 1: case 1:
m_users[username] = std::make_shared<RestaurantOwner>(username, name, phone, password, email); m_users[username] = std::make_shared<RestaurantOwner>(username, name, phone, password, email, address);
break; break;
case 2: case 2:
m_users[username] = std::make_shared<Customer>(username, name, phone, password, email); m_users[username] = std::make_shared<Customer>(username, name, phone, password, email, address);
break; break;
case 3: case 3:
m_users[username] = std::make_shared<DeliveryPartner>(username, name, phone, password, email); m_users[username] = std::make_shared<DeliveryPartner>(username, name, phone, password, email, address);
break; break;
case 4: case 4:
return; return;
@@ -742,6 +744,7 @@ void FoodDeliveryController::viewProfile() const
<< std::left << std::setw(10) << "Username " << ": " << m_authenticatedUser->getUsername() << "\n" << std::left << std::setw(10) << "Username " << ": " << m_authenticatedUser->getUsername() << "\n"
<< std::left << std::setw(10) << "Phone " << ": " << m_authenticatedUser->getPhone() << "\n" << std::left << std::setw(10) << "Phone " << ": " << m_authenticatedUser->getPhone() << "\n"
<< std::left << std::setw(10) << "Email " << ": " << m_authenticatedUser->getEmail() << "\n" << std::left << std::setw(10) << "Email " << ": " << m_authenticatedUser->getEmail() << "\n"
<< std::left << std::setw(10) << "Type " << ": " << m_authenticatedUser->getType() << "\n"; << std::left << std::setw(10) << "Type " << ": " << m_authenticatedUser->getType() << "\n"
<< std::left << std::setw(10) << "Address " << ": " << m_authenticatedUser->getAddress() << "\n";
} }
} }
@@ -22,8 +22,9 @@ public:
const std::string& name, const std::string& name,
const std::string& phone, const std::string& phone,
const std::string& password, const std::string& password,
const std::string& email) : const std::string& email,
User(username, name, phone, password, email) const std::string& address) :
User(username, name, phone, password, email, address)
{} {}
void addRestaurant(std::shared_ptr<Restaurant>); void addRestaurant(std::shared_ptr<Restaurant>);
restaurants& getRestaurants(); restaurants& getRestaurants();
@@ -123,7 +123,6 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Address.cpp" />
<ClCompile Include="Customer.cpp" /> <ClCompile Include="Customer.cpp" />
<ClCompile Include="CustomerMenu.cpp" /> <ClCompile Include="CustomerMenu.cpp" />
<ClCompile Include="DeliveryAssignment.cpp" /> <ClCompile Include="DeliveryAssignment.cpp" />
@@ -144,7 +143,6 @@
<ClCompile Include="User.cpp" /> <ClCompile Include="User.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Address.h" />
<ClInclude Include="Customer.h" /> <ClInclude Include="Customer.h" />
<ClInclude Include="CustomerMenu.h" /> <ClInclude Include="CustomerMenu.h" />
<ClInclude Include="DeliveryAssignment.h" /> <ClInclude Include="DeliveryAssignment.h" />
@@ -27,9 +27,6 @@
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Address.cpp">
<Filter>Models</Filter>
</ClCompile>
<ClCompile Include="Customer.cpp"> <ClCompile Include="Customer.cpp">
<Filter>Models</Filter> <Filter>Models</Filter>
</ClCompile> </ClCompile>
@@ -86,9 +83,6 @@
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Address.h">
<Filter>Models</Filter>
</ClInclude>
<ClInclude Include="Customer.h"> <ClInclude Include="Customer.h">
<Filter>Models</Filter> <Filter>Models</Filter>
</ClInclude> </ClInclude>
@@ -25,6 +25,11 @@ std::string User::getEmail() const
return m_email; return m_email;
} }
std::string User::getAddress() const
{
return m_address;
}
bool User::login(const std::string& password) const bool User::login(const std::string& password) const
{ {
return password == m_password; return password == m_password;
@@ -14,30 +14,35 @@ private:
std::string m_phone; std::string m_phone;
std::string m_password; std::string m_password;
std::string m_email; std::string m_email;
std::string m_address;
public: public:
User(): User():
m_username(""), m_username(""),
m_name(""), m_name(""),
m_phone(""), m_phone(""),
m_password(""), m_password(""),
m_email("") m_email(""),
m_address("")
{} {}
User(const std::string& username, User(const std::string& username,
const std::string& name, const std::string& name,
const std::string& phone, const std::string& phone,
const std::string& password, const std::string& password,
const std::string& email): const std::string& email,
const std::string& address):
m_username(username), m_username(username),
m_name(name), m_name(name),
m_phone(phone), m_phone(phone),
m_password(password), m_password(password),
m_email(email) m_email(email),
m_address(address)
{} {}
virtual ~User() = default; virtual ~User() = default;
std::string getUsername() const; std::string getUsername() const;
std::string getName() const; std::string getName() const;
std::string getPhone() const; std::string getPhone() const;
std::string getEmail() const; std::string getEmail() const;
std::string getAddress() const;
virtual std::string getType() const = 0; virtual std::string getType() const = 0;
bool login(const std::string&) const; bool login(const std::string&) const;
}; };