Question

In C++, what is the easiest way to have a program ask for first, middle and...

In C++, what is the easiest way to have a program ask for first, middle and last name; Then, later print in the following format: 'Last name', 'First Name' 'middle initial'. ? I am currently creating a program that is separated into three files (.h, .cpp & main), and so this task seems more complicated when trying to figure out what part goes where. Thanks for your help in advance!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

int main() {
        string first, mid, last;
        
        cout << "Enter first name: ";
        cin >> first;
        cout << "Enter middle name: ";
        cin >> mid;
        cout << "Enter last name: ";
        cin >> last;

        cout << last << ", " << mid << " " << first << endl;
}

this is the very simple and easy code i have given for your requirement.. This do not require a separate header and .cpp file, because those are required for a external module. In this case, there is no external module.. Just a piece of code for input/output.

Add a comment
Know the answer?
Add Answer to:
In C++, what is the easiest way to have a program ask for first, middle and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • create a C++ program which reads in a Social Security number, a first name, a middle...

    create a C++ program which reads in a Social Security number, a first name, a middle name or initial, and a last name from the file inData.dat. The name is written to file outData.dat in three different formats: Format 1: First name, middle name, last name, and Social Security number Format 2: Last name, first name, middle name, and Social Security number Format 3: Last name, first name, middle initial, and Social Security number Format 4: Last name, middle initial, last name Note: The...

  • PYTHON CODING Create a program that prompts the user twice. The first prompt should ask for...

    PYTHON CODING Create a program that prompts the user twice. The first prompt should ask for the user's most challenging course at Wilmington University. The second prompt should ask for the user's second most challenging course. The red boxes indicate the input from the user. Your program should respond with two copies of an enthusiastic comment about both courses. Be sure to include the input provided by the user to display the message. There are many ways to display a...

  • This is subject of C++ Your program should read the file answers.dat. This file contains the...

    This is subject of C++ Your program should read the file answers.dat. This file contains the name of the student who took the quiz, and his answers for each question. The answers file has the following format: The student name is always the first line. A student name may or may not have last names. For example, both Elvis Presley and Cher took this class. A quiz always has 11 questions. There is one answer per line. Each answer is...

  • Write a simple telephone directory program in C++ that looks up phone numbers in a file...

    Write a simple telephone directory program in C++ that looks up phone numbers in a file containing a list of names and phone numbers. The user should be prompted to enter a first name and last name, and the program then outputs the corresponding number, or indicates that the name isn't in the directory. After each lookup, the program should ask the user whether they want to look up another number, and then either repeat the process or exit the...

  • I need help writing c++ code to make this program. 1. Define a function that can...

    I need help writing c++ code to make this program. 1. Define a function that can read the input file answers.dat. This function should not print anything. 2. Define a function that computes the quiz score of the function by comparing the correct answers to the student’s answer. The result should be a percentage between 0 and 100, not a value between 0 and 1. This function should not print anything. 3. Define a function that prints the report as...

  • in c++ please Write a program in c+ to do the following: 1.Save the data shown...

    in c++ please Write a program in c+ to do the following: 1.Save the data shown below (in the same format) to make a text file called "InputData. txt"; use the file as input to enter data into a hash table. Fname Lname 2019-01-31 First Last 2018-02-01 Jonh Doe 2017-03-28 Jane Doe 2016-04-01 as the data items in the file 2. Your hash table should have as many entries 3. The birthday should be used as the hash key by...

  • I need a C++ program like this please! and please follow all instructions! Thanks so much!...

    I need a C++ program like this please! and please follow all instructions! Thanks so much! A menu-driven program with 3 choices: Names Rearranger, Number Validator, or Exit Menu Option 1: Name Rearranger: 1. Input ONE STRING from the user containing first name, middle name, and last name. ie, "John Allen Smith". USE THE GETLINE function. (Not cin) 2. Loop through the string and validate for a-z or A-Z or . If the name has any other characters, then ask...

  • Please Help, I will rate either way because of the effort. Description: help in c++, this...

    Please Help, I will rate either way because of the effort. Description: help in c++, this program should have 3 files GuessWho.cpp, Person.cpp, Person.h This program will be a Guess Who game. The program should Read the first line of people.txt, Use the contents to set the members of your Person object, Print the Guess Who People heading, Print the Person that you read earlier Prompt the user for a feature (name, haircolor, hairtype, gender, glasses, eyecolor, or hat) Print...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called...

    Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT