So i'm new to C++ programming, and have a project in where the user inputs a sentence, and based on 5 grammar rules (Ex. <sentence> ::= <noun><verb><noun>), determines whether the sentence is legal or not. Also the words derive from different text files, (Ex. nouns.txt). I have looked at the strings & input . output tutorials here, but i am stuck and can't figure out what to start. I know i also have to include loops to test that the sentence follows all 5 rules. I was just wondering if anyone could help me start of.
Uhh it's just more of a concept based thing. I just don't know how to assign variables to the string, or even how to make my program check a sentence using those rules. If i could see how the code works using one of the rules, i would be able to figure out how to apply it to the rest of the rules. Just don't get how to write the rules as code is all.
sorry for being hard on you but if you start one thread and then completely disregard whatever's been put on that thread or give no feedback upon those suggestions and come back later with another thread describing the same problem it just seems like a waste of everyone's time. perhaps someone will give you a few leads
haha no it's totally fine man. I just figured I would simplify it down to what i actually need help with, and then just ask questions as i got along. didn't mean to waste your time! i appreciated your response.
so far i have that ^^ to check my files for the words inputted, but whenever i go to run it, it just says "unexpected type name 'fstream': expected expression" , is this happening because i haven't written the code for applying the grammar rules yet?
int findGrammar(string sentence) {
string A, B, C, D;
int wordNumber = 1;
for (int i = 0; i < sentence.size(); i++){
if (sentence [i] == '')
wordNumber++;
else {
if (wordNumber == 1)
A += sentence [i];
if (wordNumber == 2)
B += sentence [i];
if (wordNumber == 3)
C += sentence [i];
if (wordNumber == 4)
D +=sentence [i];
}
}
}
string isnoun;
string isverb;
string ispronoun;
string isadjective;
if (isNoun(A)==true && isVerb(B)==true && isNoun(C)==true){
cout << "Your sentence is a legal sentence by rule 1." <<
endl;
}
else if (isNoun(A)==true && isVerb(B)==true && isAdjective(C)==true && noun(D)==true){
cout << "Your sentence is a legal sentence by rule 2." <<
endl;
}
else if (isPronoun(A)==true && isVerb(B)==true && isNoun(C)==true){
cout << "Your sentence is a legal sentence by rule 3." << endl;
}
else if (isPronoun(A)==true && isVerb(B)==true && isAdjective(C)==true && isNoun(D)==true){
cout << "Your sentence is a legal sentence by rule 4." << endl;
}
else if (isPronoun(A)==true && isVerb(B)==true && isPronoun(C)==true){
cout << "Your sentence is a legal sentence by rule 5." << endl;
}
else
cout << "Your sentence is not a legal sentence." << endl;{
return 0;
}