Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.86 KB | None | 0 0
  1. //Olga Rún Kristjánsdóttir
  2. //2303892179
  3. //olgak10@ru.is
  4.  
  5. #include <iostream>
  6. #include <string>
  7. #include <vector>
  8.  
  9. using namespace std;
  10.  
  11. void make_lower (string& first, string& last)
  12. {
  13.  
  14.     for (int i = 0; i < first.length ();i++)
  15.     {
  16.         first [i] = tolower(first[i]);
  17.     }
  18.  
  19.     for (int j = 0; j< last.length ();j++)
  20.     {
  21.         last [j] = tolower(last [j]);
  22.     }
  23.  
  24.     first [0] = toupper(first [0]);
  25.     last [0] = toupper(last [0]);
  26.  
  27. }
  28.  
  29. void pig_latin_string (string& first, string& last, vector<char>& pig_first, vector<char>& pig_last)
  30. {
  31.     //vector <char> pig_first;
  32.     //vector <char>pig_last;
  33.  
  34.     char array_consonants [] = {'b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','z'};
  35.     char array_vowels [] = {'a','e','i','o','u','y'};
  36.  
  37.     for (int i = 0;i<21;i++)
  38.     {
  39.         if (first [0] == array_consonants [i])
  40.         {
  41.             for (int t = 1; t < first.length();t++)
  42.             {
  43.                 pig_first.push_back(first [t]);
  44.  
  45.             }
  46.             pig_first.push_back (first [0]);
  47.             pig_first.push_back ('a');
  48.             pig_first.push_back ('y');
  49.  
  50.         }
  51.  
  52.         if (last [0] == array_consonants [i])
  53.         {
  54.             for (int o = 1; o < last.length();o++)
  55.             {
  56.                 pig_last.push_back (last[o]);
  57.             }
  58.             pig_last.push_back (last [0]);
  59.             pig_last.push_back ('a');
  60.             pig_last.push_back ('y');
  61.  
  62.         }
  63.     }
  64.  
  65.     for (int j = 0; j<7; j++)
  66.     {
  67.         if (first [0] == array_vowels [j])
  68.         {
  69.             for (int z = 0;z<first.length (); z++)
  70.             {
  71.                 pig_first.push_back(first [z]);
  72.             }
  73.             pig_first.push_back ('w');
  74.             pig_first.push_back ('a');
  75.             pig_first.push_back ('y');
  76.         }
  77.  
  78.  
  79.         if (last [0] == array_vowels [j])
  80.         {
  81.             for (int u =0; u<last.length (); u++)
  82.             {
  83.                 pig_last.push_back (last[u]);
  84.             }
  85.             pig_last.push_back ('w');
  86.             pig_last.push_back ('a');
  87.             pig_last.push_back ('y');
  88.  
  89.         }
  90.     }
  91.  
  92.  
  93. }
  94.  
  95.     void print_results (vector<char>& pig_first, vector<char>& pig_last)
  96.     {
  97.         for (unsigned int f = 0; f <pig_first.size (); f++)
  98.         {
  99.             cout << pig_first[f];
  100.         }
  101.         cout << " ";
  102.  
  103.         for (unsigned int e = 0;e<pig_last.size();e++)
  104.         {
  105.             cout << pig_last [e];
  106.         }
  107.  
  108.     }
  109.  
  110.  
  111. int main()
  112. {
  113.     string firstname, lastname;
  114.  
  115.     vector <char> pig_first;
  116.     vector <char>pig_last;
  117.  
  118.     cout << "enter your first and last name" << endl;
  119.  
  120.     cin >> firstname >> lastname;
  121.  
  122.     make_lower (firstname, lastname);
  123.     pig_latin_string (firstname, lastname, pig_first, pig_last);
  124.     print_results (pig_first, pig_last);
  125.  
  126.     return 0;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement