Programmer

Friday, 1 June 2018

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

class data
{
int id;
char fname[20],lname[20],pno[14];

public:
void add();
void display();
int getId(){ return id;}
char* getfname()
{
return fname;
}
}d;

void storedata();
void readdata();
void searchdata();
void deldata();

void main()
{
char n;
clrscr();
do
{
cout<<endl<<endl<<endl<<"\t\t\t         Main Menu";
cout<<endl<<"\t\t\t============================";
cout<<endl<<"\t\t\t 0. EXIT";
cout<<endl<<"\t\t\t 1. Add Data";
cout<<endl<<"\t\t\t 2. Display Data";
cout<<endl<<"\t\t\t 3. Search Data";
cout<<endl<<"\t\t\t 4. Delete Data";
cout<<endl<<"\t\t\t CHOOSE : ";
n=getche();
switch(n)
{
case '0': exit(0); break;
case '1':
clrscr();
storedata();
clrscr();
textcolor(RED+BLINK);
cprintf("!Data Added");
textcolor(7);
break;
case '2':
clrscr();
readdata();
getch();
clrscr();
break;
case '3':
clrscr();
searchdata();
break;
case '4':
clrscr();
deldata();
break;
default :
clrscr();
textcolor(RED+BLINK);
cprintf("Invalid Input");
textcolor(7);
}
}
while('n'!='0');
}
void data::add()
{
cout<<"Enter Your Id : ";
cin>>id;
cout<<"Enter Your First Name : ";
cin.get();
cin.getline(fname,20);
cout<<"Enter Your Last Name : ";
cin.getline(lname,20);
cout<<"Enter Your Phone No : ";
cin.getline(pno,14);
}
void data::display()
{
cout<<"Id : "<<id;
cout<<endl<<"Name : "<<fname<<" "<<lname;
cout<<endl<<"Phone No : "<<pno;
}
void storedata()
{
ofstream fout;
fout.open("data.dat",ios::binary|ios::app);
d.add();
fout.write((char*)&d,sizeof(d));
fout.close();
}
void readdata()
{
ifstream fin;
fin.open("data.dat");
while(fin.read((char*)&d,sizeof(d)))
{
d.display();
cout<<endl<<endl;
}
fin.close();
}
void searchdata()
{
int fid;
cout<<"Enter Id : ";
cin>>fid;
ifstream fin;
fin.open("data.dat");
while(fin.read((char*)&d,sizeof(d)))
{
if(fid==d.getId())
{
d.display();
cout<<endl<<endl;
}
}
fin.close();
}
void deldata()
{
char ffname[20];
ofstream fout;
cout<<"Enter First Name : ";
cin.getline(ffname,20);
ifstream fin;
fin.open("data.dat");
fout.open("data1.dat");
while(fin.read((char*)&d,sizeof(d)))
{
if(stricmp(ffname,d.getfname())!=0)
{
fout.write((char *)&d,sizeof(d));
}
}
fout.close();
fin.close();
remove("data.dat");
rename("data1.dat","data.dat");
fin.close();
}


Tuesday, 29 May 2018





//Product Management Project
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<string.h>
int size=4;
struct product
{
int id;
char name[20];
int price;
int qun;
long amt;
}s[15]={
{1,"Pen",10,1000,10000},
{2,"Pencil",5,500,2500},
{3,"Eraser",3,670,2010},
{4,"Notebook",30,500,1500}
       };

void entry()
{
clrscr();
printf("Enter Product ID :");
scanf("%d",&s[size].id);
printf("Enter Product Name :");
fflush(stdin);
gets(s[size].name);
printf("Enter Product Price :");
scanf("%d",&s[size].price);
printf("Enter Prodcut Quantity :");
scanf("%d",&s[size].qun);
s[size].amt=s[size].qun*s[size].price;
}

void header()
{
int i;
printf("\tP_ID \t P_Name \t P_Price \t P_Quantity \t P_Amount\n");
for(i=1;i<=80;i++)
printf("*");
}
void display()
{
int i;
clrscr();
header();
for(i=0;i<size;i++)
{
printf("\t%3d\t %7s\t %7d\t %7d %14ld\n",s[i].id,s[i].name,s[i].price,s[i].qun,s[i].amt);
}
}

void search()
{
int id,i,found=0,p;
clrscr();
printf("Enter Product ID to Search :");
scanf("%d",&id);
for(i=0;i<size;i++)
{
if(id==s[i].id)
{
p=i;
found++;
}
}
if(found>0)
{
printf("Product ID : %d\n",s[p].id);
printf("Product Name : %s\n",s[p].name);
printf("Prodcut Price : %d\n",s[p].price);
printf("Product Quantity: %d\n",s[p].qun);
}
else
{
textcolor(RED+BLINK);
printf("Product Not Found..");
textcolor(7);
}
}

void del()
{
char pname[20];
int i,p,found=0;
clrscr();
printf("Enter Product Name to Delete Product :");
fflush(stdin);
gets(pname);
for(i=0;i<size;i++)
{
if(stricmp(pname,s[i].name)==0)
{
p=i;
found++;
}
}
if(found>0)
{
printf("Product ID : %d\n",s[p].id);
printf("Product Name : %s\n",s[p].name);
printf("Prodcut Price : %d\n",s[p].price);
printf("Product Quantity: %d\n\n\n",s[p].qun);

textcolor(GREEN+BLINK);
cprintf("Product Deleted Successfully..!");
textcolor(7);

for(i=0;i<p;i++)
{
s[p]=s[p+1];
}
size--;
}
else
{
textcolor(RED+BLINK);
cprintf("Product Not Found");
textcolor(7);
}
}

void main()
{
int ch;
do
{
clrscr();
printf("\n\n\n\n");
printf("\t\t\t************************\n");
printf("\t\t\t*   MENU        *\n");
printf("\t\t\t************************\n");
printf("\t\t\t* 0. Exit        *\n");
printf("\t\t\t* 1. Add Product       *\n");
printf("\t\t\t* 2. Display Product   *\n");
printf("\t\t\t* 3. Search Product    *\n");
printf("\t\t\t* 4. Delete Produtct   *\n");
printf("\t\t\t************************\n");
printf("\t\t\tEnter Your Choice :");
scanf("%d",&ch);

switch(ch)
{
case 0: exit(0);
break;

case 1: entry();
size++;
break;

case 2: display();
break;

case 3: search();
break;

case 4: del();
break;

default:
textcolor(RED+BLINK);
cprintf("Wrong Input");
textcolor(7);
}
getch();
}while(ch);
}


Program To Print Particular Line From File.

#include<fstream.h> #include<conio.h> #include<stdlib.h> void main() { ifstream fin; int count=0,num,l=1; char ...