1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
docker41 [41]
2 years ago
7

Write a program that asks for the user's first, middle, and last name as one input. The names must 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 first initial of the middle name and a period. Display the contents of the fourth array on the screen. No standard strings can be used. Oh I'm so mean.
Sample input:
Neil Patrick Harris
Output:
Harris, Neil P.

Computers and Technology
1 answer:
nydimaria [60]2 years ago
8 0

Answer:

Here is the C++ program:

#include <iostream>  //to use input output functions  

#include <cstring>  // used to manipulate c strings  

using namespace std;  //to identify objects cin cout

const int SIZE = 20;  //fixes constant size for firstName, middleName and lastName arrays  

const int FULL_SIZE = 60;  //constant size for fullName array  

int main() {  //start of main method  

 char firstName[SIZE]; //declares a char type array to hold first name  

 char middleName[SIZE];//declares a char type array to hold middle name  

 char lastName[SIZE]; //declares a char type array to hold last name  

 char fullName[FULL_SIZE]; //declares a char type array to hold full name

 cout << "Enter first, middle, and last name:  ";  //prompts user to enter first name

 cin>>firstName>>middleName>>lastName;  //reads last name from user, stores it in lastName array

 strcpy(fullName, lastName);  //copies last name from lastName to fullName array using strcpy method which copies a character string from source to destination

 strcat(fullName, ", "); //appends comma "," and empty space " " after last name in fullName using strcat method which appends a string at the end of another string

 strcat(fullName, firstName);  //appends first name stored in firstName to the last of fullName

 strcat(fullName, " ");  //appends an empty space to fullName

  char temp[2];  //creates a temporary array to hold first initial of middle name

temp[0] = middleName[0];  //holds the first initial of middle name

strcat(fullName, temp);  //appends first initial of middle name stored in temp to the last of fullName

strcat(fullName, ".");   //appends period

    cout<<fullName;  } //displays full name

Explanation:

I will explain the program with an example

Lets say user enters Neil as first name, Patrick as middle and Harris as last name. So firstName char array contains Neil, middleName char array contains Patrick and lastName char array contains Harris.  

Next the fullName array is declared to store Neil Patrick Harris in a specific format:

strcpy(fullName, lastName);

This copies lastName to fullName which means fullName now contains Harris.

 strcat(fullName, ", ");

This appends comma and an empty space to fullName which means fullName now contains Harris with a comma and empty space i.e. Harris,

strcat(fullName, firstName);

This appends firstName to fullName which means Neil is appended to fullName which now contains Harris, Neil

 strcat(fullName, " ");  

This appends an empty space to fullName which means fullName now contains Harris, Neil with an empty space i.e. Harris, Neil

char temp[2];

temp[0] = middleName[0];

This creates an array to hold the first initial of middle name i.e. P of Patrick

strcat(fullName, temp);

This appends an the first initial of middleName to fullName which means fullName now contains Harris, Neil P

strcat(fullName, ".");

This appends a period to fullName which means fullName now contains Harris, Neil P.

Now    cout <<"Full name is:\n"<<fullName<< endl; prints the fullName so the output of this entire program is:

Full name is:                                                                                                                                  Harris, Neil P.

The screenshot of the program along with its output is attached.

You might be interested in
How i can download play store?​
Phantasy [73]

Answer:

in Google type play Store and you will get the app and then click on that word install and it will get installed

Explanation:

hope this helps

3 0
3 years ago
Consider the scenario below and determine the most likely source of the problem. A user reports that her or his printer is not r
Lina20 [59]
The answer would be D.

4 0
2 years ago
Read 2 more answers
In a relational database, the three basic operations used to develop useful sets of data are:
lesya692 [45]
<span>Which is not a component of a database that describes how data is stored?</span>
6 0
3 years ago
Constructive criticism is intended as a possible solution.
wlad13 [49]

Answer:

True

Explanation:

Constructive criticism is a comment that cuts down on someone, but in an influencing way.

Example: Let's ask him to be more careful the next time he buys fish.

7 0
2 years ago
A cell reference with only one dollar sign before either the column or the row is called an absolute reference.
BlackZzzverrR [31]
False, absolute references have two dollar signs
4 0
3 years ago
Other questions:
  • "What line of code can be used to provide a convenient way to merge the source code from one file with the source code in anothe
    8·1 answer
  • HELP!!! Bad things about Helen Keller. I'm doing a debate and i need to prove that Steve Jobs is better than Helen Keller!!
    14·1 answer
  • If you used a peach as a model of an animal cell, what would the peach's skin represent? A.nucleus B.cell wall C.cytoplasm D.cel
    10·2 answers
  • All of the following are helpful tips for protecting your digital privacy, except:
    10·2 answers
  • Write a function that takes as input a single integer parameter n and computes the nth Fibonacci Sequence number. The Fibonacci
    8·1 answer
  • If you misspell a word in your Java program it may be true that I. the program will not compile II. the program may compile, but
    6·1 answer
  • We have constructed a Player Class for you. Add the following: public static variable: int totalPlayers Static variable should b
    8·1 answer
  • In disc brakes, pads are forced against the of a brake disc​
    14·1 answer
  • The bullet points above describe _____.
    7·1 answer
  • Which example illustrates the idea of "collecting data"?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!