Question

In: Computer Science

Using Ruby. Create a program that prompt the users for his full name For example: Brian...

Using Ruby. Create a program that prompt the users for his full name

For example: Brian Smith

You code should swap the first name to last and last name to first and display the result.

Smith Brian

Your code should run for any combination of first name and last name.

Hint: Research around String class methods in Ruby. The separator is the space in between first and last name.

Please submit your code, as well as screenshot of how your code ran in the console.

Solutions

Expert Solution

Code:

print "Enter your Full Name : " #asking user to enter the full Name

$full_name=STDIN.gets #taking user full name as input from user

$full_name=$full_name.strip #used for removing \n after entering name hitting enter takes \n as character

$final_name=$full_name.split(" ") #split the given name by using delimiter " "

puts $final_name[1] + " " + $final_name[0] #concatenate first index value with zeroth index value

Code and Outputs Screenshots:

Note: In program we are using strip function. the main operation of strip function is removing trailing spaces or tabs or new lines as well as ending spaces and tabs and new lines.Here in this program after entering the input we are hitting Enter button so the enter button (\n) is considering as input character and stores that into $full_name variable.

Here we are removing that last \n using strip function.

Note : if you have any queries please post a comment thanks a lot..always available to help you...


Related Solutions

Ruby programming Create a Ruby program which reads numbers, deposits them into an array and then...
Ruby programming Create a Ruby program which reads numbers, deposits them into an array and then calculates the arithmetic mean (otherwise known as the average), the median (that is, the number that splits the set of value in half with half being above and half being below the number), and the standard deviation (that is, the average of distance each number is from the mean then squared). Further information about these calculations can be found here: average: http://en.wikipedia.org/wiki/Average (add up...
Create a program using python that provides a simple calculator: Requires a login with a prompt...
Create a program using python that provides a simple calculator: Requires a login with a prompt for a username and a password prior to using the calculator If username and password are incorrect, the program should re-prompt to re-enter correct username and password Once logged in, the user should have access to the calculator and should have the ability for the following mathematical operators: Addition Subtraction Multiplication Division Square Root PI Exponents
Write a C program that performs the following: Asks the user to enter his full name...
Write a C program that performs the following: Asks the user to enter his full name as one entry. Asks the user to enter his older brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have any older brother). Asks the user to enter his younger brothers’ names each at a time (the user should be instructed by the program to enter NULL if he does not have...
Create a Linear Program solver using Matlab or Python. Prompt variable and constraint entry.
Create a Linear Program solver using Matlab or Python. Prompt variable and constraint entry.
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
Create a new file name condition_quiz.py. Add a comment with your name and the date. Prompt...
Create a new file name condition_quiz.py. Add a comment with your name and the date. Prompt the user to enter the cost. Convert the input to a float. Prompt the user for a status. Convert the status to an integer Compute the special_fee based on the status. If the status is 0, the special_fee will be 0.03 of the cost. Else if the status is 1, the special_fee will be 0.04 of the cost. Else if the status is 2,...
Python Code: Write a program to prompt the user to enter a first name, last name,...
Python Code: Write a program to prompt the user to enter a first name, last name, student ID, number of hours completed and GPA for 5 students. Use a loop to accept the data listed below. Save the records in a text file. Write a second program that reads the records from your new text file, then determines if the student qualifies for Dean’s list or probation. Display the records read from the file on screen with appropriate headings above...
create flowchart using Flowgorithm and Pseudocode for the following program example:   Design a program for Jones...
create flowchart using Flowgorithm and Pseudocode for the following program example:   Design a program for Jones College. The current tuition is $12,000 per year, and tuition is expected to increase by 5 percent each year. Display the tuition amount for each year over the next five years (use a looping structure).
Write a program to store record of 15 Facebook users using Dictionary data type. Actual name...
Write a program to store record of 15 Facebook users using Dictionary data type. Actual name record should hold username, number of friends, place, date of birth and the date their account was created. https://realpython.com/python-lists-tuples/ https://realpython.com/python-dicts/
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT