Write a
lastName, firstName Middle_Initial.
For example, the input
Mary Average User
should produce the output:
User, Mary A.
The input
Mary A. User
should also produce the output:
User, Mary A.
Your program should work the same and place a period after the middle initial even if the input did not contain a period. Your program should allow for users who give no middle name or middle initial. In that case, the output, of course, contains no middle name or initial. For example, the input
Mary User
should produce the output
User, Mary
If you are using C strings, assume that each name is at most 20 characters long. Alternatively, use the class string.
(Hint: You may want to use three string variables rather than one large string variable for the input. You may find it easier to not use getline.)
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Experiencing MIS
Database Concepts (8th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Artificial Intelligence: A Modern Approach
Introduction to Programming Using Visual Basic (10th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- (Modify) a. Modify the program you wrote for Exercise 7 to provide the mass of a person as an output, given his or her weight as an input to the program. Use your program to determine the mass of a person who weighs 140 lbf on Earth. b. Modify the program written for Exercise 7a to also output the person’s weight on Mars and the moon. The pull of gravity on Mars is 12.54ft/sec2=3.728m/s2,andonthemoonis5.33ft/sec2=1.625m/s2.arrow_forward(Program) Write a program to simulate the rolling of two dice. If the total of the two dice is 7 or 11, you win; otherwise, you lose. Embellish this program as much as you like with betting, different odds, different combinations for win or lose, stopping play when you have no money left or reach the house limit, displaying the dice, and so forth. (Hint: Calculate the dots showing on each die with theexpressiondots=(int)(6.0randomnumber+1), where random number is between 0 and 1.)arrow_forwardWrite a program that reads student scores, gets the best score, andthen assigns grades based on the following scheme:Grade is A if score is ≥ best -5Grade is B if score is ≥best -10;Grade is C if score is ≥best -15;Grade is D if score is ≥best -20;Grade is F otherwise.The program prompts the user to enter the total number of students, and thenprompts the user to enter all of the scores, and concludes by displaying the grades.Here is a sample run: Enter the number of students: 4 ↵EnterEnter 4 scores: 40 55 70 58 ↵EnterStudent 0 score is 40 and grade is FStudent 1 score is 55 and grade is CStudent 2 score is 70 and grade is AStudent 3 score is 58 and grade is Carrow_forward
- Many documents use a specific format for a person's name. Write a program that reads a person's name in the following format: firstName middleName lastName (in one line) and outputs the person's name in the following format: lastName, firstInitial.middleInitial. Ex: If the input is: Pat Silly Doe the output is: Doe, P.S. If the input has the following format: firstName lastName (in one line) the output is: lastName, firstInitial. Ex: If the input is: Julia Clark the output is: Clark, J.arrow_forward24. Write a program which asks the user for an integer number and prints out whether the input number is a multiple of 7. A. Example 1 i. Input: • ii. Output: B. Example 2 i. Input: Please enter number: 9 ii. Output: Number is not a multiple of seven 25. Write a program which asks the user for two integer numbers (say N1 and N2) and prints out whether the input number NI is a multiple of N2. A. Example 1 i. Input: • B. Example 2 ii. Output: • i. Input: A. Example Please enter number: 49 Number is a multiple of seven i. Input: ii. Output: Number 40 is not a multiple of 3 26. Write a program which asks the user for an integer number and prints out whether the input number is even or odd. Please enter first number: 49 Please enter second number: 7 Number 49 is a multiple of 7 Please enter first number: 40 Please enter second number: 3 • Please enter number: 42 i. Input ii. Output: Number is even 27. Write a program that asks the user for an integer number and prints a pattern. A. Example…arrow_forwardWrite a program that reads student scores, gets the best score, and hence assigns grades based on the following scheme: Grade is A if score is > = best - 10; Grade is B if score is > = best - 20; Grade is C if score is > = best - 30; Grade is D if score is > = best - 40; Grade is F otherwise. The program prompts the user to enter the total number of students, then prompts the user to enter all of the scores, and concludes by displaying the grades. Language: C++arrow_forward
- Given the sample code above in generating a random number. Create a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. 1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Don't display the computer's choice yet.) 2. The user enters his or her choice of "rock", "paper", or "scissors" at the keyboard. (You can use a menu if you prefer.) 13. The computer's choice is displayed. 4. A winner is selected according to the following rules: a. If one player chooses rock and the other player chooses scissors, then rock wins. (The rock smashes the scissors.) b. If one player chooses scissors and the other player chooses paper, then scissor wins. (Scissors cuts paper.) c. If one player chooses paper and the other player…arrow_forward1. Write a pyrhon program that prints out a classic hangman stick figure. The program should ask the user to enter a number from 1-6 and the corresponding hangman should be printed. The value the user inputs corresponds to the number of incorrect guesses in a real hangman game and so the completeness of the hangman will correspond to the number of ‘incorrect guesses’ inputted by the user (e.g., if the user enters 1, then only the head of the hangman will be printed; full example below). Example:Enter a number from 1-6: 1O Enter a number from 1-6: 2O|Enter a number from 1-6: 3O\||Enter a number from 1-6: 4O\|/|Enter a number from 1-6: 5O\|/|/Enter a number from 1-6: 6O\|/|/ \ 2. Modify your program from problem 1 so that the user input is checked to be a validsingle digit (1-6) before printing the corresponding hangman. If the input is not valid, theninstead of a hangman the following message should be printed “Invalid input: you must enter asingle number from 1-6.” Example:Enter a…arrow_forwardIN PYTHON Write a python that calculates the position of a car moving in a 2D-plane given the list of movements that should be executed in order. The movements are right, left, up, or down, followed by the number of units that the car has to move. The number of units can be either integer values or floating values but must be positive. If the input is invalid, then the program should print that there is an error and prompt the user to enter the input again. Note: The starting position of the car is x=0.0, and y=0.0.arrow_forward
- Write a program that reads from the user a character ('q' or 'c'). If the character is 'c', the program reads from the user the radius rof a circle and prints its area. • If the user enters 'q', the program asks the user to enter the length and width of a quadrilateral. We assume the quadrilateral is either a square or rectangle. You should print if the quadrilateral is square or rectangle. • Otherwise, it prints "Wrong character" PS: Use the following formulas: area of circle=3.14*r Sample Run1: Enter a character (q or c): q Enter the Length and Width: 80 150 |It is a rectangle Sample Run2: Enter a character (q or c): q Enter the Length and Width: 80 80 It is a square Sample Run3: Enter a character (q or c): c Enter the radius: 2 The area of the circle is 12.56 Sample Run4: Enter a character (q or c): d Wrong characterarrow_forwardWrite a program that reads from a student his/her name and his/her ID which is formed of 8 digits. The program should display the day of registration and the starting hour of registration according to the below tables. First 4 digits to the left Registration Day Monday Tuesday WEdnesday 2018 2019 2020 First digit to the right Registration IHour 4 6 10 7-8arrow_forwardComputer Science Java programarrow_forward
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr