| 1. | What is VSS (Visual Source Safe) ? |
| | You can use VSS to secure code access among the developer and make control over the access right, also can check for multiple version of code. |
| 2. | Assume you have an array that contains a number of strings (perhaps char * a[100]). Each string is a word from the dictionary. Your task, described in high-level terms, is to devise a way to determine and display all of the anagrams within the array (two words are anagrams if they contain the same characters; for example, tales and slate are anagrams.) |
| | Begin by sorting each element in the array in alphabetical order. So, if one element of your array was slate, it would be rearranged to form aelst (use some mechanism to know that the particular instance of aelst maps to slate). At this point, you slate and tales would be identical: aelst. Next, sort the entire array of these modified dictionary words. Now, all of the anagrams are grouped together. Finally, step through the array and display duplicate terms, mapping the sorted letters (aelst) back to the word (slate or tales). |
| 3. | What is the difference between a NULL pointer and a void pointer? |
| | A NULL pointer is a pointer of any type whose value is zero. A void pointer is a pointer to an object of an unknown type, and is guaranteed to have enough bits to hold a pointer to any object. A void pointer is not guaranteed to have enough bits to point to a function (though in general practice it does) |
| 4. | What is encapsulation technique? |
| | Hiding data within the class and making it available only through the methods. This technique is used to protect your class against accidental changes to fields, which might leave the class in an inconsistent state. |
| 5. | Definition of Object Oriented Programming in single line? |
| | Object oriented programming is a programming paradigm which uses objects and its interactions to design applications and computer programs. |
| 6. | What is virtual function? |
| | The virtual keyword means that method, property or function can be overridden |
| 7. | What’s a Windows process? |
| | It’s an application that’s running and had been allocated memory. |
| 8. | What is programming? |
| | Computer programming is writing or editing a computer program. A computer program is a set of instructions which determine how the computer will react to input when that program is running. |
| 9. | What is a debugger? |
| | debugger is a program in which you run another program that you are trying to debug. Inside a debugger, you can step through your program one line or instruction at a time, set break points and have your program run until it hits one, examine the contents of variables and memory, and such other useful things as that. |
| 10. | what is a Programming language? |
| | A programming language is a stylized communication technique intended to be used for controlling the behavior of a machine (often a computer). Like human languages programming languages have syntactic and semantic rules used to define meaning. |
| 11. | What's the difference between a programming language, a scripting language? |
| | The main difference between a "programming language" (C, C++ etc.) and a "scripting language" (ASP, JSP, JavaScript, VBScript) is that code written in a programming language needs to be compiled before it is run. Once it is compiled, it can be run any number of times. Scripting languages, on the other hand, are interpreted at run-time. This means that every time you want to run the program, a separate program needs to read the code, interpret it, and then follow the instructions in the code. Compiled code has already been interpreted into machine language, so it is will typically execute faster because the conversion into machine language has already been done. |
Showing posts with label c projects. Show all posts
Showing posts with label c projects. Show all posts
Thursday, September 8, 2011
Interview Questions for Programming General
Labels:
c projects,
c++,
dot net,
general programming,
gui java,
Interview Questions,
language,
programming
Thursday, July 21, 2011
Library Management System (Sample)
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
#include<string.h>
#include<dos.h>
void book_menu();
void member_menu();
void issue_menu();
class book
{
public:
int bkno;
char bkna[30];
char auth[30];
char edi[20];
char pags[10];
char pblis[40];
void add();
void search();
void del();
void modify();
void show();
void exit();
};
void book::add()
{
cout<<"\n Enter book no. : ";
cin>>bkno;
cout<<"\n Enter book name : ";
gets(bkna);
cout<<"\n Enter author name : ";
gets(auth);
cout<<"\n Enter book edition : ";
gets(edi);
cout<<"\n Enter pages : ";
gets(pags);
cout<<"\n Enter book Publisher : ";
gets(pblis);
}
void book::search()
{
book b;
int d;
int f=0;
ifstream ob1;
ob1.open("book.txt",ios::in);
cout<<"\n Enter book no. to search : ";
cin>>d;
ob1.read((char*)&b,sizeof(b));
while(ob1)
{
if(b.bkno==d)
{
b.show();
cout<<"\n Book found.";
f=1;
break;
}
else
{
f=0;
}
ob1.read((char*)&b,sizeof(b));
}
if(f==0)
{
cout<<"\n Book not found.";
}
ob1.close();
getch();
}
void book::del()
{
book b;
int d;
ifstream ob2;
ofstream ob3;
ob2.open("book.txt",ios::in);
ob3.open("temp.txt",ios::app);
cout<<"\n Enter book no. to delete : ";
cin>>d;
ob2.read((char*)&b,sizeof(b));
while(ob2)
{
if(b.bkno==d)
{
b.show();
cout<<"\n Record deleted.";
}
else
{
ob3.write((char*)&b,sizeof(b));
}
ob2.read((char*)&b,sizeof(b));
}
remove("book.txt");
rename("temp.txt","book.txt");
ob2.close();
ob3.close();
getch();
}
void book::modify()
{
book b;
int d;
ifstream ob4;
ofstream ob5;
ob4.open("book.txt",ios::in);
ob5.open("temp.txt",ios::app);
cout<<"\n Enter book no. to modify record : ";
cin>>d;
ob4.read((char*)&b,sizeof(b));
while(ob4)
{
if(b.bkno==d)
{
b.show();
cout<<"\n Enter new values for record";
b.add();
ob5.write((char*)&b,sizeof(b));
}
else
{
ob5.write((char*)&b,sizeof(b));
}
ob4.read((char*)&b,sizeof(b));
}
remove("book.txt");
rename("temp.txt","book.txt");
ob4.close();
ob5.close();
getch();
}
void book::show()
{
cout<<"\n Book no. : "<<bkno;
cout<<"\n Book name : "<<bkna;
cout<<"\n Author's name : "<<auth;
cout<<"\n Book Edition : "<<edi;
cout<<"\n Book Pages : "<<pags;
cout<<"\n Book publisher : "<<pblis;
}
void book::exit()
{
getch();
}
class member
{
char nm[50];
char pno[40];
char val[30];
int idno;
char ad[100];
char mems[30];
public:
void add();
void search();
void del();
void modify();
void show();
void exit();
};
void member::add()
{
cout<<"\n Enter member name : ";
gets(nm);
cout<<"\n Enter id no. : ";
cin>>idno;
cout<<"\n Enter member address : ";
gets(ad);
cout<<"\n Enter phone no. : ";
gets(pno);
cout<<"\n Membership started on : ";
gets(mems);
cout<<"\n Membership valid upto : ";
gets(val);
}
void member::search()
{
member mem;
int d;
ifstream ob6;
int f=0;
ob6.open("meb.txt",ios::in);
cout<<"\n Enter id no. to search member : ";
cin>>d;
ob6.read((char*)&mem,sizeof(mem));
while(ob6)
{
if(mem.idno==d)
{
mem.show();
cout<<"\n Record found.";
f=1;
break;
}
else
{
f=0;
}
ob6.read((char*)&mem,sizeof(mem));
}
if(f==0)
{
cout<<"\n Record not found.";
}
ob6.close();
getch();
}
void member::del()
{
member mem;
int d;
ifstream ob7;
ofstream ob8;
ob7.open("meb.txt",ios::in);
ob8.open("temp.txt",ios::app);
cout<<"\n Enter id no. to delete a member : ";
cin>>d;
ob7.read((char*)&mem,sizeof(mem));
while(ob7)
{
if(mem.idno==d)
{
mem.show();
cout<<"\n Record deleted.";
}
else
{
ob8.write((char*)&mem,sizeof(mem));
}
ob7.read((char*)&mem,sizeof(mem));
}
remove("meb.txt");
rename("temp.txt","meb.txt");
ob7.close();
ob8.close();
getch();
}
void member::modify()
{
member mem;
int d;
ifstream ob9;
ofstream ob10;
ob9.open("meb.txt",ios::in);
ob10.open("temp.txt",ios::app);
cout<<"\n Enter id no. to modify record : ";
cin>>d;
ob9.read((char*)&mem,sizeof(mem));
while(ob9)
{
if(mem.idno==d)
{
mem.show();
cout<<"\n Enter new values for record";
mem.add();
ob10.write((char*)&mem,sizeof(mem));
}
else
{
ob10.write((char*)&mem,sizeof(mem));
}
ob9.read((char*)&mem,sizeof(mem));
}
remove("meb.txt");
rename("temp.txt","meb.txt");
ob9.close();
ob10.close();
getch();
}
void member::show()
{
cout<<"\n Id no. : "<<idno;
cout<<"\n Member name : "<<nm;
cout<<"\n Address of member : "<<ad;
cout<<"\n Phone no : "<<pno;
cout<<"\n Membership started on : "<<mems;
cout<<"\n Membership valid upto : "<<val;
}
void member::exit()
{
getch();
}
class issue
{
public:
char baa[50];
char buka[50];
char editi[59];
char doi[50];
char bi[50];
char mno[50];
char tik[40];
int bn;
issue()
{
strcpy(baa,"");
bn=0;
}
void add();
void search();
void del();
void modify();
void show();
void exit();
};
void issue::add()
{
cout<<("\n Enter book name : ");
gets(baa);
cout<<("\n Enter book author : ");
gets(buka);
cout<<("\n Enter edition : ");
gets(editi);
cout<<"\n Enter date of issue(Enter date without spaces) : ";
gets(doi);
cout<<"\n Book issued to : ";
gets(bi);
cout<<"\n Member id no. : ";
gets(mno);
cout<<"\n Ticket no. : ";
gets(tik);
}
void issue::search()
{
issue iss;
int d;
ifstream ob11;
int f=0;
ob11.open("isu.txt",ios::in);
cout<<"\n Enter book no. to search : ";
cin>>d;
ob11.read((char*)&iss,sizeof(iss));
while(ob11)
{
if(iss.bn==d)
{
iss.show();
cout<<"\n Book found.";
f=1;
break;
}
else
{
f=0;
}
ob11.read((char*)&iss,sizeof(iss));
}
if(f==0)
{
cout<<"\n Book is already issued.";
}
ob11.close();
getch();
}
void issue::del()
{
issue iss;
int d;
ifstream ob12;
ofstream ob13;
ob12.open("isu.txt",ios::in);
ob13.open("temp.txt",ios::app);
cout<<"\n Enter book no. to search : ";
cin>>d;
ob12.read((char*)&iss,sizeof(iss));
while(ob12)
{
if(iss.bn==d)
{
iss.show();
cout<<"\n Record deleted.";
}
else
{
ob13.write((char*)&iss,sizeof(iss));
}
ob12.read((char*)&iss,sizeof(iss));
}
remove("isu.txt");
rename("temp.txt","isu.txt");
ob12.close();
ob13.close();
getch();
}
void issue::modify()
{
issue iss;
int d;
ifstream ob14;
ofstream ob15;
ob14.open("isu.txt",ios::in);
ob15.open("temp.txt",ios::app);
cout<<"\n Enter book no. to modify record :";
cin>>d;
ob14.read((char*)&iss,sizeof(iss));
while(ob14)
{
if(iss.bn==d)
{
iss.show();
cout<<"\n Enter new values for record";
iss.add();
ob15.write((char*)&iss,sizeof(iss));
}
else
{
ob15.write((char*)&iss,sizeof(iss));
}
ob14.read((char*)&iss,sizeof(iss));
}
remove("isu.txt");
rename("temp.txt","isu.txt");
ob14.close();
ob15.close();
getch();
}
void issue::show()
{
cout<<"\n Book no : "<<bn;
cout<<"\n Book name : "<<baa;
cout<<"\n Book author : "<<buka;
cout<<"\n Book edition : "<<editi;
cout<<"\n Date of issue : "<<doi;
cout<<"\n Book issued to : "<<mno;
cout<<"\n Member id no. : "<<bi;
cout<<"\n Ticket no. : "<<tik;
}
void issue::exit()
{
getch();
}
class retrn
{
int bnn;
char ba[30];
char dor[20];
public:
void add();
void search();
void del();
void modify();
void show();
void exit();
};
void retrn::add()
{
issue iss;
retrn ret;
char ch='y';
ifstream ob16;
int d;
while(ch=='y'||ch=='Y')
{
ob16.open("file.txt",ios::in);
cout<<"\n Enter book no.";
cin>>bnn;
ob16.read((char*)&ret,sizeof(ret));
while(ob16)
{
if(iss.bn==bnn)
{
cout<<"\n Enter the date of return(Enter date without spaces) : ";
cin>>dor;
}
else
{
exit();
}
}
cout<<"\n Enter 'y' to continue : ";
cin>>ch;
}
}
void retrn::search()
{
retrn ret;
int d;
ifstream ob17;
int f=0;
ob17.open("file.txt",ios::in);
cout<<"Enter book no. to search : ";
cin>>d;
ob17.read((char*)&ret,sizeof(ret));
while(ob17)
{
if(ret.bnn==d)
{
ret.show();
cout<<"\n Book returned.";
f=1;
break;
}
else
{
f=0;
}
}
if(f==0)
{
cout<<"\n Book not returned.";
}
ob17.close();
}
void retrn::del()
{
retrn ret;
int d;
ifstream ob18;
ofstream ob19;
ob18.open("file.txt",ios::in);
ob19.open("temp.txt",ios::app);
cout<<"\n Enter book no. to search : ";
cin>>d;
ob18.read((char*)&ret,sizeof(ret));
while(ob18)
{
if(ret.bnn==d)
{
ret.show();
cout<<"\n Record deleted.";
}
else
{
ob19.write((char*)&ret,sizeof(ret));
}
ob18.read((char*)&ret,sizeof(ret));
}
remove("file.txt");
rename("temp.txt","file.txt");
ob18.close();
ob19.close();
}
void retrn::modify()
{
retrn ret;
int d;
ifstream ob20;
ofstream ob21;
ob20.open("file.txt",ios::in);
ob21.open("temp.txt",ios::app);
cout<<"Enter book no. to modify a record.";
cin>>d;
ob20.read((char*)&ret,sizeof(ret));
while(ob20)
{
if(ret.bnn==d)
{
ret.show();
cout<<"\n Enter new values for this record.";
ret.add();
ob21.write((char*)&ret,sizeof(ret));
}
else
{
ob21.write((char*)&ret,sizeof(ret));
}
ob20.read((char*)&ret,sizeof(ret));
}
remove("file.txt");
rename("temp.txt","file.txt");
ob20.close();
ob21.close();
getch();
}
void retrn::show()
{
cout<<"\n Book no. : "<<bnn;
cout<<"\n Book name : "<<ba;
cout<<"\n Date of issue : "<<dor;
}
void retrn::exit()
{
getch();
}
void book_menu()
{
char c='y';
ifstream ob1;
ofstream ob;
book b;
int ch;
clrscr();
cout<<"\n 1. Add new record";
cout<<"\n 2. Search record";
cout<<"\n 3. Delete record";
cout<<"\n 4. Modify record";
cout<<"\n 5. Show record";
cout<<"\n 6. Back to menu";
cout<<"\n Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
clrscr();
ob.open("book.txt",ios::app);
while(c=='y'||c=='Y')
{
b.add();
ob.write((char*)&b,sizeof(b));
cout<<"\n Press y to Continue : ";
cin>>c;
}
ob.close();
break;
case 2:
clrscr();
b.search();
break;
case 3:
clrscr();
b.del();
break;
case 4:
clrscr();
b.modify();
break;
case 5:
clrscr();
ob1.open("book.txt",ios::in);
ob1.read((char*)&b,sizeof(b));
while(ob1)
{
b.show();
ob1.read((char*)&b,sizeof(b));
}
ob1.close();
getch();
break;
case 6:
clrscr();
b.exit();
break;
}
}
void member_menu()
{
ofstream ob;
ifstream ob1;
int ch;
int days;
member mem;
char c='y';
clrscr();
cout<<"\n 1. Add new record";
cout<<"\n 2. Search record";
cout<<"\n 3. Delete record";
cout<<"\n 4. Modify record";
cout<<"\n 5. Show record";
cout<<"\n 6. Back to menu";
cout<<"\n Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
clrscr();
ob.open("meb.txt",ios::app);
while(c=='y'||c=='Y')
{
mem.add();
ob.write((char*)&mem,sizeof(mem));
cout<<"\n Press y to continue : ";
cin>>c;
}
ob.close();
break;
case 2:
clrscr();
mem.search();
break;
case 3:
clrscr();
mem.del();
break;
case 4:
clrscr();
mem.modify();
break;
case 5:
clrscr();
ob1.open("meb.txt",ios::in);
ob1.read((char*)&mem,sizeof(mem));
while(ob1)
{
mem.show();
ob1.read((char*)&mem,sizeof(mem));
}
ob1.close();
getch();
break;
case 6:
clrscr();
mem.exit();
break;
}
}
void issue_menu()
{
ofstream ob;
ifstream ob1;
int ch;
issue iss;
textcolor(RED);
cprintf("Warning : Book must be returned within a week or there is a fine of Rs.
2 / day.");
cout<<"\n 1. Add new record";
cout<<"\n 2. Search record";
cout<<"\n 3. Delete record";
cout<<"\n 4. Modify record";
cout<<"\n 5. Show record";
cout<<"\n 6. Back to menu";
cout<<"\n Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
clrscr();
book b;
int bn1;
int f=0;
ifstream ob11;
ofstream ob12;
ob12.open("isu.txt",ios::app);
ob11.open("book.txt",ios::in);
cout<<"\n Enter book no. you want to Issue : ";
cin>>bn1;
ob11.read((char*)&b,sizeof(b));
while(ob11)
{
if(b.bkno==bn1)
{
iss.bn=bn1;
iss.add();
f=1;
break;
}
else
{
f=0;
}
ob11.read((char*)&b,sizeof(b));
}
if(f==0)
cout<<"\n Book not available.";
else
ob12.write((char*)&iss,sizeof(iss));
ob11.close();
ob12.close();
getch();
getch();
break;
case 2:
iss.search();
break;
case 3:
iss.del();
break;
case 4:
iss.modify();
break;
case 5:
ob1.open("isu.txt",ios::in);
ob1.read((char*)&iss,sizeof(iss));
while(ob1)
{
iss.show();
ob1.read((char*)&iss,sizeof(iss));
cout<<"\n Press any key to continue.";
getch();
}
ob1.close();
getch();
break;
case 6:
iss.exit();
break;
}
}
void main()
{
int ch;
clrscr();
while(ch!=4)
{
clrscr();
textcolor(MAGENTA+BLINK);
cprintf("..........********** Welcome to 'Library Management
Project'**********..........");
textcolor(MAGENTA);
cprintf("................................................................................");
textcolor(YELLOW);
cprintf("\n\nSubmitted To : Prem Saini Sir Submitted by : Inderjeet Singh");
textcolor(YELLOW);
cprintf("\n................................................................................");
cout<<"\n 1. Book Menu";
cout<<"\n 2. Member Menu";
cout<<"\n 3. Issue Menu";
cout<<"\n 4. Exit";
cout<<"\n Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
clrscr();
book_menu();
break;
case 2:
clrscr();
member_menu();
break;
case 3:
clrscr();
issue_menu();
break;
case 4:
textcolor(MAGENTA);
cprintf("\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n Thanks for using it!!!");
getch();
}
}
};
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
#include<string.h>
#include<dos.h>
void book_menu();
void member_menu();
void issue_menu();
class book
{
public:
int bkno;
char bkna[30];
char auth[30];
char edi[20];
char pags[10];
char pblis[40];
void add();
void search();
void del();
void modify();
void show();
void exit();
};
void book::add()
{
cout<<"\n Enter book no. : ";
cin>>bkno;
cout<<"\n Enter book name : ";
gets(bkna);
cout<<"\n Enter author name : ";
gets(auth);
cout<<"\n Enter book edition : ";
gets(edi);
cout<<"\n Enter pages : ";
gets(pags);
cout<<"\n Enter book Publisher : ";
gets(pblis);
}
void book::search()
{
book b;
int d;
int f=0;
ifstream ob1;
ob1.open("book.txt",ios::in);
cout<<"\n Enter book no. to search : ";
cin>>d;
ob1.read((char*)&b,sizeof(b));
while(ob1)
{
if(b.bkno==d)
{
b.show();
cout<<"\n Book found.";
f=1;
break;
}
else
{
f=0;
}
ob1.read((char*)&b,sizeof(b));
}
if(f==0)
{
cout<<"\n Book not found.";
}
ob1.close();
getch();
}
void book::del()
{
book b;
int d;
ifstream ob2;
ofstream ob3;
ob2.open("book.txt",ios::in);
ob3.open("temp.txt",ios::app);
cout<<"\n Enter book no. to delete : ";
cin>>d;
ob2.read((char*)&b,sizeof(b));
while(ob2)
{
if(b.bkno==d)
{
b.show();
cout<<"\n Record deleted.";
}
else
{
ob3.write((char*)&b,sizeof(b));
}
ob2.read((char*)&b,sizeof(b));
}
remove("book.txt");
rename("temp.txt","book.txt");
ob2.close();
ob3.close();
getch();
}
void book::modify()
{
book b;
int d;
ifstream ob4;
ofstream ob5;
ob4.open("book.txt",ios::in);
ob5.open("temp.txt",ios::app);
cout<<"\n Enter book no. to modify record : ";
cin>>d;
ob4.read((char*)&b,sizeof(b));
while(ob4)
{
if(b.bkno==d)
{
b.show();
cout<<"\n Enter new values for record";
b.add();
ob5.write((char*)&b,sizeof(b));
}
else
{
ob5.write((char*)&b,sizeof(b));
}
ob4.read((char*)&b,sizeof(b));
}
remove("book.txt");
rename("temp.txt","book.txt");
ob4.close();
ob5.close();
getch();
}
void book::show()
{
cout<<"\n Book no. : "<<bkno;
cout<<"\n Book name : "<<bkna;
cout<<"\n Author's name : "<<auth;
cout<<"\n Book Edition : "<<edi;
cout<<"\n Book Pages : "<<pags;
cout<<"\n Book publisher : "<<pblis;
}
void book::exit()
{
getch();
}
class member
{
char nm[50];
char pno[40];
char val[30];
int idno;
char ad[100];
char mems[30];
public:
void add();
void search();
void del();
void modify();
void show();
void exit();
};
void member::add()
{
cout<<"\n Enter member name : ";
gets(nm);
cout<<"\n Enter id no. : ";
cin>>idno;
cout<<"\n Enter member address : ";
gets(ad);
cout<<"\n Enter phone no. : ";
gets(pno);
cout<<"\n Membership started on : ";
gets(mems);
cout<<"\n Membership valid upto : ";
gets(val);
}
void member::search()
{
member mem;
int d;
ifstream ob6;
int f=0;
ob6.open("meb.txt",ios::in);
cout<<"\n Enter id no. to search member : ";
cin>>d;
ob6.read((char*)&mem,sizeof(mem));
while(ob6)
{
if(mem.idno==d)
{
mem.show();
cout<<"\n Record found.";
f=1;
break;
}
else
{
f=0;
}
ob6.read((char*)&mem,sizeof(mem));
}
if(f==0)
{
cout<<"\n Record not found.";
}
ob6.close();
getch();
}
void member::del()
{
member mem;
int d;
ifstream ob7;
ofstream ob8;
ob7.open("meb.txt",ios::in);
ob8.open("temp.txt",ios::app);
cout<<"\n Enter id no. to delete a member : ";
cin>>d;
ob7.read((char*)&mem,sizeof(mem));
while(ob7)
{
if(mem.idno==d)
{
mem.show();
cout<<"\n Record deleted.";
}
else
{
ob8.write((char*)&mem,sizeof(mem));
}
ob7.read((char*)&mem,sizeof(mem));
}
remove("meb.txt");
rename("temp.txt","meb.txt");
ob7.close();
ob8.close();
getch();
}
void member::modify()
{
member mem;
int d;
ifstream ob9;
ofstream ob10;
ob9.open("meb.txt",ios::in);
ob10.open("temp.txt",ios::app);
cout<<"\n Enter id no. to modify record : ";
cin>>d;
ob9.read((char*)&mem,sizeof(mem));
while(ob9)
{
if(mem.idno==d)
{
mem.show();
cout<<"\n Enter new values for record";
mem.add();
ob10.write((char*)&mem,sizeof(mem));
}
else
{
ob10.write((char*)&mem,sizeof(mem));
}
ob9.read((char*)&mem,sizeof(mem));
}
remove("meb.txt");
rename("temp.txt","meb.txt");
ob9.close();
ob10.close();
getch();
}
void member::show()
{
cout<<"\n Id no. : "<<idno;
cout<<"\n Member name : "<<nm;
cout<<"\n Address of member : "<<ad;
cout<<"\n Phone no : "<<pno;
cout<<"\n Membership started on : "<<mems;
cout<<"\n Membership valid upto : "<<val;
}
void member::exit()
{
getch();
}
class issue
{
public:
char baa[50];
char buka[50];
char editi[59];
char doi[50];
char bi[50];
char mno[50];
char tik[40];
int bn;
issue()
{
strcpy(baa,"");
bn=0;
}
void add();
void search();
void del();
void modify();
void show();
void exit();
};
void issue::add()
{
cout<<("\n Enter book name : ");
gets(baa);
cout<<("\n Enter book author : ");
gets(buka);
cout<<("\n Enter edition : ");
gets(editi);
cout<<"\n Enter date of issue(Enter date without spaces) : ";
gets(doi);
cout<<"\n Book issued to : ";
gets(bi);
cout<<"\n Member id no. : ";
gets(mno);
cout<<"\n Ticket no. : ";
gets(tik);
}
void issue::search()
{
issue iss;
int d;
ifstream ob11;
int f=0;
ob11.open("isu.txt",ios::in);
cout<<"\n Enter book no. to search : ";
cin>>d;
ob11.read((char*)&iss,sizeof(iss));
while(ob11)
{
if(iss.bn==d)
{
iss.show();
cout<<"\n Book found.";
f=1;
break;
}
else
{
f=0;
}
ob11.read((char*)&iss,sizeof(iss));
}
if(f==0)
{
cout<<"\n Book is already issued.";
}
ob11.close();
getch();
}
void issue::del()
{
issue iss;
int d;
ifstream ob12;
ofstream ob13;
ob12.open("isu.txt",ios::in);
ob13.open("temp.txt",ios::app);
cout<<"\n Enter book no. to search : ";
cin>>d;
ob12.read((char*)&iss,sizeof(iss));
while(ob12)
{
if(iss.bn==d)
{
iss.show();
cout<<"\n Record deleted.";
}
else
{
ob13.write((char*)&iss,sizeof(iss));
}
ob12.read((char*)&iss,sizeof(iss));
}
remove("isu.txt");
rename("temp.txt","isu.txt");
ob12.close();
ob13.close();
getch();
}
void issue::modify()
{
issue iss;
int d;
ifstream ob14;
ofstream ob15;
ob14.open("isu.txt",ios::in);
ob15.open("temp.txt",ios::app);
cout<<"\n Enter book no. to modify record :";
cin>>d;
ob14.read((char*)&iss,sizeof(iss));
while(ob14)
{
if(iss.bn==d)
{
iss.show();
cout<<"\n Enter new values for record";
iss.add();
ob15.write((char*)&iss,sizeof(iss));
}
else
{
ob15.write((char*)&iss,sizeof(iss));
}
ob14.read((char*)&iss,sizeof(iss));
}
remove("isu.txt");
rename("temp.txt","isu.txt");
ob14.close();
ob15.close();
getch();
}
void issue::show()
{
cout<<"\n Book no : "<<bn;
cout<<"\n Book name : "<<baa;
cout<<"\n Book author : "<<buka;
cout<<"\n Book edition : "<<editi;
cout<<"\n Date of issue : "<<doi;
cout<<"\n Book issued to : "<<mno;
cout<<"\n Member id no. : "<<bi;
cout<<"\n Ticket no. : "<<tik;
}
void issue::exit()
{
getch();
}
class retrn
{
int bnn;
char ba[30];
char dor[20];
public:
void add();
void search();
void del();
void modify();
void show();
void exit();
};
void retrn::add()
{
issue iss;
retrn ret;
char ch='y';
ifstream ob16;
int d;
while(ch=='y'||ch=='Y')
{
ob16.open("file.txt",ios::in);
cout<<"\n Enter book no.";
cin>>bnn;
ob16.read((char*)&ret,sizeof(ret));
while(ob16)
{
if(iss.bn==bnn)
{
cout<<"\n Enter the date of return(Enter date without spaces) : ";
cin>>dor;
}
else
{
exit();
}
}
cout<<"\n Enter 'y' to continue : ";
cin>>ch;
}
}
void retrn::search()
{
retrn ret;
int d;
ifstream ob17;
int f=0;
ob17.open("file.txt",ios::in);
cout<<"Enter book no. to search : ";
cin>>d;
ob17.read((char*)&ret,sizeof(ret));
while(ob17)
{
if(ret.bnn==d)
{
ret.show();
cout<<"\n Book returned.";
f=1;
break;
}
else
{
f=0;
}
}
if(f==0)
{
cout<<"\n Book not returned.";
}
ob17.close();
}
void retrn::del()
{
retrn ret;
int d;
ifstream ob18;
ofstream ob19;
ob18.open("file.txt",ios::in);
ob19.open("temp.txt",ios::app);
cout<<"\n Enter book no. to search : ";
cin>>d;
ob18.read((char*)&ret,sizeof(ret));
while(ob18)
{
if(ret.bnn==d)
{
ret.show();
cout<<"\n Record deleted.";
}
else
{
ob19.write((char*)&ret,sizeof(ret));
}
ob18.read((char*)&ret,sizeof(ret));
}
remove("file.txt");
rename("temp.txt","file.txt");
ob18.close();
ob19.close();
}
void retrn::modify()
{
retrn ret;
int d;
ifstream ob20;
ofstream ob21;
ob20.open("file.txt",ios::in);
ob21.open("temp.txt",ios::app);
cout<<"Enter book no. to modify a record.";
cin>>d;
ob20.read((char*)&ret,sizeof(ret));
while(ob20)
{
if(ret.bnn==d)
{
ret.show();
cout<<"\n Enter new values for this record.";
ret.add();
ob21.write((char*)&ret,sizeof(ret));
}
else
{
ob21.write((char*)&ret,sizeof(ret));
}
ob20.read((char*)&ret,sizeof(ret));
}
remove("file.txt");
rename("temp.txt","file.txt");
ob20.close();
ob21.close();
getch();
}
void retrn::show()
{
cout<<"\n Book no. : "<<bnn;
cout<<"\n Book name : "<<ba;
cout<<"\n Date of issue : "<<dor;
}
void retrn::exit()
{
getch();
}
void book_menu()
{
char c='y';
ifstream ob1;
ofstream ob;
book b;
int ch;
clrscr();
cout<<"\n 1. Add new record";
cout<<"\n 2. Search record";
cout<<"\n 3. Delete record";
cout<<"\n 4. Modify record";
cout<<"\n 5. Show record";
cout<<"\n 6. Back to menu";
cout<<"\n Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
clrscr();
ob.open("book.txt",ios::app);
while(c=='y'||c=='Y')
{
b.add();
ob.write((char*)&b,sizeof(b));
cout<<"\n Press y to Continue : ";
cin>>c;
}
ob.close();
break;
case 2:
clrscr();
b.search();
break;
case 3:
clrscr();
b.del();
break;
case 4:
clrscr();
b.modify();
break;
case 5:
clrscr();
ob1.open("book.txt",ios::in);
ob1.read((char*)&b,sizeof(b));
while(ob1)
{
b.show();
ob1.read((char*)&b,sizeof(b));
}
ob1.close();
getch();
break;
case 6:
clrscr();
b.exit();
break;
}
}
void member_menu()
{
ofstream ob;
ifstream ob1;
int ch;
int days;
member mem;
char c='y';
clrscr();
cout<<"\n 1. Add new record";
cout<<"\n 2. Search record";
cout<<"\n 3. Delete record";
cout<<"\n 4. Modify record";
cout<<"\n 5. Show record";
cout<<"\n 6. Back to menu";
cout<<"\n Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
clrscr();
ob.open("meb.txt",ios::app);
while(c=='y'||c=='Y')
{
mem.add();
ob.write((char*)&mem,sizeof(mem));
cout<<"\n Press y to continue : ";
cin>>c;
}
ob.close();
break;
case 2:
clrscr();
mem.search();
break;
case 3:
clrscr();
mem.del();
break;
case 4:
clrscr();
mem.modify();
break;
case 5:
clrscr();
ob1.open("meb.txt",ios::in);
ob1.read((char*)&mem,sizeof(mem));
while(ob1)
{
mem.show();
ob1.read((char*)&mem,sizeof(mem));
}
ob1.close();
getch();
break;
case 6:
clrscr();
mem.exit();
break;
}
}
void issue_menu()
{
ofstream ob;
ifstream ob1;
int ch;
issue iss;
textcolor(RED);
cprintf("Warning : Book must be returned within a week or there is a fine of Rs.
2 / day.");
cout<<"\n 1. Add new record";
cout<<"\n 2. Search record";
cout<<"\n 3. Delete record";
cout<<"\n 4. Modify record";
cout<<"\n 5. Show record";
cout<<"\n 6. Back to menu";
cout<<"\n Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
clrscr();
book b;
int bn1;
int f=0;
ifstream ob11;
ofstream ob12;
ob12.open("isu.txt",ios::app);
ob11.open("book.txt",ios::in);
cout<<"\n Enter book no. you want to Issue : ";
cin>>bn1;
ob11.read((char*)&b,sizeof(b));
while(ob11)
{
if(b.bkno==bn1)
{
iss.bn=bn1;
iss.add();
f=1;
break;
}
else
{
f=0;
}
ob11.read((char*)&b,sizeof(b));
}
if(f==0)
cout<<"\n Book not available.";
else
ob12.write((char*)&iss,sizeof(iss));
ob11.close();
ob12.close();
getch();
getch();
break;
case 2:
iss.search();
break;
case 3:
iss.del();
break;
case 4:
iss.modify();
break;
case 5:
ob1.open("isu.txt",ios::in);
ob1.read((char*)&iss,sizeof(iss));
while(ob1)
{
iss.show();
ob1.read((char*)&iss,sizeof(iss));
cout<<"\n Press any key to continue.";
getch();
}
ob1.close();
getch();
break;
case 6:
iss.exit();
break;
}
}
void main()
{
int ch;
clrscr();
while(ch!=4)
{
clrscr();
textcolor(MAGENTA+BLINK);
cprintf("..........********** Welcome to 'Library Management
Project'**********..........");
textcolor(MAGENTA);
cprintf("................................................................................");
textcolor(YELLOW);
cprintf("\n\nSubmitted To : Prem Saini Sir Submitted by : Inderjeet Singh");
textcolor(YELLOW);
cprintf("\n................................................................................");
cout<<"\n 1. Book Menu";
cout<<"\n 2. Member Menu";
cout<<"\n 3. Issue Menu";
cout<<"\n 4. Exit";
cout<<"\n Enter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
clrscr();
book_menu();
break;
case 2:
clrscr();
member_menu();
break;
case 3:
clrscr();
issue_menu();
break;
case 4:
textcolor(MAGENTA);
cprintf("\n\n \n\n\n\n\n\n\n\n\n\n\n\n\n Thanks for using it!!!");
getch();
}
}
};
Labels:
c projects,
library management
Thursday, June 10, 2010
Demo Project
#include<stdio.h>
#include<conio.h>
struct student
{
int rlno;
char na[20];
}; //structure for student data
struct student stu; //global variable for structure
//Function to recieve value of structure
void getdata()
{
printf("\n Enter Roll Num ");
scanf("%d",&stu.rlno);
printf("\n Enter Name ");
scanf("%s",stu.na);
}
//function to display values of structure
void showdata()
{
// printf("\n Name is %s ",stu.na);
// printf("\n Roll Num is %d ",stu.rlno);
printf("\n%d\t\t%s\n",stu.rlno,stu.na);
}
void main()
{
int ch; // var for choice
int choice;
int rl;
FILE *fp, *fp1;//var to open a file
while(choice!=5)
{
clrscr();
printf("\n 1. Add data ");
printf("\n 2. List Records ");
printf("\n 3. Delete Record ");
printf("\n 4. Modify Record ");
printf("\n 5. Quit");
printf("\n Enter your choice ");
scanf("%d",&choice);
switch(choice)
{
case 1:
fp=fopen("stud.txt","a"); //openning a file
while(ch!=0)//loop
{
getdata();//getting data
fwrite(&stu,sizeof(stu),1,fp);//writing to a file
printf("\n Press 1 to add more, 0 to quit ");//prompt the user for cont...
scanf("%d",&ch);
}
fclose(fp);//closing a file
break;
case 2:
fp=fopen("stud.txt","r"); //reopening a file
printf("\n Roll Num\t\tName");
printf("\n======================================\n");
while(fread(&stu,sizeof(stu),1,fp)==1)//loop for reading data
{
showdata();//display a data
}
fclose(fp);//closing a file
getch();
break;
case 3:
fp=fopen("stud.txt","r");
fp1=fopen("temp.txt","a");
printf("\n Enter rollnum u wanna delete ");
scanf("%d",&rl);
while(fread(&stu,sizeof(stu),1,fp)==1)
{
if(stu.rlno==rl)
{
printf("\n Record found ");
showdata();
printf("\n Press any Key to cont...");
getch();
}
else
{
fwrite(&stu,sizeof(stu),1,fp1);
}
}
fclose(fp);
fclose(fp1);
remove("stud.txt");
rename("temp.txt","stud.txt");
break;
case 4:
fp=fopen("stud.txt","r");
fp1=fopen("temp.txt","a");
printf("\n Enter rollnum u wanna Modify ");
scanf("%d",&rl);
while(fread(&stu,sizeof(stu),1,fp)==1)
{
if(stu.rlno==rl)
{
printf("\n Record found ");
showdata();
printf("\n Press any Key to enter new Values");
getch();
getdata();
fwrite(&stu,sizeof(stu),1,fp1);
}
else
{
fwrite(&stu,sizeof(stu),1,fp1);
}
}
fclose(fp);
fclose(fp1);
remove("stud.txt");
rename("temp.txt","stud.txt");
break;
case 5:
printf("\n Thanks for using this software ");
getch();
break;
default:
printf("\n Invalid Option ");
getch();
}//switch
}//while
}
#include<conio.h>
struct student
{
int rlno;
char na[20];
}; //structure for student data
struct student stu; //global variable for structure
//Function to recieve value of structure
void getdata()
{
printf("\n Enter Roll Num ");
scanf("%d",&stu.rlno);
printf("\n Enter Name ");
scanf("%s",stu.na);
}
//function to display values of structure
void showdata()
{
// printf("\n Name is %s ",stu.na);
// printf("\n Roll Num is %d ",stu.rlno);
printf("\n%d\t\t%s\n",stu.rlno,stu.na);
}
void main()
{
int ch; // var for choice
int choice;
int rl;
FILE *fp, *fp1;//var to open a file
while(choice!=5)
{
clrscr();
printf("\n 1. Add data ");
printf("\n 2. List Records ");
printf("\n 3. Delete Record ");
printf("\n 4. Modify Record ");
printf("\n 5. Quit");
printf("\n Enter your choice ");
scanf("%d",&choice);
switch(choice)
{
case 1:
fp=fopen("stud.txt","a"); //openning a file
while(ch!=0)//loop
{
getdata();//getting data
fwrite(&stu,sizeof(stu),1,fp);//writing to a file
printf("\n Press 1 to add more, 0 to quit ");//prompt the user for cont...
scanf("%d",&ch);
}
fclose(fp);//closing a file
break;
case 2:
fp=fopen("stud.txt","r"); //reopening a file
printf("\n Roll Num\t\tName");
printf("\n======================================\n");
while(fread(&stu,sizeof(stu),1,fp)==1)//loop for reading data
{
showdata();//display a data
}
fclose(fp);//closing a file
getch();
break;
case 3:
fp=fopen("stud.txt","r");
fp1=fopen("temp.txt","a");
printf("\n Enter rollnum u wanna delete ");
scanf("%d",&rl);
while(fread(&stu,sizeof(stu),1,fp)==1)
{
if(stu.rlno==rl)
{
printf("\n Record found ");
showdata();
printf("\n Press any Key to cont...");
getch();
}
else
{
fwrite(&stu,sizeof(stu),1,fp1);
}
}
fclose(fp);
fclose(fp1);
remove("stud.txt");
rename("temp.txt","stud.txt");
break;
case 4:
fp=fopen("stud.txt","r");
fp1=fopen("temp.txt","a");
printf("\n Enter rollnum u wanna Modify ");
scanf("%d",&rl);
while(fread(&stu,sizeof(stu),1,fp)==1)
{
if(stu.rlno==rl)
{
printf("\n Record found ");
showdata();
printf("\n Press any Key to enter new Values");
getch();
getdata();
fwrite(&stu,sizeof(stu),1,fp1);
}
else
{
fwrite(&stu,sizeof(stu),1,fp1);
}
}
fclose(fp);
fclose(fp1);
remove("stud.txt");
rename("temp.txt","stud.txt");
break;
case 5:
printf("\n Thanks for using this software ");
getch();
break;
default:
printf("\n Invalid Option ");
getch();
}//switch
}//while
}
Labels:
c projects,
Project,
Source code
Subscribe to:
Posts (Atom)