You are on page 1of 26

INTRO TO PROGRAMMING - C++/C#, PYTHON

ONLINE SHOPPING

Submitted by: Group 3

LUONG BAO HAN IELSIU17003


TRAN THI YEN NHI IELSIU17040
PHAM THI PHUONG TRINH IEIEIU15046

Advisor: Mr. Do Vinh Truc

June 3, 2019

1
Contents
I. INTRODUCTION ..................................................................................................................... 3
Background ............................................................................................................................... 3
Aim of the study ........................................................................................................................ 3
Significance of the study ........................................................................................................... 3
II. LITERATURE REVIEW ....................................................................................................... 4
III. METHODOLOGY ................................................................................................................. 4
1. The online shopping program .............................................................................................. 4
Main Program ........................................................................................................................... 4
Add order................................................................................................................................... 5
Add account ............................................................................................................................... 6
Add product............................................................................................................................... 6
List product ............................................................................................................................... 6
Delete product ........................................................................................................................... 6
Modify product.......................................................................................................................... 6
Modify order.............................................................................................................................. 7
2. The program flowchart ........................................................................................................ 8
3. The coding process .............................................................................................................. 18
IV. CONCLUSIONS AND RECOMMENDATIONS ............................................................. 25
Conclusions .............................................................................................................................. 25
Recommendations ................................................................................................................... 26
REFERENCES ............................................................................................................................ 26

2
I. INTRODUCTION
Background
Online shopping is a form of electronic commerce which allows consumers to directly buy goods
or services from a seller over the Internet using a web browser. Consumers find a product of
interest by visiting the website of the retailer directly or by searching among alternative vendors
using a shopping search engine, which displays the same product's availability and pricing at
different e-retailers.
Aim of the study
This project was conducted for students to gain knowledge about programming skills with basic
of C/C++ and file manipulation. Online shopping management is a common type of information
system, especially with students in Computer Science and Information Technology fields. In this
problem, our group built a very simple C/C++ programs to implement some functionalities of an
online shopping management system. To simplify the system, we only stored information about
orders of users and hide warehousing-related data. Building this C/C++ structures is a basic
foundation to create a website for shopping online such as Shopee, Lazada, Tiki, Sendo, etc.
Information in online shopping system is stored in 3 files. The first one is User Information:
account.txt, the next one is Product Information: product.txt and Order Information: order.txt is
the last one.
There are six mini problems in this project and it can also serve as an introduction to relational
database through simulation on file system.
 Provide mechanisms to build user account database and login function.
 Provide mechanisms to add a product into database and list all the products.
 Provide mechanisms to list all products in the database (product.txt file) and allow user to delete
a product from the system.
 Provide mechanisms to list all products in the database (product.txt file) and allow user to
modify the price and in-store amount of a product.
 Provide mechanisms to list all products in the database (product.txt file) and allow users to add
products and specify the amount into a new order.
 Provide a mechanism for store owner to modify content of an UNPAID order.

Significance of the study


The most essential thing in this project is to help students who are capable to utilize basic control
structures of C++ to implement algorithms for specific problems in online shopping. They also
can initialize, manipulate and utilize arrays / multi-dimensional arrays in modeling data for solving
problem. Moreover, manipulating strings of characters, reading and writing from files are the skills
that students earn after doing this project.

3
II. LITERATURE REVIEW
Dev-C++ is a free integrated development environment (IDE) for programming in C/C++. Dev-
C++ is developed by Bloodshed software. In IDE, C++ is considered as a language that can be
used for two methods of writing computer programs: procedural programming and object-oriented
programming.
In procedural programming, the programmer constructs functions (procedures). The functions are
collections of programming statements that perform a specific task. The functions each contain
their own variables and commonly share variables with other functions. Procedural programming
is centered on the procedure, or function.
Object-oriented programming (OOP), on the other hand, is centered on the object. An object is a
programming element that contains data and the procedures that operate on the data. It is a self-
contained unit. The objects contain, within themselves, both information and the ability to
manipulate the information. Operations are carried out on the information in an object by sending
the object a message. When an object receives a message instructing it to perform some operation,
it carries out the instruction. Online shopping problem is a typical one of OOP.
To construct online shopping program, we use six standard headers and header files from C++
Standard Library:
1. <iostream>: Provides C++ input and output fundamentals.
2. <fstream>: Provides facilities for file-based input and output.
3. <string>: Provides the C++ standard string classes and templates.
4. <stdlib.h>: Defines numeric conversion functions, pseudo-random numbers generation
functions, memory allocation, process control function.
5. <stdio.h>: Defines core input and output functions.
6. <time.h>: Defines date- and time-handling functions.
Besides, function prototypes, which display the message, is used as a major function to construct
the program. This function simply performs one or more statements which follows terminate. The
function does not return a value to the part of the program that executed it.
void addorder();
void addaccount();
void addproduct();
void deleteproduct();
void modifyproduct();
void modifyorder();

III. METHODOLOGY
1. The online shopping program
Main Program
The program starts with the main console to ask the user to enter the username and password to
login. The shop owner will login to the menu option for the shop by entering the username as
“admin” and the password as “12345”. After logging in, the shop owner will have six options in
the menu as following: add account, add product, list product, delete product, modify product and
modify order. The shop owner can choose an option to go to different functions of the program.

4
Each option provides a mechanism for the shop owner to manage the online shop. The first option
is adding account which allows the shop owner to add a new user to the list of account and store
the information in the account.txt file. The second option which is adding product is the same as
the adding account. It allows the owner to add the product ID, name, price and the in-store quantity
of each product and then store all the information of the product in product.txt. The next option is
to list the product available in the product.txt so the owner can easily manage what products are in
the shop. The forth option is deleting any product from the list of products in product.txt by
entering the product ID that the shop owner want to remove. The next option is modifying the
product. This provide the owner a mechanism to modify the price or the in-store quantity of each
product and store the new information into the product.txt file. The last option in the menu let the
owner modify the unpaid order. The small menu has two options which are remove item or add
more items to the unpaid orders. On the other hand, if the user is not the shop owner, the program
will start to check the information of the username and password of the user. If the information is
correct, the program will let the user to start adding their orders. If the username or the password
or both are incorrect, the program will send a notification to let the user know that their information
is incorrect and ask the user to enter the information again. The flowchart of the main program is
shown in Figure 1.
Add order
This mechanism is provided for the customers of the shop. This mini program uses modifyu.txt
and modify.txt to store the information of the unpaid orders. The modify.txt store the information
of the order in the [Product ID] – [Quantity] – [Price] form while modify.txt store in the form of
[Product name] – Amount: [Quantity] – Price: [Price] to show the owner in the modifying order
mechanism. The program also stores the information of the paid orders in modifyp.txt to
distinguish with two others files. When the user login, the program will write the information of
the buyer ID and generate the order ID of each user and each time they place an order. The user
will see the whole list of products that are available in the shop. The program will first generate
the data of the date the order is placed and write into the temporary files. The program uses
temporary files to store the information of each order before writing into modify.txt, modifyu.txt,
modify.txt. The user can enter the product ID that they want to add to their orders. The program
will first check if the products exist in product.txt file or not, if the products are not available, the
program will ask the user to enter a new product ID. If the products exist, the program will ask the
user to enter the quantity of the products. The program will respectively write the product ID and
the quantity to temporary files and order.txt. The program will now open product.txt file and find
the name and the price of the product ID and then write them into modify.txt, order.txt and
temporary files. After that, the user can choose to add more items to the orders or stop. The
program will ask if the user wants to pay for their order or not. If the user wants to pay the order,
then the temporary files will write to the modifyp.txt to store a new paid order. If the user doesn’t
want to pay for the order, then the temporary files will write to the modify.txt and modifyu.txt to
store a new unpaid order. The program will finally show the whole order that has been placed by
the user. The flowchart of the adding account mini program is shown in Figure 2.

5
Add account
The first menu option for the shop owner is adding new account. The shop owner can simply add
an account by entering the name and the password of the new account. The program can generate
on its own the user ID for each new account added. After adding one account, the program allows
the owner to choose to add more account or to exit to the main menu. The new account will be
written to the account.txt for future use. The flowchart of the adding account mini program is
shown in Figure 3.
Add product
The second menu option is adding new product. A new product can be added by the shop owner
by adding the product ID, name, price and in-store quantity of the product. Just like the adding
account mechanism, the adding product program will allow the owner to add many products at
once by choosing continue to add more products. The information of the product will be stored to
product.txt for future use. The flowchart of the adding product mini program is shown in Figure
4.
List product
The listing product use the ifstream mechanism to read the product.txt file and print to the screen
all the information of the product in the file. This program helps the owner to easily managing the
available product.
Delete product
The forth menu option is to delete products from the list in product.txt. The program will first list
all the product from product.txt to let the owner know which products are available in the store.
After that, the owner will enter the product ID that he/she wants to remove from the list, if the
product ID doesn’t exist in the list, the program would not do anything. The program will write all
the information of the list to the new file which is newlist.txt while searching for the product ID
that the owner wants to remove. Once the product ID is found, the program will skip all the
information of that specific product and will not write to the newlist.txt file. After skipping all the
information of that product such as product ID, name, price, in-store, the program will continue to
write all the information that has left in the list to newlist.txt. When it comes to the end of the
product.txt, the newlist.txt will now have all the information of every product in the shop except
for the product that the owner chose to delete. The program will remove the old product.txt file
and rename the newlist.txt to product.txt. If the owner wants to continue to remove more products,
he/she can press “y” to continue or any keys to exit to main menu. The flowchart of the deleting
product mini program is shown in Figure 5.
Modify product
The next option is to modify the product price or the in-store. The program will first list all the
product from product.txt to let the owner know which products are available in the store. After
that, the owner will enter the product ID that he/she wants to modify. The program will start to
write all the information of the products in product.txt to a new file which is newlist.txt while
searching for the product ID that the owner wants to modify. When the program found the product

6
ID line that the owner wants to modify, the program will show a menu that has two options which
are modify price and modify in-store. If the owner chooses the modify price option, the program
will skip the information of the price in the product.txt file and ask the owner to enter the new
price of the product then write that new price to newlist.txt. If the owner chooses the second option
which is modify in-store, the program will write the price line of the product to newlist.txt and
then skip the in-store line. The program will now allow the owner to enter the new in-store of the
product and then write that new in-store to newlist.txt. After that, the program will write all the
information that has left from the product.txt into newlist.txt. After finishing writing all the
information to the new file, the program will remove the old file which is product.txt and replace
it with the newlist.txt and rename it into product.txt for future use. Now the user can choose to
continue to modify another product or exit to main menu. The flowchart of the modify product
mini program is shown in Figure 6.
Modify order
The last option in the menu is modifying order. This mini program only allows the owner to modify
the unpaid orders of the user. The program will first list all the order in modify.txt in the form of
[Product name] – Amount: [Quantity] – Price: [Price] for the owner to easily see the name and the
details of the order. The program will ask the owner to enter the order ID that he/she wants to
modify. While writing the information of the orders to temporary files, the program will search for
the order ID that the owner has entered. Once the order ID is found, a menu with two options of
remove item and add item will be shown. The owner can choose one option.
The first option which is to remove item will allow the owner to remove any items respectively in
the order. If the owner chooses to remove items, then the program will find the product ID and the
product name in modifyu.txt and modify.txt to skip the information of that item and will not write
to the temporary files. The owner can choose to remove more items in order or to exit.
The second option is to add item will allow the owner to add more item to the unpaid order. The
program will first show the whole list of the available products in the shop so the owner can choose.
When the owner enters the product ID and the quantity, the program will find the product name
and price in product.txt to write to modifyu.txt and modify.txt. The program allows the owner to
add more items in one run or he/she can choose to exit.
If the owner chooses to exit, then the program will write all the order information that has left to
the temporary files and then append the information from the modifyp.txt to the temporary files
and then remove all the old files and rename the temporary files to the new files with new
information. The program will ask if the owner wants to modify more orders by pressing “y” or
any keys to exit to main menu. The flowchart of the modify order mini program is shown in Figure
7, 8 and 9.

7
2. The program flowchart

8
Figure 1. Main Program Flowchart

9
Figure 2. Add Order Flowchart

10
Figure 3. Add Account Flowchart

11
Figure 4. Add Product Flowchart

12
Figure 5. Delete Product Flowchart

13
Figure 6. Modify Product Flowchart

14
Figure 7. Modify Order Flowchart

15
Figure 8. Add Item Flowchart

16
Figure 9. Remove Item Flowchart

17
3. The coding process

18
19
20
21
22
23
24
IV. CONCLUSIONS AND RECOMMENDATIONS
Conclusions
The program provides both the shop owner and the customers of the shop some useful mechanism
of an online shop. The program helps the customers to place an easy order with an easy to use
console. Moreover, the program gives the shop owner the easy access to the shop’s files and
various of functions to manage the shop.
Although the program has successfully performed all the necessary function of an online shopping
program, there are still some drawbacks. Firstly, the program hasn’t had a GUI for the user so there
are some functions that the program cannot operate. Secondly, the coding process is quite long for
an online shopping program. This causes some inconvenience for the coder in the coding process
if he/she wants to edit the code. Lastly, the program still lacks of some other functions of an online
shopping program such as to return the items, check the in-store quantity, ect.

25
Recommendations
Firstly, the code can be upgraded by adding an easy-to-use GUI for the user. The GUI can provide
some more mechanism to exit or to go back to the main menu easier. Secondly, the code should
be shortened to make it easier for the coding process. Last but not least, the coder should add more
mechanisms to the code to make it more functional to the owner and the customers of the shop.

REFERENCES
Policy, P. (2019). Dev-C++ : Introduction. [online] Onecore.net. Available at:
https://onecore.net/dev-c-introduction.htm [Accessed 26 May 2019].
Gaddis, T. (2012). Starting out with C++. 7th ed. Boston: Pearson Addison-Wesley, pp.22,23.
En.wikipedia.org. (2019). C++ Standard Library. [online] Available at:
https://en.wikipedia.org/wiki/C%2B%2B_Standard_Library [Accessed 26 May 2019].
Gaddis, T. (2012). Starting out with C++. Boston: Pearson Addison-Wesley, pp.303, 304.

26

You might also like