QuestionQuestion

1. The following is a code snippet which reads in a string from the console. Explain the difference in behavior between using the extraction operator “>>” and using the getline function.
string buffer;
cin >> buffer;
getline(cin, buffer);

2. Besides the difference in syntax, summarize the difference between a C style string and a C++ style string.

3. Write a user defined function named trimRight which takes a string as an input and returns back a modified string where all trailing spaces (spaces after the last text) are removed. For example, the string “hello world    “ would become “hello world”.

4. Write a user defined function named isPalindrome program accepts a string as an input and returns true if the word is a palindrome, and false if it is not. A palindrome is a word which when the letters are reversed remains the same. For instance the word “level” is a palindrome while “leveled” is not.

5. (Upload as Source) When a new customer’s information is entered into a computer program the information should be verified to be of an appropriate format. For instance a zip code should be all numerical digits and of length five. Write a user defined function which accepts a social security number in the form of a string and returns true with the number is valid, otherwise return false.

Verify the following:
• The phone number is of length 11
• If is of the format ###-##-#### where a # is a numerical digit
o Detect if a dash is not present
o Detect that a numerical digit is present in all the locations that have a #
Finally, write a main() function which prompts the user to enter in a social security number, calls the function created above and prints to the console the validity of the number.

6. (Upload as Source) Often times multiple pieces of data comes from the user at once and requires parsing to separate the pieces of data for later use. Write a program which uses getline exclusively to fetch two address lines from the user. The first line is the address number and street name, and the second line is the town, state, and zipcode information. Example is shown below:
####   street name
town_name,   state_abbreviation zipcode
i.e.
1230 Lincoln Drive
Carbondale, IL 62901

Separate the two input strings into separate pieces of data for the address number, street name, town name, state abbreviation and zip code. Then display the separated pieces of data to the console. As shown in the image below.

Parsing considerations
• The address number is only a single number with multiple digits which will always be the item on the string
• The street name maybe multiple words such as Martin Luther Drive
• Town name maybe multiple words such as New York City but will always have a comma after it
• State abbreviation is always two letters followed by a space
• You may assume only a single space between each item
Use C++ style strings and their methods to solve the problem.

Bonus Opportunity:
Detect Incorrect Format on the Second Line. This includes the absence of a comma after the town name, a state abbreviation that is not two characters in length, and a zip code that is not 5 digits in length, and a zip code that is not all digits.
Allow for the parsing to be space insensitive for both lines. In other words, assume multiple spaces can be between each item.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

1.

cin >> buffer; // get input character from keyboard until a space or a new line character is entered
getline(cin, buffer); // get input character from keyboard until a new line character is entered...
$60.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Visual Basic Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats