Computer Science Project C++
Computer Science Project C++
1. OVERVIEW OF C++ 1
2. SYNOPSYS 3
3. SYSTEM REQUIREMENTS 4
8. SOURCE CODE 9
9. OUTPUT 41
10. CONCLUSION 52
12. BIBLIOGRAPHY 54
OVERVIEW OF C++
PHILOSOPHY OF C++:
Throughout the life of C++, its development and evolution has been
guided by a set of principles:
DATA ENCAPSULATION:
DATA ABSTRACTION:
MODULARITY:
INHERITANCE:
POLYMORPHISM:
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:
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
RAM: 1 GB or above
Language: C++
HEADER FILES USED
Site:
iii) it is used to store all the information regarding the items present
for sale in the website.
#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();
cin>>cat;
cout<<endl;
clrscr();
cin>>code;
cout<<endl;
gets(decsy);
cout<<endl;
cout<<"Enter the price: ";
cin>>price;
cout<<endl;
cin>>qon;
};
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));
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));
cin>>rep;
}while(rep=='y' || rep=='Y');
fb.close();
getch();
void delfile()
clrscr();
int r;
char rep;
site s;
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)
else
remove("product.dat");
rename("tempu.dat","product.dat");
int d;
cin>>d;
if(d==0)
return;
else
delfile();
void modfile()
clrscr();
int r;
char rep;
site s;
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();
getch();
s.getdata();
ft.write((char *)&s,sizeof(s));
else
ft.write((char *)&s,sizeof(s));
getch();
return;
getch();
fb.read((char *)&s,sizeof(s));
}while(fb);
ft.close();
fb.close();
remove("product.dat");
rename("tempu.dat","product.dat");
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);
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();
cin>>choice;
switch(choice)
{
case 1:
char add[150];
float tax=0.008*sum;
getch();
gets(add);
cin>>cho;
switch(cho)
case 1:
cin>>no;
cin>>cvv;
cin>>atmpin;
cout<<"\nTransaction successful!";
break;
case 2:
cin>>no;
break;
case 3:
getch();
break;
case 2:
delfile2();
break;
case 3:
exit(0);
}
void stock()
clrscr();
int r;
char rep;
site s;
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<<s.qon;
getch();
cin>>s.qon;
ft.write((char *)&s,sizeof(s));
else
ft.write((char *)&s,sizeof(s));
getch();
return;
getch();
fb.read((char *)&s,sizeof(s));
}while(fb);
ft.close();
fb.close();
remove("product.dat");
rename("tempu2.dat","product.dat");
cin>>d;
if(d==0)
return;
void delfile2()
int r;
char rep;
site s;
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";
else
remove("basket.dat");
rename("tempu1.dat","basket.dat");
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;
if(l==2)
return;
else
int ch;
do
cin>>toad;
basket(toad);
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;
cin>>l;
if(l==2)
return;
else
int ch;
do
cin>>toad;
basket(toad);
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;
cin>>l;
if(l==2)
return;
else
int ch;
do
cin>>toad;
basket(toad);
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;
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);
cin>>ch;
} while(ch!=2);
}
void shopping()
clrscr();
int w;
cout<<"\n\n----------------------------------------------------------------------
----------";
cout<<"-----------------------------------------------------------------------------
---\n\n";
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<<"\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\t4. MODIFY\n\n\n";
cin>>c;
switch(c)
case 1:
char ch;
clrscr();
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<<"-----------------------------------------------------------------------------
---\n\n";
cin>>ch;
switch(ch)
case 1:
clrscr();
char *pass;
gotoxy(7,12);
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:
Password: 2003
Administrator Menu:
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: