Computer Science Class 12 Project
Computer Science Class 12 Project
COMPUTER SCIENCE
Name of the student :……………………………………………………
Class :…………………………………………………….
Division :…………………………………………………….
1
CONTENTS
SNO. TOPIC PAGE NO.
1. Certificate 2
2. Acknowledgement 4
3. Aim and Objective 5
4. Introduction to C++ 6
5. Requirement 8
6. Introduction to program 9
7. Header files used and 10
their purpose
8. Program coding 11
9. Output 17
10. Conclusion 21
11. Bibliography 22
2
ACKNOWLEDGEMENT
I'd like to express my greatest gratitude to the people who have
helped and supported me throughout my project.
I'm grateful to Mrs. Deepa Madhavan for her continuous support
for the project ,from initial advice and encouragement to this day.
3
AIM AND OBJECTIVE
This project uses the concept of data file handling ,object oriented
programming and other techniques. This project aims to enable
users keep a secure record of the details of Food.
Here you can keep record of details of Food. This project helps to
store data in a very easily accessible way instead of storing data
in huge bulks of files.
4
INTRODUCTION TO C+
+
C++ was developed by Bjarne Stroustrup of AT and T Bell
laboratories in the early 1980's , and is a pun-"++" is a syntactic
construct used in C(to increment a variable), and C++ is intended
as an increment improvement of C.Most of C is a subset of C++ ,
so that most C programs can be compiled(i.e. converted into a
series of low level instructions that the computer can execute
directly) using a C++ compiler.
6
REQUIREMENT
Hardware Required:
Printer ,to print the required documents of the project
Compact Drive
Processor :Pentium 111
Ram :64 MB
Harddisk :20 Gb.
Software Required:
Operating system :Windows XP
Turbo C++ ,for execution of program and
MS word , for presentation of output.
7
INTRODUCTION TO PROGRAM
8
HEADER FILES AND THEIR
PURPOSE
9
PROGRAM CODING
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class fmenu
{int fid;
char name[20] ;
float price;
char cuisine[20];
public:
void read();
void display();
void modify();
int getfid()
{return fid;
}
};
void fmenu::read()
{cout<<"Enter Food ID No.\n";
cin>>fid;
cout<<"Enter Food Name\n";
gets(name);
cout<<"Enter Price\n";
cin>>price;
cout<<"Enter Cuisine\n";
gets(cuisine);
10
}
void fmenu::display()
{cout<<"\nFood ID No.- "<<fid;
cout<<"\nFood Name-";puts(name);
cout<<"Price:-"<<price;
cout<<"\nCuisine:- "<<cuisine<<'\n';
}
void fmenu::modify()
{char name1[20], cuisine1[20];int fid1;float
price1;
cout<<"Enter New Food ID No.\n";
cin>>fid1;
cout<<"Enter New name\n";
gets(name1);
cout<<"Enter New Price\n";
cin>>price1;
cout<<"Enter New Cuisine\n";
cin>>cuisine1;
strcpy(name,name1);
fid=fid1;
strcpy(cuisine,cuisine1);
price=price1;
}
fmenu s,s1;
void add()
{char ch;
ofstream fout("fmnu",ios::binary);
do{s.read();
fout.write((char*)&s,sizeof(s));
cout<<"Do you want to continue?\n";
11
cin>>ch;
}
while(ch=='y'||ch=='Y');
}
void show()
{ifstream fin("fmnu",ios::binary);
while(fin.read((char*)&s,sizeof(s)))
{
s.display();
}
}
void insert()
{int flag=0;
ifstream fin("fmnu",ios::binary);
ofstream fout("ftemp",ios::binary);
cout<<"Enter the details to be inserted\n";
s1.read();
while(fin.read((char*)&s,sizeof(s)))
{if(s.getfid()>=s1.getfid())
{fout.write((char*)&s1,sizeof(s1));
fout.write((char*)&s,sizeof(s));
flag=1;
break;
}
else
fout.write((char*)&s,sizeof(s));
}
if( flag==0)
fout.write((char*)&s,sizeof(s));
while(fin.read((char*)&s,sizeof(s)))
12
{fout.write((char*)&s,sizeof(s));
}
remove("fmnu");
rename("ftemp","fmnu");
}
void delet()
{int flag=0,r;
ifstream fin("fmnu",ios::binary);
ofstream fout("ftemp",ios::binary);
cout<<"Enter the Food ID no to be deleted\n";
cin>>r;
while(fin.read((char*)&s,sizeof(s)))
{if(s.getfid()==r)
{flag=1;
cout<<"\nRecord deleted successfully\n";
}
else
fout.write((char*)&s,sizeof(s));
}
if(flag==0)
cout<<"Record not found";
remove("fmnu");
rename("ftemp","fmnu");
}
void modify()
{int r;
fstream fin("fmnu",ios::in|ios::out|
ios::binary);
cout<<"Enter the Food ID No to be modified";
cin>>r;
13
while(fin.read((char*)&s,sizeof(s)))
{if(s.getfid()==r)
{s1.modify();
int pos=fin.tellg()-sizeof(s);
fin.seekp(pos);
fin.write((char*)&s1,sizeof(s));
}
}
}
void search()
{int r,flag=0;
fstream fin("fmnu",ios::in|
ios::out,ios::binary);
cout<<"Enter the Food ID no to be searched";
cin>>r;
while(fin.read((char*)&s,sizeof(s)))
{if(s.getfid()==r)
{s.display();
flag=1;
break;
}}
if(flag==0)
cout<<"Record not found";
}
void main()
{clrscr();
cout<<"\t\t\tFOOD DATABASE \n";
int ch;char ch1;
do
{cout<<"\n1.Add details";
14
cout<<"\n2.Display all details";
cout<<"\n3.Insert any new details";
cout<<"\n4.Delete any detail";
cout<<"\n5.Modify any detail";
cout<<"\n6.Search for a record";
cout<<"\nEnter your choice\n";
cin>>ch;
switch(ch)
{case 1:add();
break;
case 2: show();
break;
case 3:insert();
break;
case 4:delet();
break;
case 5: modify();
break;
case 6:search();
break;
default:cout<<"Invalid choice";
}cout<<"\nDo you want to continue to add or
show?\n";
cin>>ch1;
}
while(ch1=='y'||ch1=='Y');
getch();
}
15
16
17
18
19
CONCLUSION
This program helps you to record the details of each Food
separately.
C++ makes our work easier so that we can make utilize of the
record of Food whenever required.
20
BIBLIOGRAPHY
www.google.com
www.cbse.nic.in
21