Page

Library Management System In C/C++

#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
#include<graphics.h>
#include<stdlib.h>
void view();
void menu();
void add();
void list();
void issue();
void list_issued();
void main()
{
clrscr();
view();
setcolor(8);
setbkcolor(4);
settextstyle(1,0,4);
outtextxy(120,120,"Library Management System");
outtextxy(60,200,"Developed by sourcecodernp.blogspot.com");
outtextxy(150,300,"Please Wait a Movement");
delay(5000);
menu();
getch();
}
void view()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"..\\bgi");
}
void menu()
{
int ch;
clrscr();
view();
setbkcolor(4);
gotoxy(30,10);
printf("Main Menu");
gotoxy(30,12);
printf("1.Add New Records");
gotoxy(30,13);
printf("2.List of Books");
gotoxy(30,14);
printf("3.Book Issued");
gotoxy(30,15);
printf("4.List of issued book");
gotoxy(30,16);
printf("5.Search Book");
gotoxy(30,17);
printf("6.Exit");
gotoxy(30,18);
printf("Enter Your Choice");
scanf("%d",&ch);
switch(ch)
{
case 1:
add();
break;
case 2:
list();
break;
case 3:
issue();
break;
case 4:
list_issued();
break;
case 5:
printf("under construction");
break;
case 6:
exit(0);
break;
default:
menu();
break;
}
}
void add()
{
int another;
FILE *fp;
struct book
{
char book_name[40];
char author_name[40];
int book_id;
int stock;
};
struct book b;
clrscr();
view();
setbkcolor(4);
fp=fopen("book.dat","ab");
if(fp==NULL)
{
printf("File Cannot Open");
}
fseek(fp,0,SEEK_END);
another='Y';
while(another=='Y')
{
printf("\n\nEnter Book Id:");
scanf("%d",&b.book_id);
printf("\n\nEnter Book name:");
scanf("%s",b.book_name);
printf("\n\nAuthor Name:");
scanf("%s",b.author_name);
printf("\n\nStock In hand:");
scanf("%d",&b.stock);
fwrite(&b,sizeof(b),1,fp);
printf("\n\nRecords is Update");
printf("\n\nAdd Another Record(Y/N):");
fflush(stdin);
another=getche();
}
fclose(fp);
menu();
}
void list()
{
FILE *fp;
struct book
{
char book_name[40];
char author_name[40];
int book_id;
int stock;
};
struct book b;
clrscr();
view();
setbkcolor(4);
gotoxy(1,1);
printf("Book Id");
gotoxy(15,1);
printf("Book Name");
gotoxy(27,1);
printf("Author Name");
gotoxy(45,1);
printf("Stock");
fp=fopen("book.dat","rb");
if(fp==NULL)
{
printf("\n\nError-File Cannot Open");
}
rewind(fp);
while(fread(&b,sizeof(b),1,fp)==1)
{
printf("\n\n%d",b.book_id);
printf("\t\t%s",b.book_name);
printf("\t\t%s",b.author_name);
printf("\t\t%d",b.stock);
}
fclose(fp);
}
void issue()
{
char anothor='Y';
struct issue
{
char i_date;
char r_date;
int reg_no;
int book_id;
};
struct issue s;
FILE *ft;
clrscr();
view();
setbkcolor(4);
ft=fopen("issue","ab");
if(ft==NULL)
{
printf("\nFile Cannot open");
}
while(anothor=='Y')
{
printf("Enter Registration no:");
scanf("%d",&s.reg_no);
printf("Enter Book Id");
scanf("%d",&s.book_id);
printf("\Enter Issued Date:");
scanf("%s",s.i_date);
printf("Enter Return Date:");
scanf("%s",s.r_date);
fwrite(&s,sizeof(s),1,ft);
printf("\n\nRecords Updated");
printf("\n\nYou Wnat to another Record(Y/N):");
fflush(stdin);
anothor=getche();
}
}
void list_issued()
{
clrscr();
printf("Under construction");
}

Lift Management System In C/C++

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void ground();
void first();
void second();
void third();
void fourth();
void fifth();
void sixth();
void seventh();
void eighth();
void ninth();
void main()
{
int ch;
clrscr();
printf("\n\nEnter floor No:");
scanf("%d",&ch);
switch(ch)
{
case 1:
first();
break;
case 2:
second();
break;
case 3:
third();
break;
case 4:
fourth();
break;
case 5:
fifth();
break;
default:
printf("\nPls Enter valid No:");
break;
}
getch();
}
void first()
{
int i;
printf("\n\nYou are going to first Floor:");
printf("\n\nTime is left:");
for(i=9;i>=0;i--)
{
delay(2000);
printf("%d\b",i);
}
printf("\n\nLift is Stop Pls get down");
sound(300);
delay(3000);
nosound();
}
void second()
{
int i;
first();
clrscr();
printf("\nNow you are going second floor");
printf("\n\nTime left : ");
for(i=9;i>=0;i--)
{
delay(2000);
printf("%d\b",i);
}
printf("\n\nLift is Stop Pls get down");
sound(500);
delay(3000);
nosound();
}
void third()
{
int i;
second();
clrscr();
printf("\nNow you are going to Third floor");
printf("\n\nTime left : ");
for(i=9;i>=0;i--)
{
delay(2000);
printf("%d\b",i);
}
printf("\n\nLift is stop Pls get down");
sound(500);
delay(3000);
nosound();
}
void fourth()
{
int i;
third();
clrscr();
printf("\nNow you are going to Fourth floor");
printf("\n\nTime left : ");
for(i=9;i>=0;i--)
{
delay(2000);
printf("%d\b",i);
}
printf("\n\nLift is stop Pls get down");
sound(500);
delay(3000);
nosound();
}
void fifth()
{
int i;
fourth();
clrscr();
printf("\nNow you are going to fifth floor");
printf("\n\nTime left : ");
for(i=9;i>=0;i--)
{
sound(500);
delay(2000);
nosound();
printf("%d\b",i);
}
printf("\n\nLift is stop Pls get down");
delay(3000);
}
void sixth()
{
int i;
fifth();
clrscr();
printf("\nNow you are going to sixth floor");
printf("\n\nTime left : ");
for(i=9;i>=0;i--)
{
sound(500);
delay(2000);
nosound();
printf("%d\b",i);
}
printf("\n\nLift is stop Pls get down");
delay(3000);
}
void seventh()
{
int i;
sixth();
clrscr();
printf("\nNow you are going to seventh floor");
printf("\n\nTime left : ");
for(i=9;i>=0;i--)
{
delay(2000);
printf("%d\b",i);
}
printf("\n\nLift is stop Pls get down");
sound(500);
delay(3000);
nosound();
}

Program to Linear Search and Binary Search in C/C++

#include<iostream.h>
#include<process.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
int linser(int[],int,int);
void main()
{ clrscr();
int a[50],item,n,index,ch;
cout<<"\n\n\n\t\t\t\t\t\tOPTIONS\n\t\t\t\t\t\t...........";
cout<<"\n\n1.Linear Search\n2.Binary Search\n3.Exit.";
cout<<"\n\n\nEnter your choice  :";
cin>>ch;
switch(ch)
{case 1:
{       clrscr();
cout<<"ENTER THE DESIRED ARRAY SIZE(max. 50):";
cin>>n;
cout<<"\nENTER ARRAY ELEMENTS\n";
for(int i=0;i<n;i++)
{ cin>>a[i];
}
cout<<"\nENTER ELEMENT TO BE SEARCHED FOR...";
cin>>item;
index=linser(a,n,item);
if(index==-1)
cout<<"\nSorry!!Given element could not be found.\n";
else
cout<<"\nElement found at index:"<<index<<",Position:"<<index+1<<"\n";
break;
}
case 2:
{ clrscr();
cout<<"ENTER THE DESIRED ARRAY SIZE(max. 50):";
cin>>n;
cout<<"\nENTER ARRAY ELEMENTS\n";
for(int i=0;i<n;i++)
{ cin>>a[i];
}
cout<<"\nENTER ELEMENT TO BE SEARCHED FOR...";
cin>>item;
index=binser(a,n,item);
if(index==-1)
cout<<"\nSorry!!Given element could not be found.\n";
else
cout<<"\nElement found at index:"<<index<<",Position:"<<index+1<<"\n";
break;

getch();
}
int linser(int a[],int size,int item)
{ for(int i=0;i<size;i++)
{ if(a[i]==item)
return i;
}
return -1;
}
int binser(int a[],int size,int item)
{ int beg,last,mid;
beg=0;
last=size-1;
while(beg<=last)
{ mid=(beg+last)/2;
if(item==a[mid])
return mid;
else if(item>a[mid])
beg=mid+1;
else
last=mid-1;
}
return -1;
}

Cable Tv Management System In C/C++ Language

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void package_list();
void package_rate();
void sport_package();
void news_package();
void movie_package();
void main()
{
int choice;
clrscr();
cout<<"\t\t\t--------------------------";
cout<<"\n\t\t\tCable Tv Management System\n";
cout<<"\n\t\t\t--------------------------\n\n";
cout<<"Package List      : 1\n";
cout<<"Package Rate      : 2\n";
cout<<"Exit              : 3\n";
cout<<"Enter Your Choice : ";
cin>>choice;
switch(choice)
{
case 1:
package_list();
break;
case 2:
package_rate();
break;
case 3:
exit(0);
}
getch();
}
void package_list()
{
int choice;
clrscr();
cout<<"\n\t\t\t\tMOVIE PACKAGE    : 1";
cout<<"\n\t\t\t\tNEWS  PACKAGE    : 2";
cout<<"\n\t\t\t\tSPORT PACKAGE    : 3";
cout<<"\n\t\t\t\tEXIT             : 4";
cout<<endl;
cout<<"t\t\t\t\tENTER YOUR CHOICE : ";
cin>>choice;
switch(choice)
{
case 1:
movie_package();
break;
case 2:
news_package();
break;
case 3:
sport_package();
break;
case 4:
exit(0);
}
}
void movie_package()
{
clrscr();
cout<<endl;
cout<<"\t\t\t\tSahara One\n";
cout<<"\t\t\t\tStar one\n";
cout<<"\t\t\t\tZ.Cinema\n";
cout<<"\t\t\t\tSet Max\n";
cout<<"\t\t\t\tFilmy\n";
cout<<endl<<endl<<"\t\t\t\tPress Any Key To Back : ";
getch();
package_list();
}
void news_package()
{
clrscr();
cout<<endl;
cout<<"\t\t\tStar News\n";
cout<<"\t\t\tZ News\n";
cout<<"\t\t\tAAJ Tak\n";
cout<<"\t\t\tNDTV\n";
cout<<"\t\t\tIndia Tv\n";
cout<<endl<<endl<<"\t\t\tPress Any Key To Back : ";
getch();
package_list();
}
void sport_package()
{
clrscr();
cout<<endl;
cout<<"\t\t\t\tStar Sport\n";
cout<<"\t\t\t\tNeo Sport\n";
cout<<"\t\t\t\tEspn\n";
cout<<"\t\t\t\tDD Sport\n";
cout<<"\t\t\t\tStar Cricket\n";
cout<<endl<<endl<<"\t\t\t\tPress Any Key To Back : ";
getch();
package_list();
}
void package_rate()
{
clrscr();
cout<<"\t\t\tPACKAGE NAME       : PACKAGE RATE\n\n";
cout<<"\t\t\tMOVIE PACKAGE      : 250\n";
cout<<"\t\t\tNEWS  PACKAGE      : 150\n";
cout<<"\t\t\tSPORT PACKAGE      : 200\n\n";
cout<<"\t\t\tPress Any Key To Go Back : ";
getch();
package_list();
}



Program to sort a range of numbers with Insertion and Quicksort in C

/* A program to sort a range of numbers with Insertion
   and Quicksort, check their sorting time and prompt
   the result on the screen */


/* use header file*/
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <values.h>
#include <time.h>
#include <string.h>
#include <conio.h>

/* define variable */
const int max=29000;
int list[max];
FILE *fp;
clock_t start,end;
char any1[8];

/* Insertion sort module */
void insertion(int min1,int max1)
{
    int a,b,v;

    for(a=min1;a<=max1;a++)
    {
       v = list[a];
       b = a;
       do
       {
  list[b] = list[b-1];
  b = b - 1;
       }  while(list[b-1] > v);
       list[b] = v;
    }
}

/* sort partitioning element */
void sorthree(int x,int y,int z)
{
int temp;

if (list[x] > list[y])
{
   temp = list[x];
   list[x] = list[y];
   list[y] = temp;
}
if (list[z] < list[x])
{
   temp = list[x];
   list[x] = list[z];
   list[z] = temp;
   temp = list[y];
   list[y] = list[z];
   list[z] = temp;
}
if ((list[z] > list[x]) && (list[z] < list[y]))
{
   temp = list[y];
   list[y] = list[z];
   list[z] = temp;
}
}

/* Quicksort module */
void quicksort(int min2,int max2)
{
int v,t,i,j,q;

if ((max2-min2) > 9)
{
   int m = (max2-min2+1)/2;
   sorthree(min2,m,max2);
   max2=max2-1;
   q = list[m];
   list[m] = list[max2];
   list[max2] = q;

   v = list[max2];
   i = min2+1;
   j = max2-1;
   do
   {
      do
      {
i=i+1;
      } while (list[i] < v);
      do
      {
j=j-1;
      } while (list[j] > v);
      t = list[i];
      list[i] = list[j];
      list[j] = t;
   }  while (i<j);
   list[j]=list[i];
   list[i]=list[max2];
   list[max2]=t;
   quicksort(min2,i-1);
   quicksort(i+1,max2);
 }
else
 insertion(min2,max2);
}


/* main program */
void main()
{
int i,j,k,min,max1;
char any2[8];

clrscr();
cout << "Enter a file name to store data :";
cin >> any1;             /* input data file name on */
cout << '\n' << "Generating file...waits\n\n";  /*   screen */

fp = fopen(any1,"w");
    for(j=0;j<max/200;j++)
    {
       for(i=0;i<200;i++)    /* write random values to file */
       {
  k = rand();
  fprintf(fp,"%d\n",k);
       }
    }
fclose(fp);

fp = fopen(any1,"r");
    i = 0;
    while(fscanf(fp,"%d\n",&k) != EOF)
    {
 list[i] = k;  /* read values from file and assign to an array */
 i = i + 1;
    }
fclose(fp);
min = 0;
max1 = max;
max1=max1-1;
cout << "Sorting with Quicksort... waits" << '\n';
start = clock();
quicksort(min,max1);   /* sort an unsorted list with quicksort */
end=clock();
float result = (end-start)/CLK_TCK;
cout << "The time needs to sort " << max
     << " numbers in Quciksort is : " << result << " second(s)" << "\n\n";


cout << "Enter an output file for Quicksort : ";
cin >> any2;

fp = fopen(any2,"w");
  for(i=0;i<max;i++)
  {                   /* write the output from quicksort and put them */
      k = list[i];    /*to a file */
      fprintf(fp,"%d\n",k);
  }
fclose(fp);

fp = fopen(any1,"r");
    i = 0;
    while(fscanf(fp,"%d\n",&k) != EOF)
    {
 list[i] = k;
 i = i + 1;
    }
fclose(fp);
cout << "\nSorting with Insertion Sort... waits" << '\n';
start = clock();
insertion(0,max);   /* sort an unsorted list with insertion sort */
end=clock();
result = (end-start)/CLK_TCK;
cout << "The time needs to sort " << max
     << " numbers in Insertion is : " << result << " second(s)" << "\n\n";

cout << "Sort an already sorted array again with Quicksort..." << '\n';
min = 0;
max1 = max;
max1=max1-1;
start = clock();
quicksort(min,max1);  /* sort an already sort list with quicksort */
end=clock();
result = (end-start)/CLK_TCK;
cout << "The time needs to sort " << max
     << " numbers in Quicksort is : " << result << " second(s)" << "\n";

cout << "Sort an already sorted array again with Insertion sort..." << '\n';
start = clock();
insertion(0,max);   /* sort an already list with insertion sort */
end=clock();
result = (end-start)/CLK_TCK;
cout << "The time needs to sort " << max
     << " numbers in Insertion sort is : " << result << " second(s)" << '\n';
}