Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 23

ONLINE SHOPPING CART

PROJECT REPORT
Submitted by
DHIVYA.S
Register No: AAAAAA

DATA STRUCTURES LABORATORY


(III SEMESTER)

KARPAGAM COLLEGE OF ENGINEERING


(Autonomous)
COIMBATORE – 641 032

OCTOBER 2019
CERTIFICAT
E
Certified that this project report titled “ONLINE SHOPPING CART” is the

bonafide work of Ms. S.DHIVYA who carried out the project under my

supervision. Certified further, that to the best of my knowledge the work reported

herein does not form part of any other project report.

I understand the policy on plagiarism and declare that the project and publications

are my own work, except where specifically acknowledged and has not been

copied from other sources or been previously submitted for award or assessment.

XXXXXXXXX XXXXXXXX

Project Guide Faculty In-charge

Submitted for the Project Viva-Voce examination held on ____________

Examiner I Examiner
Online Shopping Cart Page |1

ABSTRACT

This is a small scale project for Online Women shopping system. The basic idea is
that customers can by products using online. The administrator can enter the name
and" password" and can create an account and then generate the receipt of the
products purchased. The Online Women Shopping system enables vendors to set
up online shops, customers to browse through the shops' and a system
administrator to approve and reject requests for new shops and maintain lists of
shop categories. Also on the agenda is designing an online shopping site to manage
the items in the shop and also help customers purchase them online without having
to visit the shop physically. Our online shopping mall will use the internet as the
sole method for selling goods to its consumers. Shopping will be highly
personalized and the mall will provide lower prices than most competitors. It is an
online store that enables website owners to sell their product online. It is a web
shopping cart that we! Enables the day-day sales functions. It includes product and
customer management modules. This website will be useful to anyone who wants
to purchase items using internet
Online Shopping Cart Page |2

S.NO. TITLE PAGE NO.

TABLE OF CONTENTS

LIST OF FIGURES

LIST OF TABLES

LIST OF ABBREVIATIONS
1 PROBLEM DEFINITION

2 REQUIREMENTS SPECIFICATION

2.1 HARDWARE REQUIREMENTS

2.2 SOFTWARE REQUIREMENTS

3 DATA STRUCTURE USED

4 ALGORITHM DESIGN

3.1 ALGORITHM

5 SOURCE CODE

6 RESULTS & DISCUSSION

7 CONCLUSION

8 BIBLIOGRAPHY
Online Shopping Cart Page |2

LIST OF FIGURES

SNO FIGURE NAME PAGE NO

1 Fig 3.1 Stack 10

2 Fig 7.1:Output 1 26
Online Shopping Cart Page |2

LIST OF TABLES

SNO TABLE NAME PAGE NO

1 Table 2.1: aaa aa

2 Table 5.2: bbb bb


Online Shopping Cart Page |2

LIST OF ABBRIVATIONS

LIFO Last In First Out

AAA Aaaaaa Aaaaa Aaaaa


Online Shopping Cart Page |2

1 PROBLEM DEFINITION

Shopping cart is a very important feature used in e-commerce to assist people


making purchases online, similar to the US English term ‘shopping cart’. The business-to-
consumer aspect of electronic commerce (e-commerce) is the most visible business use of the
World Wide Web. The primary goal of an e-commerce site is to sell goods and services online. E-
commerce is fast gaining ground as an accepted and used business paradigm. More and more
business houses are implementing web site providing functionality for performing commercial
transactions over the web. It is reasonable to say that the process of shopping on the web is
becoming commonplace.

There are mainly 5 main modules in this software

 Adding Products to Shopping Cart using Stacks.


 Deleting Products from the Shopping Cart.
 Poping out a last seen Product using Stacks.
 Provide Product list with the cost.
 User can select a limited number of products.

In this software we can add products in cart remove it and if we need we can view the last
added product. The cart also provides the cost of each product as well as total cost of product in
cart.
Online Shopping Cart Page |2

2 REQUIREMENT SPECIFICATION

2.1 HARDWARE REQUIREMENTS

Processor : Core i3/ i5/ i7

RAM : 128 MB

Hard Disk : 20GB

Monitor : 15” Color monitor

Key Board : 104 Keys

2.2 SOFTWARE REQUIREMENTS

Operating System : Windows 7/8.

Language : C ++

Software : Turbo Cpp compiler


Online Shopping Cart Page |2

3 DATA STRUCTURE USED

Stacks

A stack is a container of objects that are inserted


and removed according to the last-in first-out
(LIFO) principle. In the pushdown stacks only
two operations are allowed: push the item into
the stack, and pop the item out of the stack. A
stack is a limited access data structure - elements
can be added and removed from the stack only at
the top. push adds an item to the top of the stack,
pop removes the item from the top. A helpful
analogy is to think of a stack of books; you can
remove only the top book, also you can add a
new book on the top.

A stack is a recursive data structure. Here is a


structural definition of a Stack: Fig 3.1 :Stack

a stack is either empty or


it consistes of a top and the rest which is a
stack;

Applications
 The simplest application of a stack is to reverse a word. You push a given word to stack -
letter by letter - and then pop letters from the stack.
 Another application is an "undo" mechanism in text editors; this operation is
accomplished by keeping all text changes in a stack.

 Language processing:

o space for parameters and local variables is created internally using a stack.
Online Shopping Cart Page |2

o compiler's syntax check for matching braces is implemented by using stack.

o support for recursion

4 ALGORITHM DESIGN
Online Shopping Cart Page |2

4.1 ALGORITHM

Insert()

Check if elements_in_cart = capacity


Print cart is full
do

call function display_category


get product code
get product cost
call function display_products_in_category
check while is_product_exists
call function get_product_details
call function getnode();
assign product_code using function get_product_key
assign product_cost using pdtls.product_cost;

remove()
check if list is NULL
if yes print no cart to remove
assign p=list;
assign list=list->next;
print all details in cart

display()
assign p=list;
check if p is NULL
if yes print no cart to display
initialize loop
print all product details in cart

currentTotal()
check if list is NULL
if yes print no cart to remove
initialize loop
calculate cost of product
print the details of product with cost
print total cost of cart

5 SOURCE CODE

#include<iostream>
Online Shopping Cart Page |2

#include<string>
#include<cstdlib>
#include<cstdio>
#include<getopt.h>
#include<cstring>
#include<map>

void cart :: insert()


{
product p;
int n, cat, pcode;

cout << "ele" << elements_in_cart << " " << capacity <<"\n";

if (elements_in_cart == capacity)
{
printf("cart is full\n");
return;
}
do
{
display_category();
//cout << "\n enter the product code\n";
cin >> cat;
//cout << "\n enter the product cost\n";
display_products_in_category(cat);
cin >> pcode;
} while(!is_product_exists(cat, pcode));

ProductDetails pdtls = get_product_details(cat, pcode);


p=getnode();
p->product_code = get_product_key(cat, pcode);
p->product_cost = pdtls.product_cost;
memset(p->product_name, '\0', PRODUCT_NAME_LEN);
strcpy(p->product_name, pdtls.product_name);
p->next=list;
list=p;
elements_in_cart++;
}
void cart :: remove()
{
product p;
if(list==NULL)
{
cout << "There are no products in the cart to remove\n";
Online Shopping Cart Page |2

return;
}
p=list;
list=list->next;
cout << "\n removed product from the cart is:" << "product code: " << p->product_code << "
product name: " << p->product_name << " product cost: "<< p->product_cost << "\n";
}
void cart :: display()
{
product p;
p=list;
if(p==NULL)
cout << "\n There are no products in the cart to display\n";

for (p=list;p!=NULL;p=p->next)
{
cout << "product code: " << p->product_code << " product name: " << p->product_name <<"
product cost: "<< p->product_cost << "\n";
}
}

void cart :: currentTotal()


{
product p;
int total_cost=0;
p=list;
if(p==NULL)
cout << "\n There are no products in the cart to display\n";

for (p=list;p!=NULL;p=p->next)
{
total_cost+=p->product_cost;
cout << "product code: " << p->product_code << " product name: " <<p->product_name <<"
product cost: "<< p->product_cost << "\n";
}
cout << "Current total cost :" << total_cost << "\n";
}

void print_usage(char *exe) {


printf("Usage: %s [-h] -p <products detail file absolute path>\n", exe);
}

int get_product_key(int category, int product_code)


{
return category * PRODUCT_KEY_MULTIPLIER + product_code;
}
Online Shopping Cart Page |2

std::string trim(const std::string& str,


const std::string& whitespace = " \t\n")
{
const std::size_t strBegin = str.find_first_not_of(whitespace);
if (strBegin == std::string::npos)
return ""; // no content

const std::size_t strEnd = str.find_last_not_of(whitespace);


const std::size_t strRange = strEnd - strBegin + 1;

return str.substr(strBegin, strRange);


}

bool insert_menu_item(const ProductDetails & pdtls)


{
std::map<int, std::string>::iterator itr = p_category.find(pdtls.product_cat_code);

if(itr != p_category.end())
{

#ifdef DEBUG
std::cout << "product category is already added, "
<< "category code => " << pdtls.product_cat_code
<< " category name => " << pdtls.product_category
<< " proceeding to add sub items"
<< endl;
#endif

ProductMenu::iterator mitr = p_menu.find(pdtls.product_cat_code);

if(mitr == p_menu.end())
{
std::cout << " item is addd to p_category but can not find in p_menu size => " << p_menu.size()
<< endl;
return false;
}

mitr->second.insert(std::pair<int, std::string>(pdtls.product_code,
std::string(pdtls.product_name)));
#ifdef DEBUG
std::cout << "added sub menu item to the existing category, p_menu size => " << p_menu.size()
<< endl;
#endif
}
else
Online Shopping Cart Page |2

{
p_category.insert(std::pair<int, std::string> (pdtls.product_cat_code,
std::string(pdtls.product_category)));
std::map<int, std::string> ps_menu;
ps_menu.clear();
ps_menu.insert(std::pair<int, std::string>(pdtls.product_code, std::string(pdtls.product_name)));
p_menu.insert(std::pair<int, std::map<int, std::string> >(pdtls.product_cat_code, ps_menu));
#ifdef DEBUG
std::cout << "item added to p_menu and now the size is => " << p_menu.size() << endl;
#endif
}

return true;
}

void display_category()
{
std::map<int, std::string>::iterator itr = p_category.begin();

std::cout << " Choose the category from the below list " << endl;
for(; itr != p_category.end(); ++itr)
{
std::cout << itr->first << " => " << itr->second << endl;
}
std::cout << endl;
}

bool display_products_in_category(int cat)


{
ProductMenu::iterator itr = p_menu.find(cat);
if(itr == p_menu.end())
{
std::cout << "Invalid category selected. Please, select the correct category again " << endl;
return false;
}

std::cout << "Select the product from the below menu " << endl;
std::map<int, std::string>::iterator sitr = itr->second.begin();
for(; sitr != itr->second.end(); ++sitr)
{
std::cout << sitr->first << " => " << sitr->second << endl;
}
std::cout << endl;

return true;
}
Online Shopping Cart Page |2

ProductDetails get_product_details(int cat, int pcode)


{
int pkey = get_product_key(cat, pcode);
std::map<int, ProductDetails>::iterator itr = stock_details.find(pkey);
return itr->second;
}

bool is_product_exists(int cat, int pcode)


{
int pkey = get_product_key(cat, pcode);
std::map<int, ProductDetails>::iterator itr = stock_details.find(pkey);

return itr != stock_details.end();


}

#endif
pdtls.product_cat_code = atoi(value.c_str());
break;
case 1:
memset(pdtls.product_category, '\0', PRODUCT_NAME_LEN);
strcpy(pdtls.product_category, value.c_str());
#ifdef DEBUG
cout << "category name => " << value << endl;
#endif
break;
case 2:
pdtls.product_code = atoi(value.c_str());
#ifdef DEBUG
cout << "product code => " << value << endl;
#endif
break;
case 3:
memset(pdtls.product_name, '\0', PRODUCT_NAME_LEN);
strcpy(pdtls.product_name, value.c_str());
#ifdef DEBUG
cout << "product name=> " << value << endl;
#endif
case 4:
value = trim(line.substr(sindex));
pdtls.product_cost = atoi(value.c_str());
#ifdef DEBUG
cout << "product price Rs. => " << value << endl << endl;
#endif
break;
Online Shopping Cart Page |2

default:
cout << "got more than expected number of delimiters. Ignoring additional values " << endl;
continue;
}
++n;

if(n == MAX_DELIMITER_PER_LINE)
{
std::pair<std::map<int, ProductDetails>::iterator, bool> ret;
int pkey = get_product_key(pdtls.product_cat_code, pdtls.product_code);
ret = stock_details.insert(std::pair<int, ProductDetails>(pkey, pdtls));

if(ret.second == false)
{
std::cout << "product key : " << pkey
<< " already exists. please, check the product details files with unique entries " << endl;
fclose(fptr);
return false;
}

insert_menu_item(pdtls);
}
found = line.find_first_of(":", sindex);
}
memset(buf, '\0', MAX_CHARS_PER_LINE);
}
return true;
}

void display_product_details()
{
std::map<int, ProductDetails>::iterator itr = stock_details.begin();

for(; itr != stock_details.end(); ++itr)


{
std::cout << "product key => " << itr->first << endl;
std::cout << "product category code => " << itr->second.product_cat_code << endl;
std::cout << "product category name => " << itr->second.product_category << endl;
std::cout << "product code => " << itr->second.product_code << endl;
std::cout << "product name => " << itr->second.product_name << endl;
std::cout << "product cost => " << itr->second.product_cost << endl;
std::cout << endl << endl;
}
}

int main(int argc, char *argv[])


Online Shopping Cart Page |2

{
//extern char *optarg;
//extern int optind;
cart c1;
int choice,n,option;
string product_file;

if(argc < 2)
{
cout << "Invalid usage. Please check the usage below" << endl;
print_usage(argv[0]);
exit(EXIT_FAILURE);
}

//Specifying the expected options


//The two options l and b expect numbers as argument
while ((option = getopt(argc, argv,"hp:")) != -1) {
switch (option) {
case 'p' :
cout << "got the file " << endl;
product_file = optarg;
cout << "assigned the file " << product_file << endl;
break;
case 'h' :
print_usage(argv[0]);
exit(EXIT_SUCCESS);
break;
case '?':
cout << " ? Invalid usage. Please check the usage below" << endl;
print_usage(argv[0]);
exit(EXIT_FAILURE);
break;
default:
cout << " default : Invalid usage. Please check the usage below" << endl;
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
}

cout << "getting the stock details" << endl;


bool status = get_stock_details(product_file);

if(!status)
{
cout << "Failed to load stock details from the file. Please check the file :"
<< product_file << endl;
Online Shopping Cart Page |2

exit(EXIT_FAILURE);
}

#ifdef DEBUG
display_product_details();
#endif

cout << "\n enter the cart size: ";


cin >> n;
c1.init(n);
do
{
cout << "\n\t1:add an element into the cart \n\n\t2:remove an element from the cart
\n\n\t3:display elements in the cart\n\n\t";
cout << "4:show last product \n\n\t5:show current total \n\n\t6:exit\n\n\n";
cout << "\nenter your choice:";
cin >> choice;
switch(choice)
{
case 1:
c1.insert();
break;
case 2:
c1.remove();
break;
case 3:
c1.display();
break;
case 4:
c1.showtop();
break;
case 5:
c1.currentTotal();
break;
case 6:
c1.freenode();
break;
}
}while(choice != 6);
return 0;
}
Online Shopping Cart P a g e | 17

6 RESULT AND DISCUSSION

Description:

As we add the items to the cart the price of the items are calculated and displayed.
Online Shopping Cart P a g e | 18

7 CONCLUSION

Our project is a humble venture to satisfy the need of customer who do the online
shopping.. Several user friendly coding have also adopted. This package shall prove to be a
powerful package in satisfying all the requirements of the customer as well as organization.

The objective of software planning is to provide a frame work that enables the
manger to make reasonable estimates made within a limited time frame at the beginning of the
software project and should be updated regularly as the project progresses.
Online Shopping Cart P a g e | 18

8 BIBLIOGRAPHY

1) http://www.tutorialspoint.com/cplusplus/

2) Data Structures And Algorithm Analysis In C++ by Mark Allen Weiss

3) Introduction To Algorithm –Third Edition By Cormen.

4) http://scanftree.com/Data_Structure/

You might also like