You are on page 1of 54

INDEX

SNO CONTENT PG NO.

1. OVERVIEW OF C++ 1

2. SYNOPSYS 3

3. SYSTEM REQUIREMENTS 4

4. HEADER FILES USED 5

5. BUILT IN FUNCTIONS USED 6

6. USER DEFINED FUNCTIONS USED 7

7. STRUCTURES AND OBJECTS 8

8. SOURCE CODE 9

9. OUTPUT 41

10. CONCLUSION 52

11. FUTURE ENHANCEMENT 53

12. BIBLIOGRAPHY 54
OVERVIEW OF C++

C++ is a general purpose programming language with imperative,


object oriented and generic programming features and facility for low level
memory manipulation. It was designed with a bias towards system
programming and embedded resource constrained and large systems, with
performance, efficiency and flexibility of use of its design highlights.

It was developed by Bjarne Stoustroup, a Danish computer scientist,


in 1979. Stoustroup developed this language with a name of “C with classes”
and later in 1983 it was renamed to C++ as a successor to the C language.
The ++ denotes the incrementaion done to the C language which was the
base for the emergence of C++. Inily Stoustroup added the features of
classes, derived classes, strong typing, inlining, default arguments, virtual
functions, operator overloading, references, constants, single line comments
using “//”.

PHILOSOPHY OF C++:

Throughout the life of C++, its development and evolution has been
guided by a set of principles:

 It must be driven be actual problems and its features should be useful


in real world programs.
 Every feature should be implementable.
 Programmers should be free to pick their own programming style, and
that style should be fully supported by C++.
 Allowing a useful feature is more important than preventing every
possibe misuse of C++.
 It should provide facilities for organising programs into well-defined
separate parts, and provide facilities for combining separately
developed parts.
 User-created types need to have the same support and performance as
built-in types.
 Unused features should not negatively impact created executables.
 There should be no language beneath C++ (except assembly language).
 C++ should work alongside other existing programming languages,
rather than fostering its own separate and incompatible programming
environment.
C++ introduced Object Oriented Programming (OOP) to C language. The
Object Oriented Programming is a programming paradigm based on the
concept of classification of data into classes and objects. The OOP has
various features and some of the features which are implemented in C++
are:

DATA ENCAPSULATION:

Encapsulation is an object-oriented programming concept that binds


together the data and functions that manipulate the data, and that keeps
both safe from outside interference and misuse. Data encapsulation led to
the important OOP concept of data hiding.

DATA ABSTRACTION:

Data abstraction refers to providing only essential information to the


outside world and hiding their background details i.e., to represent the
needed information in program without presenting the details.

MODULARITY:

Modularity refers to a software designtechnique that emphasises


seperating the functionality of a program into independent, interchangable
modules, such that each contains everythig necessary to execute only one
aspect of the desired fuction.

INHERITANCE:

The capability of a class to derive properties and characteristics from


another class is call the Inheritance.

POLYMORPHISM:

The representaion of a member function in various forms is known as


polymorphism i.e., different ways of approaching the same data.
SYNOPSYS

Online shopping has been a usual way of buying our needs nowadays.
Many websites have been prominent in providing their needs to the people
like Flipkart, Amazon etc. These websites have been built by high level
programming languages. Although a similar website can be built using C++.
The main objective of this project is to develop a mini e-commerce website
and providing the options for both administrators and users to access the
site. The program can be broadly devided into two menus:

ADMINISTRATOR MENU: To add, delete, modify the goods and to update


the stocks of the present goods. Password is neceesary to access the menu.

USER MENU: To view the goods list, order the required goods. The ordered
goods are sent to the cart and proceeded for further operations. In the cart,
the user can checkout, delete specific items in the cart and can cancel the
full order and exit the page. During checkout, the user will be shown of their
bill with the grand total (including tax and delivery charge). Then the user
has to provide the address information and the information about the mode
of payment. After all this process, the order will be placed and a greeting
message will be displayed to the user and redirected to the home page.
SYSTEM REQUIREMENTS

Processor: Intel Pentium III and above

Hard Disk: 1 GB or above

RAM: 1 GB or above

OS: Windows XP or above

Compiler: Turbo C++/Dev C++/Code Blocks etc.

Language: C++
HEADER FILES USED

iostream.h - For using the basic i/o functions.

fstream.h - For creating, writing and reading .dat files.

iomanip.h - For setting the width of the output statement.

conio.h - For using functions like clrscr() and getch()

graphics.h - For changing the background colour of the o/p screen

stdlib.h - For using functions like gets() etc.

process.h - For using the exit() function.

stdio.h - For using the functions like remove() etc.

string.h - For using fuctions like strcmp().


BUILT-IN FUNCTIONS USED

clrscr() - To clear the output screen.

gets() - To get a string/sentence.

setw() - To set the width of the output statement.

open() - To open a file.

read() - To read a created file.

write() - To write in a created file.

remove() - To delete the file pointed by the parameter.

rename() - To rename a file.

getch() - To display the output in the output screen.


USER DEFINED FUNCTIONS USED

home() - To display the homepage.

getdata() - To get the details of the product.

dispdata() - To display the details of the product.

basket() - To see the items in the cart.

create1() - To create a detail database of products.

addfile() - To add a product to the product database.

delfile() - To delete a product.

delfile2() - To delete product from the cart.

modfile() - To modify the record of a product.

bill() - To view the bill.

stock() - To update the stock present.

electronics() - To view the electronics page.

home_needs() - To view the home needs page.

fashion() - To view the fashion page.

misc() - To the miscellaneous items page.

shopping() - To view the user shopping page.

admin() - To view the administrator menu page.

main() - The main fuction of the program.


STRUCTURES AND OBJECTS

Site:

i) it contains the following members:

code (float) - to store the item code.

decsy[30] (char) - to store the item description.

Price (float) - to store the price of the item.

Cat (int) - to store the category of the item.

Qon (int) - to store the quantity of the goods.

ii) it contains the following functions:

getdata() - to get the information about the goods.

Dispdata() - to display the goods details.

iii) it is used to store all the information regarding the items present
for sale in the website.

.dat files used:

Basket.dat - used to store the items in the cart.

Products.dat - used to store the items availabe in the site.

Tempu2.dat - used as a temporary file.


SOURCE CODE

#include<fstream.h>

#include<iostream.h>

#include<stdio.h>

#include<iomanip.h>

#include<conio.h>

#include<graphics.h>

#include<stdlib.h>

#include<process.h>

#include<string.h>

void home();

struct purchase

float code;

float price;

};
struct site

float code;

char decsy[30];

float price;

int cat;

int qon;

void dispdata();

void getdata()

clrscr();

cout<<"\n\n\nEnter the category: \n\n1. ELECTRONICS";

cout<<"\n\n\n2. FASHION\n\n\n3. HOME NEEDS\n\n\n4.


MISCELLANEOUS\n\n\nEnter ur choice: ";

cin>>cat;

cout<<endl;

clrscr();

cout<<"Enter the code no of the item: ";

cin>>code;

cout<<endl;

cout<<"Enter description: ";

gets(decsy);

cout<<endl;
cout<<"Enter the price: ";

cin>>price;

cout<<endl;

cout<<"Enter the quantity: ";

cin>>qon;

cout<<"New item has been added!";

};

void site::dispdata()

cout<<setw(5)<<code<<setw(30)<<decsy<<setw(15)<<price<<setw(10)<
<qon<<endl;

cout<<endl<<endl;

void basket(int p)

fstream fb;

fstream fp;
fb.open("product.dat",ios::in|ios::binary);

fp.open("basket.dat",ios::app|ios::binary);

site s;

fb.read((char *)&s,sizeof(s));

do

if(p==s.code)

s.dispdata();

s.qon--;

cout<<"\n";

cout<<endl;

fp.write((char *)&s,sizeof(s));

fb.read((char *)&s,sizeof(s));

}while(fb);

fb.close();

fp.close();

}
void main()

home();

void create1()

clrscr();

cout<<"\n\n";

site s;

fstream fb;

fb.open("product.dat",ios::out|ios::binary);

char rep;

do

s.getdata();

fb.write((char *)&s,sizeof(s));

cout<<"\n\n\t Want to add more records? (y/n): ";

cin>>rep;

}while(rep=='y' || rep=='Y');

fb.close();
getch();

void addfile()

clrscr();

cout<<"\n\n";

site s;

fstream fb;

fb.open("product.dat",ios::app|ios::binary);

char rep;

do

s.getdata();

fb.write((char *)&s,sizeof(s));

cout<<"\n\n\tWant to add more records? (y/n): ";

cin>>rep;

}while(rep=='y' || rep=='Y');

fb.close();
getch();

void delfile()

clrscr();

int r;

char rep;

site s;

cout<<" \n\n\nEnter the item code u want to delete: ";

cin>>r;

fstream fb,ft;

fb.open("product.dat",ios::in|ios::binary);

ft.open("tempu.dat",ios::out|ios::binary);

int flag=0;

fb.read((char *)&s,sizeof(s));

do

if(r!=s.code)

{
ft.write((char *)&s,sizeof(s));

else

flag++;

fb.read((char *)&s,sizeof(s));

}while(fb);

fb.close();

ft.close();

if(flag==0)

cout<<"No such item exists!\n\n";

else

cout<<"\nITEM HAS BEEN DELETED!\n\n";

remove("product.dat");

rename("tempu.dat","product.dat");

cout<<"\n\nTo move back, press 0\n ";


cout<<"To delete more product, press any other digit: ";

int d;

cin>>d;

if(d==0)

return;

else

delfile();

void modfile()

clrscr();

int r;

char rep;

site s;

cout<<"Enter the item code u want to modify: ";

cin>>r;

fstream fb,ft;

fb.open("product.dat",ios::in|ios::binary);

ft.open("tempu.dat",ios::out|ios::binary);

fb.read((char *)&s,sizeof(s));
do

if(r==s.code)

cout<<setw(5)<<"CODE"<<setw(25)<<"DESCRIPTION"<<setw(15)<<"PRI
CE"<<setw(5)<<"QUANTITY";

s.dispdata();

cout<<"Enter new data: \n";

getch();

s.getdata();

ft.write((char *)&s,sizeof(s));

else

ft.write((char *)&s,sizeof(s));

cout<<"\nNo such item exists!\n";

cout<<"\nPress press enter to go back";

getch();

return;

getch();
fb.read((char *)&s,sizeof(s));

}while(fb);

ft.close();

fb.close();

remove("product.dat");

rename("tempu.dat","product.dat");

cout<<"\n\nTo move back, press 0\n";

int d;

cin>>d;

if(d==0)

return;

void bill()

clrscr();

void delfile2();

site s;

fstream fj;

fj.open("basket.dat",ios::in|ios::binary);

cout<<"\nYour cart has following items\n\n";


cout<<setw(10)<<"NAME"<<setw(32)<<"CODE"<<setw(15)<<"PRICE"<<
endl;

float sum=0;

fj.read((char *)&s,sizeof(s));

do

cout<<setw(20)<<s.decsy<<setw(15)<<s.code<<setw(15)<<s.price;

cout<<"\n\n";

sum+=s.price;

fj.read((char *)&s,sizeof(s));

}while(fj);

fj.close();

int choice,cho,ed,em,cvv,atmpin;

long no;

getch();

clrscr();

cout<<"\n\n\nTo Checkout, press 1\n";

cout<<"\nTo delete items from cart, press 2\n";

cout<<"\nTo reject full order and exit, press 3\n\n";

cout<<"Enter your choice: ";

cin>>choice;

switch(choice)
{

case 1:

char add[150];

cout<<"\n\nYour bill amount is Rs. "<<sum;

float tax=0.008*sum;

cout<<"\n\nTax on your billed amount is Rs. "<<tax;

cout<<"\n\nThe Grand total is Rs. "<<sum+tax;

getch();

cout<<"\n\nEnter your residence address: ";

gets(add);

cout<<"\nEnter your mode of payment: \n1. Credit/Debit


card\n2.Paytm\n3.Cash on Delivery";

cout<<"\nEntery our choice: ";

cin>>cho;

switch(cho)

case 1:

cout<<"\nEnter your 12 digit card number: ";

cin>>no;

cout<<"\nEnter the CVV: ";

cin>>cvv;

cout<<"\nEnter the ATM PIN: ";

cin>>atmpin;

cout<<"\nTransaction successful!";

break;
case 2:

cout<<"\nEnter the phone number linked to paytm account: ";

cin>>no;

cout<<"\nPayment successfully made!";

break;

case 3:

cout<<"\nOrder placed successfully";

cout<<"\nPlease ensure the full payment of bill at the time of


delivery\n";

cout<<"Your product will be delivered to you within 2 days\n";

cout<<"\nThank you for shopping with us!";

getch();

break;

case 2:

delfile2();

break;

case 3:

exit(0);

}
void stock()

clrscr();

int r;

char rep;

site s;

cout<<"Enter the item code u want to update: ";

cin>>r;

fstream fb,ft;

fb.open("product.dat",ios::in|ios::binary);

ft.open("tempu2.dat",ios::out|ios::binary);

fb.read((char *)&s,sizeof(s));

do

if(r==s.code)

cout<<"\n\nOld quantity is ";

cout<<s.qon;

cout<<"\n\nEnter new quantity: ";

getch();
cin>>s.qon;

ft.write((char *)&s,sizeof(s));

cout<<"\n\nNew quantity has been registered!\n";

else

ft.write((char *)&s,sizeof(s));

cout<<"\nNo such item exists!\n";

cout<<"\nPress enter to go back ";

getch();

return;

getch();

fb.read((char *)&s,sizeof(s));

}while(fb);

ft.close();

fb.close();

remove("product.dat");

rename("tempu2.dat","product.dat");

cout<<"\n\nTo move back, press 0\n";


int d;

cin>>d;

if(d==0)

return;

void delfile2()

int r;

char rep;

site s;

cout<<"Enter the item code u want to delete: ";

cin>>r;

fstream fb,ft;

fb.open("basket.dat",ios::in|ios::binary);

fb.open("tempu1.dat",ios::out|ios::binary);

int flag=0;

fb.read((char *)&s,sizeof(s));

do

if(r!=s.code)

{
ft.write((char *)&s,sizeof(s));

else

flag++;

fb.read((char *)&s,sizeof(s));

}while(fb);

ft.close();

fb.close();

if(flag==1)

cout<<"ITEM DELETED";

cout<<"No. of items deleted are "<<flag;

else

cout<<"\n NO ITEMS DELETED ";

remove("basket.dat");

rename("tempu1.dat","basket.dat");

cout<<"\n\nTo Check out 0";

int d;

cin>>d;

if(d==0)

return;
}

void electronics()

site t;

fstream fp;

fp.open("product.dat",ios::in|ios::binary);

clrscr();

fp.read((char *)&t,sizeof(t));

cout<<endl<<endl;

cout<<setw(5)<<"CODE"<<setw(15)<<"DESCRIPTION"<<setw(15)<<"PRI
CE"<<setw(10)<<"QUANTITY";

cout<<endl<<endl;

do

if(t.cat==1)

t.dispdata();

fp.read((char *)&t,sizeof(t));

}while(fp);

fp.close();

int toad,l,m;

cout<<"To return back, press 2, to buy press 1:\t";


cin>>l;

if(l==2)

return;

else

int ch;

do

cout<<"\nTo add the product to your cart, enter the product


code from the list:\t"<<endl;

cin>>toad;

basket(toad);

cout<<"\nThe product you have chosen has been added to your


cart!n";

cout<<"\n\nTo Continue your shopping press 1, To go to


homepage, press 2:\t";

cin>>ch;

}while(ch!=2);

void home_needs()

site t;
fstream fp;

fp.open("product.dat",ios::in|ios::binary);

clrscr();

fp.read((char *)&t,sizeof(t));

cout<<endl<<endl;

cout<<setw(5)<<"CODE"<<setw(25)<<"DESCRIPTION"<<setw(15)<<"PRI
CE"<<setw(5)<<"QUANTITY";

cout<<endl<<endl;

do

if(t.cat==3)

t.dispdata();

fp.read((char *)&t,sizeof(t));

}while(fp);

fp.close();

int toad,l,m;

cout<<"To return back, press 2, to buy press 1:\t";

cin>>l;

if(l==2)

return;

else

int ch;
do

{ cout<<"\nTo add the product to your cart, enter the product


code from the list:\t";

cin>>toad;

basket(toad);

cout<<"\nThe product you have chosen has been added to your


cart!\n";

cout<<"\n\nTo Continue your shopping press 1, To go to


homepage, press 2:\t";

cin>>ch;

} while(ch!=2);

void misc()

site t;

fstream fp;

fp.open("product.dat",ios::in|ios::binary);

clrscr();

fp.read((char *)&t,sizeof(t));

cout<<endl<<endl;

cout<<setw(5)<<"CODE"<<setw(25)<<"DESCRIPTION"<<setw(15)<<"PRI
CE"<<setw(5)<<"QUANTITY";

cout<<endl<<endl;
do

if(t.cat==4)

t.dispdata();

fp.read((char *)&t,sizeof(t));

}while(fp);

fp.close();

int toad,l,m;

cout<<"To return back, press 2, to buy press 1:\t";

cin>>l;

if(l==2)

return;

else

int ch;

do

{ cout<<"\nTo add the product to your cart, enter the product


code from the list:\t";

cin>>toad;

basket(toad);

cout<<"\nThe product you have chosen has been added to your


cart!\n";

cout<<"\n\nTo Continue your shopping press 1, To go to


homepage, press 2:\t";

cin>>ch;
} while(ch!=2);

void fashion()

site t;

fstream fp;

fp.open("product.dat",ios::in|ios::binary);

clrscr();

fp.read((char *)&t,sizeof(t));

cout<<endl<<endl;

cout<<setw(5)<<"CODE"<<setw(15)<<"DESCRIPTION"<<setw(15)<<"PRI
CE"<<setw(10)<<"QUANTITY";

cout<<endl<<endl;

do

if(t.cat==2)

t.dispdata();

fp.read((char *)&t,sizeof(t));

}while(fp);

fp.close();
int toad,l,m;

cout<<"To return back, press 2, to buy press 1:\t";

cin>>l;

if(l==2)

return;

else

int ch;

do

{ cout<<"\nTo add the product to your cart, enter the product code
from the list:\t";

cin>>toad;

basket(toad);

cout<<"\nThe product you chose has been added to your cart!";

cout<<"\n\nTo Continue your shopping press 1, To go to


homepage, press 2:\t";

cin>>ch;

} while(ch!=2);

}
void shopping()

clrscr();

int w;

cout<<"\n\n----------------------------------------------------------------------
----------";

cout<<" WELCOME TO WALLMART ONLINE


SHOPPING\n";

cout<<"-----------------------------------------------------------------------------
---\n\n";

cout<<" \n1. ELECTRONICS\n\n";

cout<<" \n2. FASHION\n\n";

cout<<" \n3. HOME NEEDS\n\n";

cout<<" \n4. MISCELLANEOUS\n\n";

cout<<" \n5. BACK\n";

cout<<endl<<endl<<"Enter your choice: ";

cin>>w;

switch(w)

case 1:

electronics();

break;

case 2:

fashion();

break;
case 3:

home_needs();

break;

case 4:

misc();

break;

case 5:

home();

break;

void admin()

int c;

do

clrscr();

cout<<endl<<endl<<endl<<endl;

cout<<" \t\t\t WELCOME TO ADMINISTRATOR MODE\n\n ";

cout<<"\n\t\tMENU: \n\n";

cout<<"\t\t1. CREATE FOR FIRST TIME (This will erase all previous
data)\n\n\n";
cout<<"\t\t2. ADD PRODUCT \n\n\n";

cout<<"\t\t3. DELETE A PRODUCT \n\n\n";

cout<<"\t\t4. MODIFY\n\n\n";

cout<<"\t\t5. STOCK UPDATION\n\n\n";

cout<<"\t\t6. BACK \n\n\n";

cout<<"\t\tEnter your choice: ";

cin>>c;

switch(c)

case 1:

char ch;

clrscr();

cout<<"\n\n\tAre you sure to erase all previous data?(y/n): ";

cin>>ch;

if(ch=='y')

create1();

else

return;

break;

case 2:

addfile();

break;

case 3:

delfile();

break;
case 4:

modfile();

break;

case 5:

stock();

break;

case 6:

return;

}while(c!=5);

void home()

textbackground(3);

textcolor(0);

fstream fp;

fp.open("basket.dat",ios::out|ios::binary);

fp.close();

int ch;

do
{

clrscr();

cout<<"\n\n----------------------------------------------------------------------
----------";

cout<<" WELCOME TO WALLMART ONLINE


SHOPPING\n";

cout<<"-----------------------------------------------------------------------------
---\n\n";

cout<<"\t\t1. ADMINISTOR MENU \n\n\n";

cout<<"\t\t2. SHOPPING MENU \n\n\n";

cout<<"\t\t3. YOUR CART\n\n\n";

cout<<"\t\t4. EXIT \n\n\n";

cout<<" Enter your choice: ";

cin>>ch;

switch(ch)

case 1:

clrscr();

char *pass;

gotoxy(7,12);

pass = getpass("Enter the password:");

if(strcmp(pass,"2003")==0)

admin();

else
cout<<"\n\nWrong password!\n\n";

getch();

break;

case 2:

shopping();

break;

case 3:

bill();

break;

case 4:

exit(0);

break;

}while(ch!=4);

}
OUTPUT

Home page:

Administrator menu – password verification:

Password: 2003
Administrator Menu:

Create for first time – verification:


Create for first time:

Category – Electronics:
Add product:
Delete a product:
Modify a product:
Stock Updation:

User Menu:
Electronics Menu:

Fashion Menu:
Home Needs menu:

Miscellaneous menu:
Buying goods:

Shopping Cart:
CONCLUSION

Thus a simple online shopping website have been created with C++.
This website has various real time features like password verification,
administrator maintanance, different mode of payments, payment
verification, stock maintanance etc. This simple website can be dynamically
developed with other advanced languages. For convinience puroposes, user
registration and login have not been included in the website. Thanks to all
those who have helped with our project.
FUTURE ENHANCEMENTS

In future, certain advanced features can be added to the program such as:

1. Including user registration and login.

2. Using advanced graphics features to design the website.

3. Scrolling option to browse across long menus.

4. Search engine to access the goods quickly.

5. Broad range of products to users.

6. Adding more information to products by dividing the products into


more subcategories.

7. Allowing multiple administrators to access the site.


BIBILIOGRAPHY

1. Let Us C++ - BPB Publications

2. Computer Science with C++ - Danpat Rai Publications

3. Learning C++ and Data Structures - Margham Publications

4. Wikipedia (for C++ Introduction)

You might also like