Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me out to write C/C++ program for the each of following two question

ID: 3804373 • Letter: P

Question

Please help me out to write C/C++ program for the each of following two questions.

Problem Write a program that prompts the user to enter a word. Convert the word to Pig Latin by moving the first letter to the end of the word and adding "ay" to the end. For example, Tuesday becomes uesdayTay. Repeat this process until the user types STOP. Problem 2 When a C program is executed, the main function is called with two arguments, arga and argv. The first, argc, is the number of command-line arguments the program was called with. The second, argv, is a pointer to an array of strings that contain the arguments. This mechanism provides a way to start a program and pass it arguments directly from the command line. As an example, the following program prints whatever arguments are on the command line when the program is executed. include

Explanation / Answer

Problem 1: C++ code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
   while(true)
   {
       string word;
       cout << "Enter a word" << endl;
       cin >> word;
       if(word != "STOP")
       {
           int len = word.length();
       char newword[len+2];

           for (int i = 1; i < len; ++i)
           {
               newword[i-1] = word[i];
           }
           newword[len - 1 ] = word[0];
           newword[len] = 'a';   newword[len + 1] = 'y';
           cout << "Pig Latin representation: " << newword << endl;
       }
       else
       {
           exit(0);
       }
   }
   return 0;
}

Sample Output:

C:UsersAkashDesktopcheggc++ io>a
Enter a word
akash
Pig Latin representation: kashaay
Enter a word
Tuesday
Pig Latin representation: uesdayTay
Enter a word

STOP

Problem 2:C++ code:

#include <bits/stdc++.h>
using namespace std;

int main(int argc, char *argv[])
{

       if(argc == 2)
       {
           string word;
           word = argv[1];
           int len = word.length();
       char newword[len+2];

           for (int i = 1; i < len; ++i)
           {
               newword[i-1] = word[i];
           }
           newword[len - 1 ] = word[0];
           newword[len] = 'a';   newword[len + 1] = 'y';
           cout << "Pig Latin representation: " << newword <<endl;

       }
       else if(argc == 3)
       {
           string word;
           word = argv[1];
           int len = word.length();
       char newword[len+2];

           for (int i = 1; i < len; ++i)
           {
               newword[i-1] = word[i];
           }
           newword[len - 1 ] = word[0];
           newword[len] = 'u';   newword[len + 1] = 'h';
           cout << "Pig Latin representation: " << newword <<endl;
       }
       else
       {
           cout << "You must enter 1-2 arguments! ";
       }
   return 0;
}

Sample Output:

C:UsersAkashDesktopcheggc++ io>a
You must enter 1-2 arguments!

C:UsersAkashDesktopcheggc++ io>a akash
Pig Latin representation: kashaay

C:UsersAkashDesktopcheggc++ io>a akash Q
Pig Latin representation: kashauh