الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

ممكن تساعدوني في تصحيح البرنامج...

بدأه Pretty2009 في 12 مايو 2009 · 2 رد · 439 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاتة..

....................................

ممكن تساعدوني في تصحيح هاذا البرنامج..

وفقكم اللــــــــــــــة

...........................................

البرنامج يقرأ من ملف موجود في قرص سي

في ملف الفيجول ستديو في البروجكت

الملف عبارة عن رول

اسم الملف

...........................

RuleFile.dat

/// output pgm

..Rule z1

If ( HAS ? X hair)

Then add ( IS ? x mammal)

Rule z2

If (GIVES ? X milk)

Then add ( IS ? x mammal)

Rule z3

If (HAS ? X feathers)

Then add (IS ? X bird )

Rule z4

If (FLIES ? X )

(LAYS ? X eggs)

Then add (IS ? x bird )

END

................................................................................

...................................

pgm

>>>>>>>>>>

#include<iostream.h>

#include<string.h>

#include <fstream>

using std::ifstream;

using std::ofstream;

ifstream RulebaseFile("RuleFile.dat",ios::in);

char *lexeme =new char[];

struct argrule

{

bool varcons;

char *value;

argrule *next;

};

argrule*argruleBase;

struct Cond

{

char *predicate ;

int nbrargument;

argrule *argument;

Cond *next;

};

Cond *CondBase=NULL;

struct Conc{

char *predicate ;

int nbrargument;

argrule *argument;

Conc *next;

};

Conc*ConcBase;

struct Rule{

char * Rname;

Cond *Condition;

Conc *Conclution;

Rule *next;

};

Rule *RuleBase=NULL;

void INSERTargrule()

{

argrule *P2=argruleBase ;

while(P2->varcons)

{

bool (P2->varcons);

RulebaseFile>>P2->value;

P2->next=NULL;

}

}

/* RuleBase->argrule = new Cond;

P2=RuleBase->argrule;

}

}

P1->next->nbrargument;

cin>>z;

for(int j=0;j<z;j++)

{ char s1[1];

// char s2[1]='?';

cin>>s1;

strcmp(s1,"?");

if(s1==s2)

{

cout<<argruleBase->varcons='T';

}

else

cout<<argruleBase->varcons='F';

cin>>argruleBase->value;

argruleBase->next;

}*/

void INSERTCond( )

{

Cond *P1;

if((RuleBase->Condition)==NULL)

{ RuleBase->Condition = new Cond;

P1=RuleBase->Condition;

}

else

{

P1=RuleBase->Condition;

while(P1->next!=NULL)

P1=P1->next;

P1->next=new Cond;

P1=P1->next;

}

RulebaseFile>>P1->predicate;

P1->nbrargument=0;

RulebaseFile>>lexeme;

while((strcmp(lexeme,")")!=0))

{

P1->nbrargument++;

INSERTargrule();

RulebaseFile>>lexeme;

}

}

void INSERTConc( )

{ Conc *P3;

if((RuleBase->Conclution)==NULL)

{ RuleBase->Conclution = new Conc;

P3=RuleBase->Conclution;

}

else

{

P1=RuleBase->Conclution;

RulebaseFile>>P3->predicate;

P3->nbrargument=0;

RulebaseFile>>lexeme;

while((strcmp(lexeme,")")!=0))

{

P3->nbrargument++;

INSERTargrule();

RulebaseFile>>lexeme;

}

}

void PrintRuleBase()

{

Rule *p= RuleBase;

while (p)

{

cout<<p->Rname<<"\n";

p = p->next;

}

}

//void printcond()

//{

//}

//void printconc()

//{

//}

void insertRule()

{

//int x;

// cout<<"give the number of rule";

// cin>>x;

Rule *p = RuleBase;

RuleBase=new Rule;

RuleBase->Rname = new char[5];

RulebaseFile>>RuleBase->Rname;

RuleBase->Conclution=NULL;

RuleBase->Condition=NULL;

RuleBase->next=p;

RulebaseFile>>lexeme;

if((strcmp(lexeme,"IF")==0)||(strcmp(lexeme,"if")==0))

{

RulebaseFile>>lexeme;

while((strcmp(lexeme,"THEN ADD")!=0)||(strcmp(lexeme,"then add")!=0))

{

INSERTCond();

RulebaseFile>>lexeme;

}

}

INSERTConc();

}

void ReadRuleBase()

{

char *lexeme;

//."?

lexeme = new char[];

cin>>lexeme;

while((strcmp(lexeme,"END")!= 0))// different from END

{

cout<<lexeme;

insertRule();

}

}

void main(){

//insertRule();

ReadRuleBase();

if(!RulebaseFile){cout<<"file not open";

exit(1);

}

PrintRuleBase();

//printcond();

//printconc();

INSERTCond( );

//factacquisition();

//Printfact();

}

#2

السلام عليكم

قمت بإصلاح الأخطاء البرمجيه

ولكنى بصراحه لم أفهم ما هو المطلوب من البرنامج بالضبط

#include<iostream.h>
#include<string.h>
#include <fstream>
using std::ifstream;
using std::ofstream;
ifstream RulebaseFile("RuleFile.dat",ios::in);
char *lexeme =new char[];
struct argrule
{
bool varcons;
char *value;
argrule *next;
};
argrule* argruleBase;
struct Cond
{
char *predicate;
int nbrargument;
argrule *argument;
Cond * next;
};
Cond * CondBase=NULL;
struct Conc{
char *predicate;
int nbrargument;
argrule *argument;
Conc *next;
};
Conc* ConcBase;
struct Rule{
char * Rname;
Cond *Condition;
Conc *Conclution;
Rule *next;
};
Rule *RuleBase=NULL;
void INSERTargrule()
{
argrule *P2=argruleBase;

while(P2->varcons)
{
bool (P2->varcons);
RulebaseFile>>P2->value;
P2->next=NULL;
}
}
/* RuleBase->argrule = new Cond;
P2=RuleBase->argrule;
}

}


P1->next->nbrargument;
cin>>z;
for(int j=0;j<z;j++)
{ char s1[1];
// char s2[1]='?';
cin>>s1;
strcmp(s1,"?");
if(s1==s2)
{
cout<<argruleBase->varcons='T';
}
else
cout<<argruleBase->varcons='F';

cin>>argruleBase->value;

argruleBase->next;
}*/

Cond *P1;
void INSERTCond( )
{
if((RuleBase->Condition)==NULL)
{ RuleBase->Condition = new Cond;
P1=RuleBase->Condition;
}
else
{
P1=RuleBase->Condition;
while(P1->next!=NULL)
P1=P1->next;
P1->next=new Cond;
P1=P1->next;
}

RulebaseFile>>P1->predicate;
P1->nbrargument=0;
RulebaseFile>>lexeme;
while((strcmp(lexeme,")")!=0))
{
P1->nbrargument++;
INSERTargrule();
RulebaseFile>>lexeme;
}
}
void INSERTConc( )
{ Conc *P3=NULL;

if((RuleBase->Conclution)==NULL)
{ RuleBase->Conclution = new Conc;
P3=RuleBase->Conclution;
}
else
{
P1=RuleBase->Condition;
RulebaseFile>>P3->predicate;
P3->nbrargument=0;
RulebaseFile>>lexeme;
while((strcmp(lexeme,")")!=0))
{
P3->nbrargument++;

INSERTargrule();
RulebaseFile>>lexeme;
}
}
}
void PrintRuleBase()
{
Rule *p= RuleBase;
while (p)
{
cout<<p->Rname<<"\n";
p = p->next;
}
}


//void printcond()
//{
//}

//void printconc()
//{
//}

void insertRule()
{
//int x;
// cout<<"give the number of rule";
// cin>>x;


Rule *p = RuleBase;

RuleBase=new Rule;

RuleBase->Rname = new char[5];

RulebaseFile>>RuleBase->Rname;

RuleBase->Conclution=NULL;

RuleBase->Condition=NULL;

RuleBase->next=p;

RulebaseFile>>lexeme;

if((strcmp(lexeme,"IF")==0)||(strcmp(lexeme,"if")==0))
{
RulebaseFile>>lexeme;
while((strcmp(lexeme,"THEN ADD")!=0)||(strcmp(lexeme,"then add")!=0))
{
INSERTCond();
RulebaseFile>>lexeme;
}
}

INSERTConc();



}

void ReadRuleBase()
{
char *lexeme;
//."?
lexeme = new char[];
cin>>lexeme;
while((strcmp(lexeme,"END")!= 0))// different from END
{
cout<<lexeme;
insertRule();

}

}

void main(){

//insertRule();
ReadRuleBase();
if(!RulebaseFile){cout<<"file not open";
exit(1);
}
PrintRuleBase();
//printcond();
//printconc();
INSERTCond();
//factacquisition();
//Printfact();
}

سلام

:resentful:

اللهم صل على سيدنا محمد وعلى آله وصحبه وسلم

#3

شكراً كثيراً لك

البرنامج يقرأ الملف الموجود بقرص سي

مواضيع مشابهة