Provide pseudocode for this program: Write a program that asks for the user\'s f
ID: 3545998 • Letter: P
Question
Provide pseudocode for this program:
Write a program that asks for the user's first, middle, and last names. The names should be stored in three different character arrays.The program should then store, in a fourth array, the name arranged in the following manner: the last name followed by a comma and a space, followed by the first name and a space, followed by the middle name.For example, if the user entered "Carol Lynn Smith", it should store "Smith, Carol Lynn" in the fourth array. Display the contents of the fourth array on the screen.
Explanation / Answer
In this program, to store the threee names in another array, we copy every character of the three arrays and store them in the new array, while adding commas and spaces. First I'll provide you the pseudo code.
Pseudo code:
begin program
input the three names in three arrays;
initialise fullname array;
add lastname array to the fullname array;
add comma and a space to the fullname array;
add firstname array to the fullname array;
add a space to the fullname array;
add middlename array to the fullname array;
print fullname array;
end program;
C++ code implementation:
#include<iostream>
using namespace std;
int main()
{
char firstname[30], middlename[30], lastname[30], fullname[100], yorn;
int i,k;
while(1)
{
cout<<"Enter your first, middle and last name : ";
cin>>firstname>>middlename>>lastname;
i=0;k=0;
while(lastname[i] != '')
{
fullname[k] = lastname[i];
k++;i++;
}
fullname[k] = ',';k++;
fullname[k] = ' ';k++;
i=0;
while(firstname[i] != '')
{
fullname[k] = firstname[i];
k++;i++;
}
fullname[k] = ' ';k++;
i=0;
while(middlename[i] != '')
{
fullname[k] = middlename[i];
k++;i++;
}
fullname[k] = '';
cout<<" Your name has been stored as "<<fullname<<" ";
cout<<"Want to try again (y or n) : ";
cin>>yorn;
if(yorn=='n' || yorn == 'N')
{
break;
}
}
return 0;
}
Hope, this solves your doubts. If you have any more doubts, just comment and I can help you further.
Cheers!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.