Just a quick question.
I am working through assignments from 2009 to prepare for this year and I have a question about Assignment 3 Question 1.
Question 1
Write a program that inputs two C string variables, first and last, each of which the user should enter with his or her name. First, convert both C strings to lowercase. Your program should then create a new C 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.
I prepared my solution and then looked at the solution in the tutorial letter. There are striking differences but both have the same results. Could someone please look and tell me if mine would be acceptable?
Language: C++
/*************************************************************
* Exam practice - Assignment 3 Semester 2
* Question 1 - Pig Latin name transformation
*
*************************************************************/
#include <iostream>
#include <string>
using namespace std;
//===============================================================
//Global Constants
//===============================================================
//===============================================================
//Function Prototypes
//===============================================================
void pigLatin(string&);
// Main function
int main()
{
string name, namecopy, surname, surnamecopy, fullname;
cout<<"Enter your first name: ";
cin>>name;
namecopy = name;
cout<<"Enter your last name: ";
cin>>surname;
surnamecopy = surname;
transform(name.begin(), name.end(),name.begin(), ::tolower);
transform(surname.begin(), surname.end(),surname.begin(), ::tolower);
pigLatin(name);
pigLatin(surname);
cout<<namecopy<<" "<<surnamecopy<<" your name in Pig Latin is: "<<name<<" "<<surname<<endl;
system("pause");
return 0;
} // Main function
//===============================================================
//Function Definitions
//===============================================================
void pigLatin(string& textSource)
{
if (( textSource[0] == ';a';)||( textSource[0] == ';e';)||( textSource[0] == ';i';)||( textSource[0] == ';o';)||( textSource[0] == ';u';))
{
textSource[0] = toupper(textSource[0]);
textSource = textSource+"way";
}
else
{
char ch = textSource[0];
textSource.erase(0,1);
textSource[0] = toupper(textSource[0]);
textSource = textSource+ch+"ay";
}
}
Chris Botha
=============================
Far and away the best prize that life has to offer is the chance to work hard at work worth doing.
Theodore Roosevelt