123k views
1 vote
create a c (.cpp) program to perform the following 2 tasks: 1. (5 points) ask the user for their first name (store it as a string), then separately ask the user to enter their last name (store it as a string). combine the 2 strings into 1 result string then print the resulting string and also the length of the result string. remember to include a space between the first and last names. note: you can use the string type defined in c header file string (

User Ogie
by
7.1k points

1 Answer

3 votes

Answer:

#include <iostream>

#include <string>

int main() {

std::string firstName, lastName, result;

std::cout << "Enter your first name: ";

std::cin >> firstName;

std::cout << "Enter your last name: ";

std::cin >> lastName;

result = firstName + " " + lastName;

std::cout << "Full name: " << result << std::endl;

std::cout << "Length of the full name: " << result.length() << std::endl;

return 0;

}

Hope this helps!

User Ellery
by
5.8k points