C++ Language:
TestCase:
CODE Explanation in code Comments :
void sort_i_before_e(Words &input , Words
&follows_rule,Words &violates_rule,Words
&inapplicable_rule){
for(int i=0;i<input.size();i++){
//Find "ei","ie" in the
vector
size_t ie =
input[i].find("ie");
size_t ei =
input[i].find("ei");
if(ie!=string::npos){
//Rule : if
"cie" exits in input[i] then goes violates_rule
//Rule : if
"cie" not exits in input[i] then goes follows_rule
if(input[i][ie-1]!='c'){
follows_rule.push_back(input[i]);
}else{
violates_rule.push_back(input[i]);
}
}else if(ei != string::npos){
//Rule : if
"cei" exits in input[i] then goes follows_rule
//Rule : if "ei"
exits in input[i] then goes violates_rule
if(input[i][ei-1]=='c'){
follows_rule.push_back(input[i]);
}else{
violates_rule.push_back(input[i]);
}
}else{
//"ei","ie" not
exists then goes to inapplicable_rule
inapplicable_rule.push_back(input[i]);
}
}
}
Entire Code :
#include<iostream>
#include<vector>
#include<string>
using namespace std;
using Words = vector<string>;
using Word = string;
void sort_i_before_e(Words &input , Words
&follows_rule,Words &violates_rule,Words
&inapplicable_rule){
for(int i=0;i<input.size();i++){
//Find "ei","ie" in the
vector
size_t ie =
input[i].find("ie");
size_t ei =
input[i].find("ei");
if(ie!=string::npos){
//Rule : if
"cie" exits in input[i] then goes violates_rule
//Rule : if
"cie" not exits in input[i] then goes follows_rule
if(input[i][ie-1]!='c'){
follows_rule.push_back(input[i]);
}else{
violates_rule.push_back(input[i]);
}
}else if(ei != string::npos){
//Rule : if
"cei" exits in input[i] then goes follows_rule
//Rule : if "ei"
exits in input[i] then goes violates_rule
if(input[i][ei-1]=='c'){
follows_rule.push_back(input[i]);
}else{
violates_rule.push_back(input[i]);
}
}else{
//"ei","ie" not
exists then goes to inapplicable_rule
inapplicable_rule.push_back(input[i]);
}
}
//print vector
for(int i=0;i<follows_rule.size();i++){
cout<<follows_rule[i]<<" ";
}
cout<<endl;
for(int i=0;i<violates_rule.size();i++){
cout<<violates_rule[i]<<" ";
}
cout<<endl;
for(int i=0;i<inapplicable_rule.size();i++){
cout<<inapplicable_rule[i]<<" ";
}
cout<<endl;
}
int main(){
//Initializing vectors
Words input =
{"happy","achieve","ceiling","beige","species","eight","ei","ie","cie","cei","thei","thie","thcie","thcei","ten"};
Words
follows_rule,violates_rule,inapplicable_rule;
sort_i_before_e(input,follows_rule,violates_rule,inapplicable_rule);
}
C++ Language: TestCase: Write a function, called "sort Lbefore e that can sort words into whether or not they conf...
C++ Language, Only the sort_i_before_e func, not included main. Also, plz look at the instructions. use vector. Write a function, called "sort Lbefore e that can sort words into whether or not they conform to the 1 beforee, except after c rule, See htrps//en.oxtorddictionaries.com/spelling/-before-e-except-after-cl. This function takes 4 references to vectors of strings as parameters . The first vector is the input consisting of lowercase words (only alphabetic charactersl. The next vector should be filled with words that follow the...
C++ Language: Do not use namespace Test Case: 3-D vectors Write a templated function, called "add 3d", that can add two const references to 3-d vectors [vector<vector-vector<T>>>]. It should return a new 3-d vector that performed element-wise addition. You cannot use indexing on this problem, instead you must use iterators to access the values of end vector. INPUT OF THE TEST CASE 1 #include <vector> 2 using std: : vector; 3 const vector<double> a{1, 4, -6}; const vector<double> b{3, 6,...
Write a French/English dictionary lookup program. Read a list of pairs of English and French words from a file specified by the user. English/French words should be exact matches (don't try to find partial matches). Use the supplied EnglishFrenchDictionary.java class as your main class. Fill in the missing code in the DictionaryTable.java class to read the input file and perform the searches. Add code to the DictionaryTable read() method to: read pairs of lines (English word is on the first...