Advertisement
chevengur

Chapter 6: excercise 6

Aug 24th, 2023 (edited)
385
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 1 0
  1. #include "std_lib_facilities.h"
  2.  
  3. // Chapter 6 Exercise 6
  4.  
  5. /*
  6.     English grammar
  7. */
  8.  
  9. bool is_noun(string str){
  10.     vector<string>noun{"birds", "fish", "C++"};
  11.    
  12.     for (auto i = 0; i < noun.size(); ++i) {
  13.         if (str == noun[i])
  14.             return true;
  15.     }
  16.     return false;
  17.    
  18. }
  19.  
  20. bool is_verbs(string str) {
  21.     vector<string>verbs{"rules", "fly", "swim"};
  22.     for (auto i = 0; i < verbs.size(); ++i) {
  23.         if (str == verbs[i])
  24.             return true;
  25.     }
  26.     return false;
  27. }
  28.  
  29. bool is_conjuction(string str) {
  30.     vector<string>conjuction{"but", "or", "and"};
  31.     for (auto i = 0; i < conjuction.size(); ++i) {
  32.         if (str == conjuction[i])
  33.             return true;
  34.     }
  35.     return false;
  36. }
  37.  
  38. bool is_pretex(string str) {
  39.     vector<string>pretex{"the"};
  40.     for (auto i = 0; i < pretex.size(); ++i) {
  41.         if (str == pretex[i])
  42.             return true;
  43.     }
  44.     return false;
  45. }
  46.  
  47. bool is_point(string str) {
  48.     string poin = "."s;
  49.     if (str == poin) {
  50.         return true;
  51.     }
  52.     return false;
  53. }
  54.  
  55. bool senteces() {
  56.     string pr, no, verb, conj, pr1, no1, verb1, t4k;
  57.     cin >> pr >> no >> verb >> conj >> pr1 >> no1 >> verb1 >> t4k;
  58.  
  59.  
  60.     if (!is_pretex(pr))
  61.         return false;
  62.  
  63.     if (!is_noun(no))
  64.         return false;
  65.  
  66.     if (!is_verbs(verb))
  67.         return false;
  68.  
  69.     if (!is_conjuction(conj))
  70.         return false;
  71.  
  72.     if (!is_pretex(pr1))
  73.         return false;
  74.  
  75.     if (!is_noun(no1))
  76.         return false;
  77.  
  78.     if (!is_verbs(verb1))
  79.         return false;
  80.  
  81.     if (is_point(t4k))
  82.         return true;
  83. }
  84.  
  85. int main() {
  86.     bool a = senteces();
  87.     if (a) {
  88.         std::cout << "OK";
  89.     }
  90.     else
  91.         std::cout << "ERROR";
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement