C++ PROJECT WITH DFH | PRODUCT MANAGEMENT SYSTEM - Working Code

/*Specially for the students of Class-12 of CBSE. It is a complete working code with proper presentation and password security system. 

Just download and go through it. */

#include<fstream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdio.h>
#include<string.h>
#include<process.h>

//Function Prototyping
void line(int=80);//Function to draw line
void adminmenu(); //Function to display operation options for admin user
void guestmenu(); //Function to display operation options for guest user
void adminOps();  //Function with admin menu options
void guestOps();  //Function with guest menu options
void header();   //header to displayed on each page
void login();   //login section admin or guest
void Add();   //Adding data to binary file
void Display();   //Reading binary file
void Search();   //Searching in binary file
void Delete();   //Deleting record in binary file
void Modify();   //Modify product in binary file
void ViewTrash(); //Deleted data in binary file
void intro();   //First page of the project.
void login();   //Function for admin or guest login option
void usermenu();  //Function to display user options
void admin();     //Function to display admin options
void conclude();  //Function to display conclude message.

class Product
{
int pid;
char pname[20];
char category[20];
int qty;
float rate;
float amount;

public:
int getID(){return pid;}
float getAmount(){return amount;}
void getData();
void showData();
void listView();
void heading();
}p;

void Product::getData()
{
cout<<"ENTER PRODUCT DETAILS\n";
line(50);
cout<<"Product ID: "; cin>>pid;
cout<<"Name      : "; cin.ignore(); cin.getline(pname,20);
cout<<"Category  : "; cin.getline(category,20);
cout<<"Qty.      : "; cin>>qty;
cout<<"Rate      : "; cin>>rate;
amount=qty*rate;
line(50);
}

void Product::showData()
{
cout<<"PRODUCT DETAILS\n";
line(50);
cout<<"Product ID: "<<pid<<endl;
cout<<"Name      : "<<pname<<endl;
cout<<"Category  : "<<category<<endl;
cout<<"Qty.      : "<<qty<<endl;
cout<<"Rate      : "<<rate<<endl;
cout<<"Amount    : "<<amount<<endl;
line(50);
}

void Product::heading()
{
cout.setf(ios::left);
cout<<setw(6)<<"ID"
    <<setw(20)<<"Name"
    <<setw(20)<<"Category"
    <<setw(5)<<"Qty"
    <<setw(8)<<"Rate"
    <<setw(11)<<"Amount"
    <<endl;
line(70);
}

void Product::listView()
{
cout.setf(ios::left);
cout<<setw(6)<<pid
    <<setw(20)<<pname
    <<setw(20)<<category
    <<setw(5)<<qty
    <<setw(8)<<rate
    <<setw(11)<<amount
    <<endl;
}

void Add()
{
header();
ofstream fout("prods.bin",ios::out|ios::binary|ios::app);
p.getData();
fout.write((char*)&p,sizeof(p));
fout.close();
cout<<"\nData Saved to File....\n";
}

void Display()
{
int rec=0;
float total=0;
ifstream fin;
fin.open("prods.bin",ios::in|ios::binary);
while(fin.read((char*)&p,sizeof(p)))
{
if(rec<1)
{
header();
p.heading();
}
//p.showData();
p.listView();
rec++;
total+=p.getAmount();
}
fin.close();
line(70);
cout<<setw(59)<<"Total Amount: "<<setw(11)<<total<<endl;
line(70);
cout<<"\nData displayed....\n";
}

void Search()
{
int n,flag=0;
header();
cout<<"Enter Id to search: ";
cin>>n;
fstream fin;
fin.open("prods.bin",ios::in|ios::binary);
while(fin.read((char*)&p,sizeof(p)))
{
if(n==p.getID())
{
p.showData();
flag++;
}
}
fin.close();
if(flag==0)
cout<<"The Product ID: "<<n<<" not found....\n";
}

void Delete()
{
int n,flag=0;
header();
cout<<"Enter Id to delete: ";
cin>>n;
ifstream fin;
ofstream fout,out;
fin.open("prods.bin",ios::in|ios::binary);
fout.open("temp.bin",ios::out|ios::binary);
out.open("trash.bin",ios::out|ios::binary|ios::app);
while(fin.read((char*)&p,sizeof(p)))
{
if(n==p.getID())
{
cout<<"Following record is deleted from file...\n";
p.showData();
out.write((char*)&p,sizeof(p));
flag++;
}
else
{
fout.write((char*)&p,sizeof(p));
}
}
fin.close();
fout.close();
out.close();
if(flag==0)
cout<<"The Product ID: "<<n<<" not found....\n";
remove("prods.bin");
rename("temp.bin","prods.bin");
}

void Modify()
{
int n,flag=0,pos;
header();
cout<<"Enter Id to modify: ";
cin>>n;
fstream fio;
fio.open("prods.bin",ios::in|ios::out|ios::binary);
while(fio.read((char*)&p,sizeof(p)))
{
if(n==p.getID())
{
pos=fio.tellg();
cout<<"Following record will be modified:\n";
p.showData();
flag++;
fio.seekg(pos-sizeof(p));
p.getData();
fio.write((char*)&p,sizeof(p));
cout<<"\nRecord Modified Successfully....\n";
}
}
fio.close();
if(flag==0)
cout<<"The Product ID: "<<n<<" not found....\n";
}

void ViewTrash()
{
int rec=0;
ifstream fin;
fin.open("trash.bin",ios::in|ios::binary);
while(fin.read((char*)&p,sizeof(p)))
{
if(rec<1)
{
header();
p.heading();
}
//p.showData();
p.listView();
rec++;
}
fin.close();
cout<<"\nData displayed....\n";
}

void line(int n)
{
int i;
for(i=1;i<n;i++)
cout<<"=";
cout<<endl;
}

void header()
{
line();
cout<<"\t\t\tPRODUCT MANAGEMENT SYSTEM\n";
line();
cout<<endl;
}

void intro()
{
clrscr();
header();
cout<<"Project Incharge: Narendra Aliani\n";
cout<<"This project is all about to know the following features\n"
    <<"1. How data is stored in the data file.\n"
    <<"2. How data is displayed from file.\n"
    <<"3. Searching, deleting and modifying of data is featured\n"
    <<"4. Secured with password protection\n"
    <<"5. Guest Login without password also available.\n";
line();
getch();
}

void conclude()
{
clrscr();
header();
cout<<"Thanks for using out project.....\n";
cout<<"Press any key to exit....\n";
getch();
exit(0);
}

void usermenu()
{
clrscr();
header();
cout<<"###################\n";
cout<<" U S E R   M E N U\n";
cout<<"###################\n";
cout<<"0. Exit\n";
cout<<"1. Admin\n";
cout<<"2. Guest\n";
cout<<"Enter your choice: ";
}

void adminmenu()
{
header();
cout<<"########################\n";
cout<<" A D M I N   M E N U \n";
cout<<"########################\n";
cout<<"0. Back to User Menu\n";
cout<<"1. Add Data\n";
cout<<"2. Show Data\n";
cout<<"3. Search Data\n";
cout<<"4. Delete Data\n";
cout<<"5. Modify Data\n";
cout<<"6. View Deleted Data\n";
cout<<"Enter your choice: ";
}

void guestmenu()
{
header();
cout<<"########################\n";
cout<<" G U E S T   M E N U \n";
cout<<"########################\n";
cout<<"0. Back to User Menu\n";
cout<<"1. Show Data\n";
cout<<"2. Search Data\n";
cout<<"Enter your choice: ";
}

void adminOps()
{
int ch;
do
{
clrscr();
adminmenu();
cin>>ch;
clrscr();
switch(ch)
{
case 0: login(); break;
case 1: Add(); break;
case 2: Display(); break;
case 3: Search(); break;
case 4: Delete(); break;
case 5: Modify(); break;
case 6: ViewTrash(); break;
}getch();
}while(ch);
}

void guestOps()
{
int ch;
do
{
clrscr();
guestmenu();
cin>>ch;
clrscr();
switch(ch)
{
case 0: login(); break;
case 1: Display(); break;
case 2: Search(); break;
}
getch();
}while(ch);
}

void admin()
{
char c, cpwd[20],pwd[]="password";
int i=0;
cout<<"Enter Password: ";
do
{
c=getch();
if(c!=13)
{
cpwd[i]=c;
cout<<"*";
i++;
}
else
{
cpwd[i]='\0';
i++;
}
}while(c!=13);

if(strcmp(pwd,cpwd)==0)
{
cout<<"\nPassword Matched....\n";
cout<<"Welcome Admin.....\n";
cout<<"Press any key to continue.\n";
getch();
adminOps();
}
else
{
cout<<"\nUnauthorized access....\n";
}
}

void login()
{
int ch;
do
{
usermenu();
cin>>ch;
switch(ch)
{
case 0: conclude(); break;
case 1: admin(); break;
case 2: guestOps(); break;
}getch();
}while(ch);
}

void main()
{
intro();
login();
}


Download the working file by clicking here....


1 comment:

  1. In this manner my friend Wesley Virgin's report starts in this SHOCKING and controversial VIDEO.

    Wesley was in the military-and shortly after leaving-he unveiled hidden, "MIND CONTROL" tactics that the CIA and others used to obtain anything they want.

    As it turns out, these are the exact same methods tons of celebrities (notably those who "became famous out of nowhere") and elite business people used to become rich and famous.

    You probably know that you use less than 10% of your brain.

    Really, that's because the majority of your brainpower is UNCONSCIOUS.

    Perhaps this expression has even taken place INSIDE OF YOUR very own mind... as it did in my good friend Wesley Virgin's mind about seven years back, while riding a non-registered, trash bucket of a car without a license and $3 in his bank account.

    "I'm very fed up with living paycheck to paycheck! When will I become successful?"

    You took part in those types of conversations, ain't it right?

    Your own success story is going to start. Go and take a leap of faith in YOURSELF.

    Learn How To Become A MILLIONAIRE Fast

    ReplyDelete

Post your comments

Powered by Blogger.