report in cpp (3)
report in cpp (3)
Guided by:
Smt . B. R. Amrutkar
Lecturer Government Polytechnic Pune
1
DEPARTMENT OF COMPUTER ENGINEERING
ACADEMIC YEAR : 2024-25
CERTIFICATE
This is to certify that the micro-project entitled “ Online
Shopping Management System” is bonafide work carried out
by: Anuja Shirole – 2306176 of class Second Year in
partial fulfillment of the requirement for the completion of
course Object Oriented Programming (CM31203) - ODD
2024 of Diploma in Computer Engineering from
Government Polytechnic Pune. The report has been
approved as it satisfies the academic requirements in respect
of micro-project work prescribed for the course.
Project Report
Background
2
This code implements a basic Online Shopping System in C++, where users can browse prod-
ucts, add items to their shopping cart, and checkout. The system consists of three main compo-
nents: the Product class, representing individual items; the Cart class, managing the user's se-
lected products and calculating the total price; and the OnlineShop class, which integrates the
product catalog and cart functionality. Users interact through a simple menu, allowing them to
view products, add items to their cart, and complete purchases. The code provides a foundation
for simulating an online shopping experience.
Objectives
The project aims to Online Shopping Management System implement a functional using C++
to manage key operations such as:
1. Simulate an Online Shopping Experience: Provide a basic framework where users can
browse products, add them to a cart, and proceed to checkout.
2. Product Management: Represent products with key attributes (ID, name, price) and dis-
play them to users in a catalog.
3. Shopping Cart Functionality: Allow users to add items to their cart, view the cart's con-
tents, and calculate the total cost of selected items.
4. User Interaction: Create an interactive command-line interface where users can choose
actions such as viewing products, adding to cart, and checking out.
5. Basic Checkout System: Simulate the checkout process by calculating the total price of
items in the cart and displaying a confirmation message upon successful checkout.
Structure Used
2. Cart Class :
o Attributes :
3
checkout(): Displays the total cost of the cart items and checks out.
OnlineShop Class:
Attributes :
productCatalog: A vector containing available Product objects.
userCart: A Cart object to store products added by the user.
Methods:
displayProducts(): Shows all products available in the catalog.
addToCart(): Adds a product to the cart by its ID.
viewCart(): Displays the current cart contents.
3. Vectors:
Used to store collections of objects, specifically products in the catalog and products in
the cart (vector<Product>).
Methods like push_back() are used to add products to the vectors.
4. Methods:
display() in Product to print details.
addProduct(), viewCart(), and checkout() in Cart to manage items.
addToCart(), viewCart(), and checkout() in OnlineShop to provide user interac-
tion
o View products.
o Checkout.
It uses a do-while loop to keep asking for user input until the user decides to exit.
Appropriate methods of the OnlineShop class are called based on the user’s choice
7. Basic Input/Output:
Input: The user enters choices and product IDs.
4
Output: The system provides feedback like displaying products, confirming cart addi-
tions, and showing the total price at checkout.
Technical Approach :
The technical approach of the Online Shopping System utilizes object-oriented programming
(OOP) principles, structuring the application into distinct classes: Product, Cart, and
OnlineShop. Each class encapsulates relevant attributes and methods to manage products, user
carts, and the shopping process. The system employs std::vector for dynamic storage of
products, allowing easy addition and management of items. A menu-driven interface facilitates
user interaction through a loop that captures choices, using a switch statement to direct actions
like viewing products, adding to the cart, or checking out. This design promotes extensibility and
scalability, enabling future enhancements, such as adding new features or products, while
ensuring code efficiency and maintainability.
Object-Oriented Approach:
Encapsulation: The design uses separate classes for Product, Cart, and OnlineShop, which en-
capsulates related attributes and behaviors. This separation reduces complexity, as each class
manages its specific responsibilities, making the code easier to understand and maintain.
Abstraction: By utilizing classes, the implementation details are hidden, allowing users to inter-
act with the system through clear, well-defined methods (e.g., addProduct(), viewCart()). This
simplifies the interface and enhances usability.
Class Structure:
Product Class: This class represents individual items, capturing essential details (ID,
name, price). This structure allows easy management and display of products.
Cart Class: By separating cart functionality into its own class, the design focuses on
managing user selections, enabling easy modifications to cart operations without affecting
product management.
OnlineShop Class: This class integrates product management and cart functionality,
serving as the main interface for user interactions, promoting cohesion within the system.
5
5. Control Flow:
Switch Statement: Using a switch statement for handling user choices streamlines the
code, making it easy to read and modify. It clearly delineates the possible actions based on
user input, promoting maintainability.
Cos Covered:
• CO1 Understand procedural and object-oriented paradigms.
6
Flowchart Chart:
Program :
#include <iostream>
#include <vector>
#include <string>
7
using namespace std;
class Product
public:
int id;
string name;
double price;
cout << "Product ID: " << id << ", Name: " << name << ", Price: $" << price <<
endl;
};
class Cart
private:
vector<Product> items;
public:
8
{
items.push_back(product);
if (items.empty())
} else {
item.display();
double total = 0;
total += item.price;
return total;
9
void checkout() const
if (items.empty())
} else {
cout << "Your total is: $" << total << endl;
cout << "Thank you for shopping with us!" << endl;
};
class OnlineShop
private:
vector<Product> productCatalog;
Cart userCart;
public:
OnlineShop()
10
void displayProducts() const
product.display();
if (product.id == productId)
userCart.addProduct(product);
return;
cout << "Product with ID " << productId << " not found." << endl;
userCart.viewCart();
11
void checkout() const
userCart.checkout();
};
int main()
OnlineShop shop;
int choice;
int productId;
do
switch (choice)
case 1:
shop.displayProducts();
break;
case 2:
12
cout << "Enter the Product ID to add to cart: ";
shop.addToCart(productId);
break;
case 3:
shop.viewCart();
break;
case 4:
shop.checkout();
break;
case 5:
break;
default:
return 0;
OUTPUT :
13
Skills Developed :
1. Problem-Solving
2. C++ Programming
3. File Management:
4. Object-Oriented Design
14
5. Debugging and Error Handling
6. File Input/Output Operations
7. Version Control and Code Organization
8. User Interface Design
9. Critical Thinking
Conclusion :
__________________________
15