Welcome! Log In Create A New Profile

Advanced

Exam Practice - Assignment 3 Question 1

Posted by core2000 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Exam Practice - Assignment 3 Question 1
May 09, 2010 04:16AM
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
avatar Re: Exam Practice - Assignment 3 Question 1
May 09, 2010 02:50PM
The question specifically states that you must input C-strings. That means that you are not allowed to use std::string. You must use char * or char[] instead.
Re: Exam Practice - Assignment 3 Question 1
May 09, 2010 02:53PM
Just goes to show what happens if you don't read the questions carefully.

Thanks

smile

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
Sorry, you do not have permission to post/reply in this forum.