//strings Cstring concatenation // This program asks for the user’s first, middl
ID: 3778482 • Letter: #
Question
//strings Cstring concatenation
// This program asks for the user’s first, middle, and last names.
//The names are stored in three different character arrays.
//The program then stores, in a fourth array, the name arranged as "lastname, firstname middlename" .
//For example, if the user entered “Teko" "Jan" "Bekkering”, it should store “Bekkering, Teko Jan” in the fourth array.
//Display the contents of the fourth array on the screen. Use string functions, not just the + operator.
/*
Enter the first name: Teko
Enter the middle name: Jan
Enter the last name: Bekkering
Bekkering, Teko Jan
Press any key to continue . . .
*/
#include <iostream>
using namespace std;
const int SIZE = 31;
const int FULLSIZE = 94;
int main()
{
char first[SIZE];
char middle[SIZE];
char last[SIZE];
char full[FULLSIZE];
cout << " Enter the first name: ";
cout << " Enter the middle name: ";
cout << " Enter the last name: ";
cout << ????? << endl;
return 0;
}
Explanation / Answer
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
const int SIZE = 31;
const int FULLSIZE = 94;
int main()
{
char first[SIZE];
char middle[SIZE];
char last[SIZE];
char full[FULLSIZE];
cout << "Enter the first name: ";
cin >> first;
cout << " Enter the middle name: ";
cin >> middle;
cout << " Enter the last name: ";
cin >> last;
cout << first << " " << middle << " "<< last<< endl;
strcpy (full,last);
strcat (full," ");
strcat (full,first);
strcat (full," ");
strcat (full,middle);
cout << full << endl;
cout << "?????" << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.