email:ali_h2_2007hoo.com
Printable View
email:ali_h2_2007hoo.com
پست کاملا ناقص و نامفهوم هست . آدرس ایمیل هم نیاز نیست . جواب شما در همین تاپیک داده میشه .
سلام نميدونم اين بدردت ميخوره يا نه
[HTML]#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<process.h>
#include<dos.h>
#include<graphics.h>
#include<math.h>
#define size 80
struct book{
char nameb[50],publisher[20];
char subject;
int bookno,count;
float price;
}x[80];
init_list(){
int i;
for(i=0;i<80;i++)
*(x[i].nameb)='\0';
}
help(){
textbackground(8);
clrscr();
textcolor(13+BLINK);
gotoxy(10,1);
cprintf("****************WEL COME TO LIBRARY PROGRAM****************");
textcolor(12);
gotoxy(2,3);
cprintf("This program has a menu with 8 items.Each item does a spicial doing:\n");
gotoxy(2,4);
cprintf(" -The input function takes the particaulars each book of you.\n");
gotoxy(2,5);
cprintf(" -The sort function orgenizes books according to their name.\n");
gotoxy(2,6);
cprintf(" -The list function shows you the list of books with spicial subject that you enter it.\n");
gotoxy(2,8);
cprintf(" -The search function shows the particaulars any book in a chart that you enter the name of book.\n");
gotoxy(2,10);
cprintf(" -The save function saves all of information about books in a file.\n");
gotoxy(2,11);
cprintf(" -The load function loads information of file.\n");
gotoxy(2,12);
cprintf(" -The exit exits of program.\n");
gotoxy(10,20);
textcolor(13);
cprintf("++++++++++++######GOOD LUCK######++++++++++++");
getch();}
input()
{
int n,i;
clrscr();
/* ofstream fp("library.txt",ios::out|ios::binary);
if(!fp){
cout<<"cannot open file."<<'\n';
getch();
exit(0);
}*/
for(i=0;i<size;i++)
if(!(*x[i].nameb))
break;
if(i==size){
cout<<"struct is full press any key...";
getch();}
clrscr();
cout<<"\nEnter a value for n:";
cin>>n;
if(n==0||n>size)
exit(0);
for(i=0;i<n;i++)
{ cout<<"\nEnter the bookname:";
gets(x[i].nameb);
if(!(*x[i].nameb))
break;
cout<<"\nEnter the publisher of book:";
gets(x[i].publisher);
cout<<"\nEnter the subject of book:";
x[i].subject=getche();
cout<<"\nEnter the booknumber:";
cin>>x[i].bookno;
cout<<"\nEnter the count of book:";
cin>>x[i].count;
cout<<"\nEnter the price of book:";
cin>>x[i].price;
}
/* fwrite(&x[i],sizeof(struct book),1,f);
clrscr();
gotoxy(20,10);
textbackground(8);
textcolor(BLUE+BLINK);
cprintf("Data saved press any key");
textcolor(3);
getch();
fp.write((char*)&x,sizeof(struct book));
fp.close();*/
}
save(){
FILE *f;
int i;
clrscr();
f=fopen("a:\\library.dat","wb");
if(!f){
cout<<"cannot open file."<<'\n';
getch();
exit(1);
}
for(i=0;i<80;i++)
if(*x[i].nameb)
fwrite(&x[i],sizeof(struct book),1,f);
clrscr();
gotoxy(20,10);
textbackground(8);
textcolor(BLUE+BLINK);
cprintf("Data saved press any key");
textcolor(3);
getch();
}
table(){
clrscr();
int i,j,k,h;
for(i=1;i<17;i++)
{ gotoxy(15,1+i);
cout<<"|\n";}
for(j=1;j<17;j++)
{gotoxy(66,1+j);
cout<<"|\n"; }
for(k=0;k<17;k+=2)
{gotoxy(16,1+k);
for(h=0;h<50;h++)
cout<<"_";
cout<<'\n';}
gotoxy(27,2);
textcolor(13);
cprintf("******BOOK PARTICULARS******");
gotoxy(16,4);
textcolor(10);
cprintf("Name:");
gotoxy(16,6);
cprintf("Publisher:");
gotoxy(16,8);
cprintf("Subject:");
gotoxy(16,10);
cprintf("Book number:");
gotoxy(16,12);
cprintf("Count:");
gotoxy(16,14);
cprintf("Price:");
gotoxy(26,16);
textcolor(13+BLINK);
cprintf("**Press any key to continue**");
textcolor(3);
getch();
}
display(char *str){
char y;
int i;
/*ifstream fp1("library.txt",ios::out|ios::binary);
if(!fp1){
cout<<"cannot open file."<<'\n';
getch();
exit(0);
} */
do{
i=1;
y=getch();
if(y==13){
clrscr();
table();
/* for(int i=0;i<size;i++)
if(*x[i].nameb){
strcpy(s,x[i].nameb);
while(fp1.read((char*)&x,sizeof(struct book))) */
gotoxy(21,4);
puts(x[i].nameb);
gotoxy(26,6);
puts(x[i].publisher);
gotoxy(24,8);
cout<<x[i].subject;
gotoxy(28,10);
cout<<x[i].bookno;
gotoxy(22,12);
cout<<x[i].count;
gotoxy(22,14);
cout<<x[i].price;
// break;
}
getch(); break; }while(x[i].price);
getch(); }
int menu()
{textbackground(80);
int i,j,m=2,c;
char s[10];
clrscr();
textcolor(4);
gotoxy(17,1);
for(i=0;i<43;i++)
cprintf("-");
gotoxy(17,3);
for(i=0;i<43;i++)
cprintf("_");
gotoxy(17,22);
for(i=0;i<43;i++)
cprintf("-");
gotoxy(17,24);
for(i=0;i<43;i++)
cprintf("_");
for(j=0;j<23;j++){
gotoxy(17,m);
cprintf("|\n");
m++;}
int k=2;
for(i=0;i<23;i++){
gotoxy(60,k);
cprintf("|\n");
k++;}
textcolor(3);
gotoxy(19,4);
for(i=0;i<19;i++)
cprintf("_");
gotoxy(20,5);
printf("1.Enter information");
gotoxy(19,6);
for(i=0;i<19;i++)
cprintf("_");
gotoxy(34,7);
for(i=0;i<25;i++)
cprintf("_");
gotoxy(35,8);
printf("2.Sort according to name");
gotoxy(34,9);
for(i=0;i<25;i++)
cprintf("_");
gotoxy(19,10);
for(i=0;i<29;i++)
cprintf("_");
gotoxy(19,11);
printf("3.List according to subject");
gotoxy(19,12);
for(i=0;i<29;i++)
cprintf("_");
gotoxy(42,13);
for(i=0;i<17;i++)
cprintf("_");
gotoxy(43,14);
printf("4.search (name)");
gotoxy(42,15);
for(i=0;i<17;i++)
cprintf("_");
gotoxy(19,16);
for(i=0;i<26;i++)
cprintf("_");
gotoxy(19,17);
printf("5.Save information in file");
gotoxy(19,18);
for(i=0;i<26;i++)
cprintf("_");
gotoxy(34,19);
for(i=0;i<26;i++)
cprintf("_");
gotoxy(34,20);
printf("6.Load information of file");
gotoxy(34,21);
for(i=0;i<26;i++)
cprintf("_");
gotoxy(30,23);
printf("7.Help");
gotoxy(38,23);
printf("8.Exit");
do{
gotoxy(30,2);
cout<<"Please select:";
gets(s);
c=atoi(s);
}while(c<0||c>8);
return(c);
getche();
}
list(){
int i,c=1,r=1,flag=0;
float sum=0;
char s,m,n,*str;
clrscr();
cout<<"Enter acharactor as a subject:";//One of these charactor:c ,m ,f ,l ,g
s=getche();
for(i=0;i<80;i++)
{ if(s==x[i].subject)
{flag=1;
cout<<'\n';
puts(x[i].nameb);
cout<<endl;
sum+=x[i].price*x[i].count;}}
if(flag==0)
cout<<"\nThere is no book with this subject in this library.";
if(sum!=0)
cout<<'\n'<<sum<<"Tomans is all the price that is paid." ;
for(i=0;i<80;i++)
{strcpy(str,x[i].nameb);
gotoxy(c,r);
n=getch();
do{ n=getch();
if(n==72){
r--;
gotoxy(c,r);
}
if(n==80){
r++;
gotoxy(c,r);}
if(n==77){
c++;
gotoxy(c,r);}
if(n==75){
c--;
gotoxy(c,r);}}while(n!=13);
if(n==13&&x[i].nameb)
display(str);
} }
sort(){
FILE *f;
char tempt[50];
for(int k=0;k<80;k++)
// fread(&x[k],sizeof(struct book),1,f);
for(int i=0;i<79;i++)
for(int j=i;j<79-i;j++)
if(strcmpi(x[j+1].nameb,x[j].nameb)<0)
{ strcpy(tempt,x[j+1].nameb);
strcpy(x[j+1].nameb,x[j].nameb);
strcpy(x[j].nameb,tempt);
puts(x[j].nameb);
cout<<'\n';}
getch();}
search()
{
int flag=0,i;
char *sname,*str;
clrscr();
textcolor(10);
cprintf("Enter a name book:");
gets(sname);
for(i=0;i<80;i++)
if(strcmpi(sname,x[i].nameb)==0)
{ if(*x[i].nameb)
flag=1;
strcpy(str,sname);
table();
display(str);
break;}
if(flag==0)
{
textcolor(RED+BLINK);
cprintf("This book is'nt in library.");
textcolor(3);
}
getch();
}
load()
{FILE *f;
int i;
clrscr();
f=fopen("a:\\library.dat","rb");
if(!f){
cout<<"cannot open file."<<'\n';
getch();
exit(1);
}
init_list();
for(i=0;i<80;i++)
fread(&x[i],sizeof(struct book),1,f);
if(feof(f)){
clrscr();
gotoxy(20,10);
textbackground(8);
textcolor(BLUE+BLINK);
cprintf("Data loaded press any key");
textcolor(3);
getch();
exit(0);}
fclose(f);
}
void main()
{
char choice,y;
int s,a,b,x1,x2,y1,y2;
b=DETECT;
a=0;
union REGS regs;
initgraph(&b,&a,"c:\\tc\\bgi");
regs.x.ax=0;
int86(0x33,®s,®s);
regs.x.ax=01;
int86(0x33,®s,®s);
// page();
setcolor(7);
outtextxy(10,420,"command line:");
regs.x.bx=0;
do{regs.x.ax=03;
int86(0x33,®s,®s);
if(!kbhit())
break;}while(regs.x.bx==0);
if(regs.x.bx!=0)//click mouse
{
if((10<regs.x.cx)&&(regs.x.cx<100))
if((30<regs.x.dx)&&(regs.x.dx,129))
{regs.x.bx=0;
do{
regs.x.ax=03;
int86(0x33,®s,®s);
}while(regs.x.bx!=2);//right click for first point
x1=regs.x.dx;
y1=regs.x.cx;
regs.x.bx=0;
do{regs.x.ax=03;
int86(0x33,®s,®s);
}while(regs.x.bx!=1);//left click for second point
x2=regs.x.bx;
y2=regs.x.cx;
s=(x1-x2)*(x1-x2)-(y1-y2)*(y1-y2);
s=sqrt(s);
regs.x.bx=0;
}}
clrscr();
init_list();
for(;;){
choice=menu();
switch(choice){
case 1:input();break;
case 2:sort();break;
case 3:list();break;
case 4:search();break;
case 5:save();break;
case 6:load();break;
case 7:help();break;
case 8:exit(0);
} }
getche();
}[/HTML]