السلام عليكم ورحمة الله وبركاتة
تحية طيبة لكل مشرف وعضو في هذا المنتدى المتميز
تكفون أطلب مساعدتكم أعرف أنه الوقت متأخر ولكن الحمد لله الله هداني لهذا المنتدى المتميز
وطبعا هذي أول مشاركة لي وتكفون أي شخص عندة خبرة ويقدر يساعدني ف حل هذا السؤال ما يبخل علي والف شكر لكل محب لفعل الخير
أترككم مع السؤال
Your task for this assignment is to write a simple keyword analyzer. Your program should ask read two files: "reservedwords.txt" file that contains all the data type reserved words which are data types: int, double, char, bool, enum, struct, class, … and an input file that your program should ask the user to enter its name. Then your program will read the input file, analyze its content (each statement, where a statement ends by ;) and save the reserved key word (data type) only as a result and print them as an output. Finally, the program should compare the reserved words along with the set of stored keywords and return true if the statement is a data declaration.
Your program should use:
· Arrays, pointers and strings.
· Files.
· Functions.
For example if the input file contains the following paragraph:
int x, y;
double z;
enum week {SAT, SUN, MON, TUE, WED, THU, FRI};
cout<<x;
Then the program should save the reserved words which are int, double, enum. After that, compare each word with the list of reserved word and return true a statement contains a reserved word otherwise return false.
ولا تبخلو علي أروكم ترائ التسليم بكرا المساء وألف شكر مرة ثانية
وهذا صورة من برنامجي الي حاولت احلة لكن بدون فايدة النتلئج خطا ف الجزئية الأخير
#include <iostream>
#include <fstream>
#include <cstring>
#include<iomanip>
using namespace std;
//Declaration of global data which are common to all the functions
void ReadInputFile (char []);
void ReadReservedFile ();
void SaveWord (char* word);
void SaveWord2 (char* word2);
bool CompareWords ();
// Two Arrayes of 100 words having a maximum of 50
//charcaters each
char KeyWord [100][50];
char KeyWord2 [30][50];
int i=0;
int s=0;
int ss=0;
int ii=0;
int main()
{
char fileName [20];
cout<<"Please type the name of the input file:"<<endl;
cin>> fileName;
cout<<endl;
ReadInputFile (fileName);
//PrintResult();
cout<<endl;
int u=0;
for (int k=0; k<i; k++)
{
cout<<KeyWord[k];
u++;
}
cout<<endl;
cout<<"********************************";
cout<<endl;
ReadReservedFile ();
for (int z=0; z<ii; z++)
cout<<KeyWord2[z];
cout<<endl;
cout<<"********************************";
cout<<endl;
bool SeeReasult = CompareWords();
for (int zz=0; zz<i; zz++)
{
cout<<KeyWord[zz]<<"\t\t"<<SeeReasult;
}
cout<<endl;
return 0;
}
void ReadInputFile (char fileName [])
{
ifstream InputFile;
char line[80];
char *wordptr;
InputFile.open(fileName);
while(!InputFile.eof()) {
InputFile.getline(line, 100, ';');
wordptr=strtok(line ," * << >>");
int counter =1;
while (wordptr!=NULL && counter !=2 )
{
SaveWord(wordptr);
counter++;
wordptr=strtok(NULL," ");
}
}
}
void ReadReservedFile ()
{
ifstream ReservedFile;
char line2[100];
char *PWord;
ReservedFile.open("reservedwords.txt");
while(!ReservedFile.eof()) {
ReservedFile.getline(line2, 100, '\0');
PWord=strtok(line2," ");
while (PWord!=NULL) {
SaveWord2(PWord);
PWord=strtok(NULL," ");
}
}
}
void SaveWord (char* wordptr)
{
strcpy(KeyWord,wordptr);
strcat(KeyWord," ");
i++;
s++;
}
void SaveWord2 (char* PWord)
{
strcpy(KeyWord2[ss],PWord);
strcat(KeyWord2[ss]," ");
ii++;
ss++;
}
bool CompareWords ()
{
bool True = true;
bool Fulse = false;
for ( int a=0; a<i; a++)
for(int aa=0; aa<ii; aa++)
{
if(strcmp( KeyWord2[aa] , KeyWord[a])==0)
return True;
if(strcmp(KeyWord2[aa] , KeyWord[a])!=0)
return Fulse;
}
return True , Fulse;
}
والف شكرا مرة ثانية ((عاشقة الجنة)) ..