ورود

View Full Version : حرفه ای: چاپ خروجی در برنامه من



arefba
چهارشنبه 26 خرداد 1389, 00:53 صبح
بسم الله الرحمن الرحیم

بچه ها اگه بخوام از برنامه زیر لیست کتاب ها رو پرینت بگیرم
باید چه چیزی بنویسم
کدوم متغیر
کتابا کجان؟؟

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>

//===========================
//===========================
class book
{
friend class library;

private:
char book_name[20];
char explain[51];
char aouther[20];
char part;
char databuy[12] ;
char shomareh[10];
char mony[10];

char user[11];
int reserved;

book *next;

public:
book();
void edit();
void reserv();
void getback();
void printbook();

}
//---------------------------
book::book()
{
clrscr();

cout<<"============ sabte ketab jadid =================="
<<"\n\nbaraye sapt ketab jadid mavared zir ra takmil konid:"
<<"\n\nname ketad?";
gets(book_name);
book_name[20]=NULL;

cout<<"\n name nevisandeh?";
gets(aouther);
aouther[20]=NULL;

cout<<"\nmozooe ketab?";
gets(explain);
explain[50]=NULL;

cout<<"\ntarekh khrid?";
gets(databuy);
databuy[12]=NULL;

cout<<"\nghaimat ketab?";
gets(mony);
mony[10]=NULL;

cout<<"\n shomareh ketab?";
gets(shomareh);
shomareh[10]=NULL;

part=book_name[0];

reserved=0;

next=NULL;

cout<<"\n\nkeatb shoma sabt shod!";
getch();
}
//---------------------------
void book::edit()
{
cout<<"virayesh emkan pazir nist! ";
}
//---------------------------
void book::printbook()
{
clrscr();
cout<<"\n=========== print all book===================";

cout<<part;
// explain
// char aouther[20];
// char part;
// char databuy[12] ;
// char shomareh[10];
// char mony[10];

getch();
}
//---------------------------
void book::reserv()
{
clrscr();
cout<<"\n=========== reserve ketab ===================";

if(reserved==0)
{
cout<<"\n\nnam reserve konandeh:?";
gets(user);
user[11]=NULL;

reserved=1;
}
if(reserved==0)
{
cout<<"\n\nmotasefam! ketab reserve shodeh ast"
<<"tavasote:";
puts(user);
}

getch();
}
//---------------------------
void book::getback()
{
reserved=0;

cout<<"\n\nbargashte ketab";
getch();
}
//===========================
//===========================
class library
{
public:
library();
void run_menu();

private:
book *parts[24];
void insert(book*);
void find();
void search();

}
//---------------------------
library::library()
{
for(int i=0;i<=23;i++)
parts[i]=NULL;

}
//---------------------------
void library::run_menu()
{

char ch='n';

while(ch!='4')
{
clrscr();

cout<<"================= ketabkhaneh =================="
<<"\n\n1:sabte ketab jadid."
<<"\n\n2:reserve ketab."
<<"\n\n3:jostojoye ketab."
<<"\n\n4:khoroj."
<<"\nprint."
<<"\n\n(lotfan shomareh vared konid):"


ch=getch();


if(ch=='1')
{
book *n=new book;
insert(n);
}
if(ch=='2')
{
find();
}
if(ch=='3')
{
search();
}
if(ch=='5')
{
cout<<book_name[2];
//
}

}//while
}
//---------------------------
void library::insert(book *s)
{
int d=s->part-97;

if(parts[d]==NULL)
{
parts[d]=s;
}
else
{
book *p=parts[d],*q;
while(p!=NULL && strcmp(p->book_name,s->book_name)<0)
{
q=p;
p=p->next;
}
q->next=s;
s->next=p;
}

}
//---------------------------
void library::find()
{
clrscr();

cout<<"=========== virayesh/hazve ketab ============"
<<"\nlotfan nam ketab ra vared konid:";
char name[20];
gets(name);
name[20]=NULL;
int d=name[0]-97;

book *p=parts[d],*q;
while(p!=NULL && strcmp(p->book_name,name)!=0)
{
q=p;
p=p->next;
}
if(p==NULL)
{
cout<<"in ketab mojod nemibashad!";
}
if(p!=NULL)
{
cout<<"\n\nhazve?('d') "
<<" virayesh?('e')"
<<" reserve?('r')"
<<" bargashte ketab?('g') :";
char ch=getch();
if(ch=='d')
{
q->next=p->next;
delete p;
}
if(ch=='e')
{
p->edit();
}
if(ch=='r')
{
p->reserv();
}
if(ch=='g')
{
p->getback();
}
}
getch();
}
//---------------------------
void library::search()
{
char ch='6';

while(ch!='7')
{
clrscr();
cout<<"================== jostojo ===================";
cout<<"\n\n1:jostojo bar asas name keatb."
<<"\n2:jostojo bar asas name navisndeh ."
<<"\n3:jostojo bar asas mozooe keatb."
<<"\n4:jostojo bar asas tarekh khared."
<<"\n5:jostojo bar asas ghaymate ketab."
<<"\n6:jostojo bar asas shomareye ketab."
<<"\n7:bargasht be aghab.(vared konid shomareh ra)";

ch=getch();

if(ch=='1')
{
cout<<"\n\n name ketab ra vared konid:";
char name[20];
gets(name);
name[20]=NULL;

int d=name[0]-97;
book *p=parts[d];
while(p!=NULL && strcmp(p->book_name,name)!=0)
{
p=p->next;
}
if(p==NULL)
{
cout<<"\nin ketab mojod nemibashad!";
}
else
{
cout<<"\n\n";
cout<<"name:";puts(p->book_name);
cout<<"nevisandeh:";puts(p->aouther);
cout<<"mozoo:";puts(p->explain);
cout<<"tarekh:";puts(p->databuy);
cout<<"ghaymat:";puts(p->mony);
cout<<"shomatrh:";puts(p->shomareh);
if(p->reserved==1)
{
cout<<"RESERVE SHODEH:";
puts(p->user);
cout<<"\n=================================";
}
else
{
cout<<"RESERVE NASHODEH:"
<<"\n=================================";
}
}//else
getch();
}//1
if(ch=='2')
{
cout<<"\n\n name nevisandeh ra vared koned:";
char name[20];
gets(name);
name[20]=NULL;
int f=0;

for(int i=0;i<=23;i++)
{
book *p=parts[i];
while(p!=NULL)
{
if(strcmp(p->aouther,name)==0)
{
f++;
cout<<"\n"<<f<<":";
cout<<"name:";puts(p->book_name);
cout<<"nevisandeh:";puts(p->aouther);
cout<<"mozoo:";puts(p->explain);
cout<<"tarekh:";puts(p->databuy);
cout<<"ghaymat:";puts(p->mony);
cout<<"shomareh:";puts(p->shomareh);
if(p->reserved==1)
{
cout<<"RESERVE SHODEH:";
puts(p->user);
cout<<"\n=================================";
}
else
{
cout<<"RESERVE NASHODEH:"
<<"\n=================================";
}
}

p=p->next;
}//while
}
getch();
}//2
if(ch=='3')
{
cout<<"\n\nmozooe ketab ra vared konid:";
char name[16];
gets(name);
name[15]=NULL;
int f=0;

for(int i=0;i<=23;i++)
{
book *p=parts[i];
while(p!=NULL)
{
char *tokenptr;
tokenptr=strtok(p->explain," ");
while(tokenptr!=NULL)
{
if(strcmp(tokenptr,name)==0)
{
f++;

cout<<"\n"<<f<<":";
cout<<"name:";puts(p->book_name);
cout<<"nevisandeh:";puts(p->aouther);
cout<<"mozoo:";puts(p->explain);
cout<<"tarekh:";puts(p->databuy);
cout<<"ghaymat:";puts(p->mony);
cout<<"shomareh:";puts(p->shomareh);
if(p->reserved==1)
{
cout<<"RESERVE SHODEH:";
puts(p->user);
cout<<"\n=================================";
}
else
{
cout<<"RESERVE ANSHODEH:"
<<"\n=================================";
}
}
tokenptr=strtok(NULL," ");
}

p=p->next;
}//while
}//for i
getch();
}//3

if(ch=='4')
{
cout<<"\n\ntarekh khared ra vared konid:";
char name[12];
gets(name);
name[12]=NULL;
int f=0;

for(int i=0;i<=23;i++)
{
book *p=parts[i];
while(p!=NULL)
{
if(strcmp(p->databuy,name)==0)
{
f++;
cout<<"\n"<<f<<":";
cout<<"name:";puts(p->book_name);
cout<<"nevisandeh:";puts(p->aouther);
cout<<"mozoo:";puts(p->explain);
cout<<"tarekh:";puts(p->databuy);
cout<<"ghaymat:";puts(p->mony);
cout<<"shomareh:";puts(p->shomareh);
if(p->reserved==1)
{
cout<<"RESERVE SHODEH:";
puts(p->user);
cout<<"\n=================================";
}
else
{
cout<<"RESERVE NASHODEH:"
<<"\n=================================";
}
}

p=p->next;
}//while
}
getch();
}//4
if(ch=='5')
{
cout<<"\n\n ghaymate ktab ra vared konid:";
char name[10];
gets(name);
name[10]=NULL;
int f=0;

for(int i=0;i<=23;i++)
{
book *p=parts[i];
while(p!=NULL)
{
if(strcmp(p->mony,name)==0)
{
f++;
cout<<"\n"<<f<<":";
cout<<"name:";puts(p->book_name);
cout<<"nevisandeh:";puts(p->aouther);
cout<<"mozoo:";puts(p->explain);
cout<<"tarekh:";puts(p->databuy);
cout<<"ghaymat:";puts(p->mony);
cout<<"shomareh:";puts(p->shomareh);
if(p->reserved==1)
{
cout<<"RESERVE SHODEH:";
puts(p->user);
cout<<"\n=================================";
}
else
{
cout<<"RESERVE NASHODEH:"
<<"\n=================================";
}
}

p=p->next;
}//while
}
getch();
}//
if(ch=='6')
{
cout<<"\n\nshomareh ra vared konid:";
char name[10];
gets(name);
name[10]=NULL;
int f=0;

for(int i=0;i<=23;i++)
{
book *p=parts[i];
while(p!=NULL)
{
if(strcmp(p->shomareh,name)==0)
{
f++;
cout<<"\n"<<f<<":";
cout<<"name:";puts(p->book_name);
cout<<"nevisandeh:";puts(p->aouther);
cout<<"mozoo:";puts(p->explain);
cout<<"tarekh:";puts(p->databuy);
cout<<"ghaymat:";puts(p->mony);
cout<<"shomareh:";puts(p->shomareh);
if(p->reserved==1)
{
cout<<"RESERVE SHODEH:";
puts(p->user);
cout<<"\n=================================";
}
else
{
cout<<"RESERVE NASHODEH:"
<<"\n=================================";
}
}

p=p->next;
}//while
}
getch();
}//6


}

}
//===========================
//===========================
int main()
{
clrscr();

library l1;
l1.run_menu();

return(0);
}

arefba
چهارشنبه 26 خرداد 1389, 15:27 عصر
بنازم به انجمن سی پلاس پلاس
هیشکی نبود جواب بده

arefba
چهارشنبه 26 خرداد 1389, 15:51 عصر
به خدا نیاز دارم
چجوری میشه اسم همه کتاب ها رو چاپ کرد

#target
چهارشنبه 26 خرداد 1389, 16:14 عصر
فکر کنم به Library اینو اضافه کن !



viod print();
تعریفشم اینجوری


library::print()
{
for(int i=0;i<=23;i++)
cout << parts[i]->printbook();
}


اگه تو تالار C++ مینوشتی تا الان جواب گرفته بودی سوال شما ربطی به این تالار نداره !