0% found this document useful (0 votes)
51 views14 pages

Computer Science Class 12 Project-C++

This C++ program defines classes for eyewear, billing, and customer data. It includes functions to input, output, update, search, and delete eyewear records stored in a binary file. The update functions allow adding, editing, or deleting eyewear data by brand, model number, price, quantity, or other fields. A menu drives the program to call the appropriate function for common operations on the eyewear records.

Uploaded by

Harsh Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views14 pages

Computer Science Class 12 Project-C++

This C++ program defines classes for eyewear, billing, and customer data. It includes functions to input, output, update, search, and delete eyewear records stored in a binary file. The update functions allow adding, editing, or deleting eyewear data by brand, model number, price, quantity, or other fields. A menu drives the program to call the appropriate function for common operations on the eyewear records.

Uploaded by

Harsh Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 14

#include<fstream.

h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<ctype.h>

struct date
{
int dd, mm, yy ;
} ;

class eyewear
{
char type[20];
char brand[20];
char shape[20];
char fcolour[20];
char gcolour[20];
char model_num[10];
char desc[20];
int price;
int qty;
date dop;

public :

void input ()
{
cout<<"\n Enter Type : ";
gets(type);
cout<<"\n Enter Brand : ";
gets(brand);
cout<<"\n Enter Shape : ";
gets(shape);
cout<<"\n Enter Frame Colour : ";
gets(fcolour);
cout<<"\n Enter Glass colour : ";
gets(gcolour);
cout<<"\n Enter Model Number : ";
gets(model_num);
cout<< "\n Enter Description : ";
gets(desc);
cout<<"\n Enter date of purchase ";
cout<<"\n Date : " ; cin>>dop.dd;
cout<<"\n Month : "; cin>>dop.mm;
cout<<"\n Year : " ; cin>>dop.yy;
cout<<"\n Enter price : ";
cin>>price;
cout<<"\n Enter Quantity : ";
cin>>qty;
}
void output()
{
cout<<"\n Type "<<type;
cout<<"\n Brand "<<brand;
cout<<"\n Shape "<<shape;
cout<<"\n Frame Colour "<<fcolour;
cout<<"\n Glass colour "<<gcolour;
cout<<"\n Model Number "<<model_num;
cout<<"\n Description "<<desc;
cout<<"\n Purchased on "<<dop.dd<<":"<<dop.mm<<":"<<dop.yy ;
cout<<"\n Price "<<price;
cout<<"\n Quantity "<<qty;
}
char* ret_model()
{ return model_num ; }
int ret_price()
{ return price ; }
int ret_qty ()
{ return qty ; }
char* ret_brand()
{ return brand ; }
int ret_date()
{ return dop.dd ; }
int ret_month()
{ return dop.mm ; }
int ret_year()
{ return dop.yy ; }
char* ret_desc()
{ return desc ; }
char* ret_shape()
{ return shape ; }

} ;

class billing
{
protected :
int bill_no;
char model_num[10] ;
date dos;
float gtotal ;
float gst;
float disc;
float ntotal;

public :
void input()
{
cout<<"\n Enter Bill number " ;
cin>>bill_no;
cout<<"\n Enter Model number " ;
cin>>model_num;
cout<<"\n Enter Date of Selling ";
cout<<"\n Date " ; cin>>dos.dd ;
cout<<"\n Month "; cin>>dos.mm ;
cout<<"\n Year "; cin>>dos.yy ;
cout<<"\n Enter Grand Total ";
cin>>gtotal;
cout<<"\n Enter Tax ";
cin>>gst;
}
void output ()
{
cout<<"\n Bill number "<<bill_no; ;
cout<<"\n Model number "<<model_num; ;
cout<<"\n Date of Selling "<<dos.dd<<":"<<dos.mm<<":"<<dos.yy;
cout<<"\n Grand Total "<<gtotal;
cout<<"\n Tax "<<gst;
ntotal= (gtotal+gst) - disc ;
cout<<"\n Net total "<<ntotal;
}
void print_bill ();
char* ret_model()
{ return model_num ;}
int ret_billno()
{ return bill_no ;}
float ret_gtotal()
{ return gtotal; }
float ret_gst()
{ return gst; }
int ret_date()
{ return dos.dd ;}
int ret_month()
{ return dos.mm; }
int ret_year ()
{ return dos.yy ;}

};

class customer : public billing


{
char cname[30];
char cphone[10];
char address[30];

public :
void input()
{
cout<<"\n Enter customer name ";
gets(cname);
cout<<"\n Enter phone ";
gets(cphone);
cout<<"\n Enter Address " ;
gets(address);
}

void output()
{
cout<<"\n Customer name "<<cname;
cout<<"\n Phone "<<cphone;
cout<<"\n Address "<<address;

char* ret_cname()
{ return cname ;}
char* ret_cphone()
{ return cphone ;}

} ;

void add_frames()
{
ofstream f1 ("frames.bat",ios::binary ) ;
eyewear e;
char ch;
do
{
e.input();
f1.write( (char*)&e, sizeof(e) );
cout<<"\n CONTINUE ? ";
cout<<"\n Press y for yes and n for no ";
cin>>ch;
} while(ch=='y' || ch=='Y' );
f1.close() ;
}

void update_price()
{
fstream f1 ("frames.bat", ios::binary|ios::ate ) ;
eyewear e;
float price;
char ch;
char mod[10];
cout<<"\n Enter model number for which price is to be updated " ;
gets(mod);
f1.read( ( char* )&e, sizeof(e) ) ;
while(f1.read( ( char* )&e, sizeof(e) ) )
{
if( strcmpi(e.ret_model() , mod )==0 )
{
cout<<"\n Original Price "<<e.ret_price();
cout<<"\n Enter new price " ;
cin>>price;
e.ret_price()==price; //logical error. How to overwrite
data in a file?
cout<<"\n Price successfully changed to "<<e.ret_price();
}
}
f1.close();
}

void update_qty()
{
fstream f1 ("frames.bat",ios::binary|ios::ate ) ;
eyewear e;
int qty, a;
char ch;
char mod[10];
cout<<"\n Enter model number for which quantity is to be updated " ;
gets(mod);
f1.read( ( char* )&e, sizeof(e) ) ;
while(f1.read( ( char* )&e, sizeof(e) ) )
{
if( strcmpi(e.ret_model() , mod)==0)
{
cout<<"\n Original quantity "<<e.ret_qty();
cout<<"\n Enter number of products to be added " ;
cin>>qty;
a = e.ret_qty();

cout<<"\n Final quantity "<<e.ret_qty();

}
}
f1.close();
}

void update_details()
{
fstream f1 ("frames.bat",ios::binary|ios::ate ) ;
eyewear e;
char ch;
char mod[10];
cout<<"\n Enter model number for which details are to be updated ";
gets(mod);
f1.read( ( char*)&e, sizeof(e) ) ;
while(f1.read( ( char*)&e, sizeof(e) ) )
{
if( strcmpi(e.ret_model() , mod )==0 )
{
cout<<"\n The following are the original details of the product
with model number "<<mod;
e.output();
cout<<"\n Enter new details for this product ";
e.input();
cout<<"\n Details successfully changed ! ";

}
}

f1.close();
}

void delete_frames ()
{
ofstream f2 ("deleted_files.bat", ios::binary ) ;
ifstream f1 ("frames.txt",ios::binary) ;
eyewear e;
char ch,x;
char mod[10];
cout<<"\n Enter model number to be deleted ";
gets(mod);
f1.read( ( char* )&e, sizeof(e) ) ;
while(f1.read( ( char* )&e, sizeof(e) ))
{
if( strcmpi(e.ret_model() , mod)==0 )
{
cout<<"\n The following are the original details of the product
with model number "<<mod;
e.output();
do
{
cout<<"\n Are you sure you want to delete this product ? ";
cout<<"\n Press y for yes and n for no ";
cin>>ch;
if ( ch=='y' || ch=='Y' )
f2.write( (char*)&e, sizeof(e) ) ;
else if ( ch=='n' || ch=='N' )
exit(0);
else
{
cout<<"\n Invalid choice " ;
cout<<"\n Try Again ? ";
cout<<"Press y for yes and n for no ";
cin>>x;
}
}while( x=='y' || x=='Y' );
}
f1.close();
f2.close();
}

void update()
{
int x;
char ch;
do
{
cout<<"\n Select what you want to update ";
cout<<"\n 1. Add frames ";
cout<<"\n 2. Update Price ";
cout<<"\n 3. Update quantity ";
cout<<"\n 4. Update all details ";
cout<<"\n 5. Delete frames ";
cin>>x;
switch(x)
{
case (1) : add_frames() ;
break;
case (2) : update_price();
break;
case (3) : update_qty();
break;
case (4) : update_details();
break;
case (5) : delete_frames();
break;

default: cout<<"\n Invalid Choice ";


}
cout<<"\n Try Again ? ";
cout<<"\n Press y for yes and n for no ";
cin>>ch;
}while (ch=='y' || ch=='Y' );
}

void search ()
{
int x ;
char ch ;
do
{
cout<<"\n Select choice. Search on the basis of : ";
cout<<"\n 1. Brand ";
cout<<"\n 2. Model number ";
cout<<"\n 3. Date of Purchase ";
cout<<"\n 4. Date of selling ";
cout<<"\n 5. Price range ";
cout<<"\n 6. Frame Colour ";
cout<<"\n 7. Glass Colour ";
cout<<"\n 8. Description ";
cout<<"\n 9. Shape ";
cin>>x;
switch(x)
{
case (1) : search_brand();
break;
case (2) : search_model();
break;
case (3) : search_dop();
break;
case (4) : search_dos();
break;
case (5) : search_price();
break;
case (6) : search_fcolour();
break;
case (7) : search_gcolour();
break;
case (8) : search_desc();
break;
case (9) : search_shape();
break;

default : cout<<"\n Invalid Choice " ;


}

cout<<"\n Continue ? ";


cout<<"\n Press y for yes and n for no ";
cin>>ch;
}while( ch=='y' || ch=='Y' ) ;

void search_brand()
{
char brand[20];
cout<<"\n Enter brand you are looking for "
gets(brand);
ofstream f1 ( "frames.bat", ios::binary )
eyewear e;
flag ;
f1.read ( (char*)&e, sizeof(e) ) ;
while(f1.read ( (char*)&e, sizeof(e) )
{
if(strcmpi( e.ret_brand() , brand == 0 )
{
flag=1;
cout<<"\n The following are the details of the product of brand
"<<brand;
e.ouput;
break;
}
else
{
flag=0;
}
}
if( flag==0 )
cout<<"\n No Brand found ";
f1.close();
}

void search_model()
{
char mod[10];
int flag ;
cout<<"\n Enter model you are looking for "
gets(mod);
ofstream f1 ( "frames.bat", ios::binary ) ;
eyewear e;
f1.read ( (char*)&e, sizeof(e) ) ;
while(f1.read ( (char*)&e, sizeof(e) )
{
if(strcmpi( e.ret_model() , mod == 0 )
{
e.ouput;
flag=1;
break;
}
else
flag=0;
}
if(flag=0)
cout<<"\n No Model found ";
f1.close();
}

void search_dop
{
date d;
int flag;
cout<<"\n Enter date of purchase of the frame you are looking for "
cout<<"\n Date " ; cin>>d.dd;
cout<<"\n Month "; cin>>d.mm;
cout<<"\n Year "; cin>>d.yy;
ofstream f1 ( "frames.bat", ios::binary ) ;
eyewear e;
f1.read ( (char*)&e, sizeof(e)
while(f1.read ( (char*)&e, sizeof(e) )
{
if( d.dd == e.ret_date() && d.mm == e.ret_month() && d.yy == e.ret_year() )
{
flag=1;
cout<<"\n Details of frame purchased on "<<d.dd<<":"<<d.mm<<":"<<d.yy;
e.ouput;
break;
}
else
flag=0;
}
if(flag==0)
cout<<"\n No frames were purchased on "<<d.dd<<":"<<d.mm<<":"<<d.yy;

void search_dos
{
date d;
int flag;
cout<<"\n Enter date of selling of the frame you are looking for "
cout<<"\n Date " ; cin>>d.dd;
cout<<"\n Month "; cin>>d.mm;
cout<<"\n Year "; cin>>d.yy;
ofstream f1 ( "frames.bat", ios::binary ) ;
billing b;
f1.read ( (char*)&b, sizeof(b) ;
while(f1.read ( (char*)&b, sizeof(b) )
{
if( d.dd == b.ret_date() && d.mm == b.ret_month() && d.yy == b.ret_year() )
{
flag=1;
cout<<"\n Details of frame sold on "<<d.dd<<":"<<d.mm<<":"<<d.yy;
e.ouput;
break;
}
else
flag=0;
}
if(flag==0)
cout<<"\n No frames were sold on "<<d.dd<<":"<<d.mm<<":"<<d.yy;

void search_price()
{
int min,max,flag;
cout<<"\n Enter Price Range "
cout<<"\n Minimum " ; cin>>min;
cout<<"\n Maximum " ; cin>>max;
ofstream f1 ( "frames.bat", ios::binary );
eyewear e;
f1.read ( (char*)&e, sizeof(e) ;
while(f1.read ( (char*)&e, sizeof(e) )
{
if( e.ret_price()>= min && e.ret_price()<=max )
{
cout<<"\n The following are the details of sunglasses within your
budget " ;
e.output();
flag=1;
break;
}
else
flag=0;
}
if(flag==0)
cout<<"\n No frame found within the given price range ";

void search_fcolour()
{
char fcolour[20];
int flag;
cout<<"\n Enter frame colour you are looking for "
gets(fcolour);
ofstream f1 ( "frames.bat", ios::binary ) ;
eyewear e;
f1.read ( (char*)&e, sizeof(e)
while(f1.read ( (char*)&e, sizeof(e) )
{
if(strcmpi( e.ret_fcolour() , fcolour == 0 )
{
cout<<"\n Details of the frame with colour "<<fcolour ;
e.output;
}
else
flag=0;
}
if(flag=0)
cout<<"\n Sorry we do not have any "<<fcolour<<" frame ";
}

void search_gcolour()
{
int flag;
cout<<"\n Enter glass colour you are looking for "
gets(gcolour);
ofstream f1 ( "frames.bat", ios::binary ) ;
eyewear e;
f1.read ( (char*)&e, sizeof(e)
while(f1.read ( (char*)&e, sizeof(e) )
{
if(strcmpi( e.ret_gcolour() ,gcolour == 0 )
{
cout<<"\n Details of frame with glass colour "<<gcolour ;
e.ouput;
flag=1;
break;
}
else
flag=0;
}
if(flag==0)
cout<<"\n Sorry we do not have any frame with "<<gcolour<<" glasses ";
}

void search_desc()
{
int flag;
cout<<"\n Enter description of the frame "
gets(desc);
ofstream f1 ( "frames.bat", ios::binary ) ;
eyewear e;
f1.read ( (char*)&e, sizeof(e) ;
while(f1.read ( (char*)&e, sizeof(e) )
{
if(strcmpi( e.ret_desc() , desc == 0 )
{
cout<<"\n Details of "<<desc<<" type frame ";
e.ouput;
flag=1;
break;
}
else
flag=0;
}
if (flag==0)
cout<<"\n Sorry, No frame is found with your mentioned description ";

void search_shape()
{
int flag;
cout<<"\n Enter shape you are looking for "
gets(shape);
ofstream f1 ( "frames.bat", ios::binary ) ;
eyewear e;
f1.read ( (char*)&e, sizeof(e);
while(f1.read ( (char*)&e, sizeof(e) )
{
if(strcmpi( e.ret_shape() , shape == 0 )
{
cout<<"\n Details of frame of "<<shape<<" shape";
e.ouput;
flag=1;
break;
}
else
flag=0;
}

if(flag==0)
cout<<"\n Sorry, no frame is found ";

void bill()
{
int x;
do
{
cout<<"\n Enter choice ";
cout<<"\n 1. New Customer ";
cout<<"\n 2. Existing Customer ";
cin>>x;
switch(x)
{
case (1): void new_cust() ;
break;
case (2) : void existing_cust() ;
break;

default : cout<<"\n Invalid Choice ";


}

cout<<"\n Try Again ? " ;


cout<<"\n Press y for yes and n for no " ;
cin>>ch ;
while( ch=='y' || ch=='Y' ) ;
}
void new_cust()
{
ofstream f3 ("customer.bat" , ios::binary ) ;
customer c ;
do
{
cout<<"\n Enter Customer Details " ;
c.input() ;
f1.write( (char*)&c, sizeof(c) )
cout<<"\n Continue ? ";
cout<<"\n Press y for yes and n for no ";
cin>>ch;
}while(ch=='y'||ch=='Y');
}

void existing_cust()
{
int x;
char name[20];
char phone[10] , ch ;
do
{
cout<<"\n Select method to search customer ";
cout<<"\n 1. Name ";
cout<<"\n 2. Phone Number ";
cin>>x;
if(x==1)
{
cout<<"\n Enter Name ";
gets(name);
ofstream f1("customer.bat", ios::binary ) ;
customer c;
f1.read( (char*)&c, sizeof(c) );
while(f1.read( (char*)&c, sizeof(c) ) )
{
if(strcmpi( c.ret_name() , name == 0 ) )
{
cout<<"\n We will give you a discount of 5% as you are an
existing customer ";
c.disc = (5*c.gtotal)/100 ;
cout<<c.disc;
c.print_bill();
}
else
{
cout<<"\n No record found ! "; // baar baar no record
found aayega

}
}
f1.close();
}
else if(x==2)
{
cout<<"\n Enter phone number ";
gets(phone);
ofstream f3("customer.bat", ios::binary ) ;
customer c;
f1.read( (char*)&c, sizeof(c) ) ;
while( f1.read( (char*)&c, sizeof(c) ) )
{
if(strcmpi( c.ret_phone() , phone == 0 ) )
{
cout<<"\n We will give you a discount of 5% as you are an
existing customer ";
c.disc= (5*c.gtotal)/100 ;
cout<<c.disc;
c.print_bill();
}
else
{
cout<<"\n No record found ! ";
}
}
f1.close();
}

cout<<"\n Invalid Choice ";


cout<<"\n Try Again ? ";
cout<<"\n Press y for yes and n for no ";
cin>>ch
while(ch=='y' || ch=='Y' );
}

void billing::print_bill()
{
cout<<"\n The following are the customer details "; //customer details ke
liye class ko inherit karaya
c.output() ;
do
{
cout<<"\n Confirm Purchase ? ";
cout<<"\n Press y for yes and n for no ";
cin>>ch
if(ch=='y' || ch== 'Y')
{
cout<<"\n THANK YOU FOR YOUR PURCHASE . HAVE A NICE DAY . PLEASE VISIT
AGAIN " ;
c.output();
main(); // MAIN MENU PE JAAYEGA, VOID MAIN ME?
}
else if(ch=='n' || ch== 'N' )
{
cout<<"\n Exiting to the main menu......";
main();
}
cout<<"\n Invalid Choice ";
cout<<"\n Try Again ? ";
cout<<"\n Press y for yes and n for no ";
cin>>ch;
}while(ch=='y' || ch=='Y') ;
}

void main()
{
cout<<"\n Welcome to VISION CARE - Your sight is our primary concern ";
do
{
int x;
char ch;
cout<<"\n Please select your choice ";
cout<<"\n 1. UPDATE ";
cout<<"\n 2. SEARCH ";
cout<<"\n 3. PRINT BILL ";
cin>>x;
switch(x)
{
case 1 : update() ;
break;
case 2 : search() ;
break;
case 3 : billing() ;
break;

default : cout<<"\n Invalid choice ";

}
cout<<"\n Try Again ? ";
cout<<"\n Press y for yes and n for no ";
cin>>ch;
}while( ch == 'y' || ch == 'Y' ) ;
}

You might also like