Skip to content

TechFlow-OOP is an object-oriented program that simulates a basic online store that sells computer-related products.

Notifications You must be signed in to change notification settings

Steven23X/Techflow-OOP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Description

TechFlow is an object-oriented program that simulates a basic online store that sells computer-related products. The program is written in C++ and follows the principle of encapsulation.


Classes


TF_String

  • is used to represent and manipulate strings of characters.

Private member variables:

  • str : type std::unique_ptr<char[]>

Constructors:

  • Default constructor.

    TF_String();
  • Constructor that takes a const char* as input.

    TF_String(const char *s);
  • Copy constructor that takes another TF_String object as input.

    TF_String(const TF_String &other);
  • Move Constructor.

    TF_String(TF_String &&other) noexcept;

Destructor:

  • Frees any dynamically allocated memory when an object of the class is destroyed.
    ~TF_String();

Overloaded operators:

  • Move assignment operator.
    TF_String& operator=(TF_String&& other) noexcept;
  • The assignment operator, operator=, which assigns one TF_String object to another.
    void operator=(const TF_String &op2);
  • The stream input operator, operator>>, which allows input from a stream into a TF_String object.
    friend std::istream &operator>>(std::istream &in, TF_String &s);
  • The stream output operator, operator<<, which allows output of a TF_String object to a stream.
    friend std::ostream &operator<<(std::ostream &out, const TF_String &s);

Methods:

  • Method that takes a const char* input and returns the length of the string.
    int str_length(const char *s);
  • Method that takes two character array inputs and copies the contents of the second array into the first.
    void str_copy(char *dest, const char *src);

TF_Vector

  • is a template class that provides a dynamic array data structure for storing a sequence of elements of type T.

Private member variables:

  • size : type int
  • data : type std::unique_ptr<T[]>
  • indexCount : type static int

Constructors:

  • Default constructor.
    TF_Vector();
  • Constructor that takes a size and an element of type T and initializes the data with the element.
    TF_Vector(int ksize, T elem);
  • Copy constructor that creates a new instance of the vector with the same size and elements as another vector.
    TF_Vector(const TF_Vector<T> &other);
  • Move Constructor.
    TF_Vector(TF_Vector &&other) noexcept;

Destructor:

  • Frees any dynamically allocated memory when an object of the class is destroyed.
    ~TF_Vector();

Overloaded operators:

  • Move assignment operator.
    TF_Vector &operator=(TF_Vector &&other) noexcept
  • The assignment operator, operator=, which assigns one TF_Vector object to another.
    void operator=(const TF_Vector<T> &other);
  • The stream input operator, operator>>, which allows input from a stream into a TF_Vector< type >.
    friend std::istream &operator>>(std::istream &in, TF_Vector<T> &vector);
  • The stream output operator, operator<<, which allows output of a TF_Vector < type > object to a stream.
    friend std::ostream &operator<<(std::ostream &out, const TF_Vector<T> &vector);
  • The subscript operator, operator[].
    T &operator[](int index);

Methods:

  • Method that is equivalent to push_back in the standard vector container.
    void pushback(T elem);
  • Getter for size.
    int getSize();
  • Static method to increment the index counter.
    static void incrementIndexCounter();
  • Static method to reset the index counter to
    static void resetIndexCounter();

TF_Customer

  • is a class that provides personal information about the customer.

Private member variables:

  • first_name : type TF_String
  • last_name : type TF_String
  • address : type TF_String
  • email : type TF_String
  • buget : type double

Constructors:

  • Default constructor : initializes all member variables to empty strings and budget to 0.
    TF_Customer();
  • Parameterized constructor that takes in the customer's first name, last name, address, email, and budget as arguments.
    TF_Customer(TF_String &first_name, TF_String &last_name, TF_String &address, TF_String &email, double budget);
  • Copy constructor that creates a new customer object with the same values as an existing customer object.
    TF_Customer(TF_Customer &other);

Destructor:

  • Frees any dynamically allocated memory when an object of the class is destroyed. (trivial)
    ~TF_Customer();

Overloaded operators:

  • The stream input operator, operator>>, which allows input from a stream into an object of class Customer.

    friend std::istream &operator>>(std::istream &in, TF_Customer &object);
  • The stream output operator, operator<<, which allows output of an object of class Customer.

    friend std::ostream &operator<<(std::ostream &out, const TF_Customer &object);

Methods:

  • Getter for budget.
    double getBudget();

TF_Product

  • is a class that provides personal information about the product.

Private member variables:

  • name : type TF_String
  • type : type TF_String
  • price : type double

Constructors:

  • Default constructor : initializes name and type to empty strings and price to 0.
    TF_Product();
  • Parameterized constructor that takes in the products's name, type, price as arguments.
    TF_Product(TF_String &name, TF_String &type, double price);
  • Parameterized constructor that takes in the products's name and price as arguments.
    TF_Product(TF_String &name, double price);
  • Copy constructor that creates a new product object with the same values as an existing product object.
    TF_Product(const TF_Product &object);

Destructor:

  • Frees any dynamically allocated memory when an object of the class is destroyed. (trivial)
    ~TF_Product();

Overloaded operators:

  • The stream input operator, operator>>, which allows input from a stream into an object of class Product.

    friend std::istream &operator>>(std::istream &in, TF_Product &object);
  • The stream output operator, operator<<, which allows output of an object of class Product.

    friend std::ostream &operator<<(std::ostream &out, const TF_Product &object);

Methods:

  • Method that applies a discount to the price of an object of the TF_Product class by a percentage specified as an integer.
    void discount(int percentage);
  • Method that applies a discount to the price of an object of the TF_Product class by a percentage specified as a double.
    void discount(double percentage);
  • Getter for price.
    double getPrice();
  • Setter for type.
    void setType(const TF_String &type);

TF_GraphicsCard

  • is a subclass of TF_Product that has the type GraphicsCard.

Private member variables:

  • memorySize : type int
  • coreClock : type int
  • memoryClock : type int

Constructors:

  • Default constructor.
    TF_GraphicsCard();
  • Parameterized constructor that takes in the products's variables and the private variables of the subclass as arguments.
    TF_GraphicsCard(TF_String &name, double price, int memorySize, int coreClock, int memoryClock);
  • Copy constructor that creates a new product object with the same values as an existing product object.
    TF_GraphicsCard(const TF_GraphicsCard &other);

Destructor:

  • Frees any dynamically allocated memory when an object of the class is destroyed. (trivial)
    ~TF_GraphicsCard();

Methods

  • From TF_DisplayInterface:
    void displayRow() override;
    void displayColumn() override;

TF_Processor

  • is a subclass of TF_Product that has the type Processor.

Private member variables:

  • coreCount : type int
  • coreClock : type int
  • socket : type TF_String

Constructors:

  • Default constructor.
    TF_Processor();
  • Parameterized constructor that takes in the products's variables and the private variables of the subclass as arguments.
    TF_Processor(TF_String &name, double price, int coreCount, int coreClock, TF_String socket);
  • Copy constructor that creates a new product object with the same values as an existing product object.
    TF_Processor(const TF_Processor &other);

Destructor:

  • Frees any dynamically allocated memory when an object of the class is destroyed. (trivial)
    ~TF_Processor();

Methods

  • From TF_DisplayInterface:
    void displayRow() override;
    void displayColumn() override;

TF_MotherBoard

  • is a subclass of TF_Product that has the type MotherBoard.

Private member variables:

  • slots : type int
  • processor_socket : type TF_String
  • chipset : type TF_String

Constructors:

  • Default constructor.
    TF_MotherBoard();
  • Parameterized constructor that takes in the products's variables and the private variables of the subclass as arguments.
    TF_MotherBoard(TF_String &name, double price, int slots, TF_String processor_socket, TF_String chipset);
  • Copy constructor that creates a new product object with the same values as an existing product object.
    TF_MotherBoard(const TF_MotherBoard &other);

Destructor:

  • Frees any dynamically allocated memory when an object of the class is destroyed. (trivial)
    ~TF_MotherBoard();

Methods

  • From TF_DisplayInterface:
    void displayRow() override;
    void displayColumn() override;

TF_Order

  • is a class that provides information about the order.

Private member variables:

  • customer : type TF_Customer
  • products : type TF_Vector< TF_Product >
  • date : type TF_String

Constructors:

  • Default constructor.
    TF_Order();
  • Parameterized constructor that takes in the orders's customer, products, date as arguments.
    TF_Order(TF_Customer customer, TF_Vector<TF_Product> products, TF_String date);
  • Copy constructor that creates a new product object with the same values as an existing product object.
    TF_Order(TF_Order &other);

Destructor:

  • Frees any dynamically allocated memory when an object of the class is destroyed. (trivial)
    ~TF_Order();

Overloaded operators:

  • The stream output operator, operator<<, which allows output of an object of class Order.
    friend std::ostream &operator<<(std::ostream &out, const TF_Order &object);

Methods:

  • Method that returns the total price of all products.
    double orderTotal();
  • Method that returns the total price after charge.
    double addCharge(double charge);
  • Method that returns the remaining budget.
    double verifyBudget(double value);

TF_PaymentMethod

  • represents an abstract base class for handling different payment methods.

Protected member variables:

  • order : type TF_Order

  • paymentDetails : type TF_String

  • isPaymentComplete : type bool Constructors

  • Creates objects.

    TF_PaymentMethod();
    TF_PaymentMethod(TF_Order order,TF_String paymentDetails,bool isPaymentComplete);

Destructor:

  • It ensures that when objects of derived classes are deleted through pointers to the base class PaymentMethod, the appropriate destructor of the derived class will be called, allowing for proper cleanup of any resources allocated in the derived classes.
    virtual ~TF_PaymentMethod();

Methods:

  • An abstract method that represents the process of processing a payment for a given amount.
    virtual void processPayment(float amount) = 0;
  • Method that displays the payment information, including the payment method name, payment details, and payment status.
    void displayPaymentInfo();
  • A protected abstract method that represents the name of the payment method.
    virtual TF_String getPaymentMethodName() = 0;

TF_Cash

  • is a subclass of TF_PaymentMethod that takes the customers cash for checkout.

Constructors

  • Creates objects.
    TF_Cash();
    TF_Cash(TF_Order order, TF_String paymentDetails, bool isPaymentComplete);

Destructor:

  • Destroys object.
    ~TF_Cash() {}

Methods:

  • method that represents the process of processing a payment.
    void processPayment() override;
  • Method that returns the name of the payment method.
    TF_String getPaymentMethodName();

TF_CreditCard

  • is a subclass of TF_PaymentMethod that takes the customers creditcard for checkout.

Private member variables:

  • cardNumber : type TF_String
  • cardHolderName : type TF_String

Constructors

  • Creates objects.
    TF_CreditCard();
    TF_CreditCard(TF_Order order, TF_String paymentDetails, bool isPaymentComplete, TF_String cardNumber, TF_String cardHolderName);

Destructor:

  • Destroys object.
    ~TF_CreditCard(){}

Methods:

  • method that represents the process of processing a payment.
    void processPayment() override;
  • Method that returns the name of the payment method.
    TF_String getPaymentMethodName();

Interfaces

TF_DisplayInterface

  • is a interface for TF_Product that displays the information based on the children type.

Virtual Destructor:

  • It ensures that when objects of derived classes are deleted through pointers to the base class PaymentMethod, the appropriate destructor of the derived class will be called, allowing for proper cleanup of any resources allocated in the derived classes.
    virtual ~TF_DisplayInterface() {}

Pure virtual methods:

  • A method that displays the information in row format.
    virtual void displayRow() = 0;
  • A method that displays the information in column format.
    virtual void displayColumn() = 0;

Exceptions

TF_Exception

  • is a custom exception class.

Private member variables:

  • errorMessage : type string

Methods:

  • override from std::exception.

    explicit TF_Exception(const char *error_message);
    const char *what() const noexcept override;

Features

TBA


Task 1

Classes

  • You must respect the principle of encapsulation.
  • Define at least 5 classes.
  • All classes will have constructors.
  • At least 3 classes must be correlated by composition.

Methods

  • At least 3 methods that operate on class member data.
  • At least one method will be overloaded.

Input and Output

  • For at least one class overload the operator << and operator >>.

Dynamic Allocation

Both TF_String and TF_Vector use Dynamic Allocation.

  • At least one class must dynamically allocate memory.
  • At least one class that dynamically allocates memory will have a copy constructor and an operator = implemented.
  • All dynamically allocated memory must be properly deallocated.
  • At least one class must have a non-trivial destructor.

Interactive Menu

  • Read from keyboard and create at least 3 types of objects among those defined.
  • Display these objects, after they have been read by the application.
  • Call a method on them.
  • Implement the move constructor and overload the move operator = for at least one class that manages dynamically allocated memory.

Task 2

Inheritance

  • At least two different inheritance hierarchies.
  1. Product Hierarchy - TF_Product -> TF_GraphicsCard, TF_Processor, TF_MotherBoard.
  2. Payment Method Hierarchy - TF_PaymentMethod -> TF_CreditCard, TF_Cash.
  • At least two different access modifiers on the inherited class .

  • public and protected.

  • At least one class that uses multiple inheritance.

  • TF_GraphicsCard, TF_Processor, TF_MotherBoard use TF_Product and the interface.

  • Call at least once a constructor (with parameters) from a base class, using an initialization list in the child class's constructor.

  • At least two data members and at least one method with the protected access modifier.

  • In TF_PaymentMethod.

Interfaces and Virtual Methods

  • Define and extend at least one interface that has at least two methods.

  • TF_DisplayInterface.

  • Define and extend at least one abstract base class.

  • TF_PaymentMethod.

  • Identify in the project at least one situation where the virtual destructor needs to be called.

  • When deleting pointer after downcasting.

  • Define at least four virtual methods that will be overridden in subclasses.

  • TF_DisplayInterface and TF_PaymentMethod.

Execution Polymorphism

  • Identify at least four places where runtime polymorphism occurs.

  • When using the interface.

  • Identify at least four instances of upcasting.

  • Products of different types in vector.

  • Perform downcasting in at least one situation in your code, using dynamic_cast or RTTI.

  • Getting Details of a Product.

Exceptions

  • Define at least one custom exception type that extends std::exception.
  • Throw exceptions in at least four different functions/methods.
  • Implement at least one try...catch block that catches an exception thrown and handles it in a specific way.
  • Implement at least one try...catch block that catches an exception, processes it, and rethrows another type of exception from the catch block.

Variables and Static Methods

  • Define a static member variable in at least one class.
  • Implement at least two static methods in your classes.

Smart Pointers and Lambda Expressions

  • Use smart pointers for dynamic allocations from your project instead of raw pointers with new and delete.
  • Use at least two lambda expressions to parameterize the functionality of a function or a class.

Task 3

Generic Programming

  • Use at least one user-defined template class. (TF_Vector)
  • Define and call at least one template function.
  • Use the template class and function defined above in at least one place in your project.

Design Patterns

  • Choose a pattern that is either already implemented in your project
  • Strategy Pattern : Payment Method Hierarchy - TF_PaymentMethod -> TF_CreditCard, TF_Cash.
  • The Strategy pattern suggests that you take a class that does something specific in a lot of different ways and extract all of these algorithms into separate classes called strategies.
  • The original class(TF_PaymentMethod), called context, must have a field for storing a reference to one of the strategies (TF_CreditCard, TF_Cash). The context delegates the work to a linked strategy object instead of executing it on its own.

Standard Library

  • Use at least two different container data types from the STL. - vector and map
  • Use at least one utility function from the standard library. - sort

Smart Pointers

  • Replace manual dynamic allocation with smart pointers.

Const and Utility Library

  • Use the const modifier correctly wherever possible and meaningful in the program.
  • Use a utility library from the standard library.
  • Used for choosing a random product in the store.

About

TechFlow-OOP is an object-oriented program that simulates a basic online store that sells computer-related products.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages