Question: I'm studying intermediate programming about c++ and Cstrings, and I have an assignment question that I want to do. this one.. Write a program that
I'm studying intermediate programming about c++ and Cstrings, and I have an assignment question that I want to do.
this one..
Write a program that inputs two string variables, first and last, each of which the user should enter with his or her name. First, convert both strings to all lowercase. Your program should then create a new string that contains the full name in pig latin with the first letter capitalized for the first and last name. The rules to convert a word into pig latin are as follows:
-
If the first letter is a consonant, move it to the end and add ay to the end.
-
If the first letter is a vowel, add way to the end.
For example, if the user inputs Erin for the first name and Jones for the last name, then the program should create a new string with the text Erinway Onesjay and print it.
And I'm facing a problem that is I'm trying to use strcat to add "way" and "ay" to the arrays but it's not working it keeps saying I add an s (strcat_s) but when I do it also doesn't work it says "E0304 no instance of overloaded function "strcat_s" matches the argument list" .. What do I do to fix it? and how can I modify the code to satisfy the question? I'm panicking it's due midnight please help me and also please don't use complicated new stuff because I only want to stick to the basics I know for now. Here is my code:
#include
void GET(char Name1[], char Name2[], int size) { char name1, name2; cout << "enter first name" << endl; int i = 0; cin.get(name1);
while (name1 != ' ') { if (i < size) { Name1[i] = name1; i++; } cin.get(name1); } Name1[i] = '\0';
cout << "enter second name" << endl; i = 0; cin.get(name2);
while (name2 != ' ') { if (i < size) { Name2[i] = name2; i++; } cin.get(name2); } Name2[i] = '\0';
// to convert now.. char vowels[10] = { 'a','o','u','i','e','E','A','O','U','I' }; int x; for (int i = 0; i < size; i++) { for (int j = 0; j < 10; j++) { if ((Name1[0] == vowels[j])) { strcat_s(Name1, "way"); } else if ((Name2[0] == vowels[j])) { strcat(Name2, "way"); } else if((Name1[0]!=vowels[j])) { x = strlen(Name1); for (int k = 0; k < x; k++) { Name1[k] = Name1[k + 1]; } strcat(Name1, "ay"); } else { x = strlen(Name2); for (int k = 0; k < x; k++) { Name2[k] = Name2[k + 1];
} strcat(Name2, "ay"); } } } }
int main() { int const size = 6; char Name1[size]; char Name2[size]; cout << "Please enter your first and last name" << endl; GET(Name1, Name2, size);
cout << "The edited version is: " << endl; for (int i = 0; i < size; i++) { cout << Name1[i]; } cout << " "; for (int j = 0; j < size; j++) { cout << Name2[j]; }
return 0; system("pause"); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
