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
Identify the four basic categories of hardware in a personal computer system
Pie
The four basic categories are the motherboard, the CPU, the graphics card, and the RAM.
Brainliest pls! thx! :)
5 0
2 years ago
How does form get its power natural gas
lana [24]

Answer:

because it does

Explanation:

7 0
3 years ago
A company operates on two types of servers: 2 large servers (L) and 4 smaller servers (S), with a combined total of 64GB RAM. Th
kati45 [8]

Explanation:

Let the size of a large server be L, and

the size of a small server be S.

We are given two scenarios,

2L+4S = 64.............(1)

and

L+3S = 40...............(2)

We solve the equations as follows

2(2)-(1)

2L-2L +6S-4S = 2*40-64

2S = 16

so S=8 ..................(3), size of small server

substitute (3) in (2)

L+3(8) =40

L = 40-24 = 16..............size of large server

8 0
3 years ago
A ____ resembles a circle of computers that communicate with each other.
Sidana [21]

Answer:

ring network

Explanation:

In a ring network, the nodes are arranged in a circular pattern where each node is connected to two adjacent nodes. In this topology, any node can communicate with any other node via the intermediaries.

In comparison,

- in a star network every communication needs to pass through a central hub node

- in a bus, each node is connected to a shared linear communication bus.

- in a hierarchical network nodes are organized along a tree structure layout.

4 0
3 years ago
Will robots take people's jobs? <br> write in complete sentence.
lilavasa [31]

Answer:

yes

Explanation:

yes because they already have them for old gun ships (which they still use) and they have made cars with them and more including bombing situations IED detinators they used in Afghanistan and in Iraq in 2011.

6 0
3 years ago
Other questions:
  • Samantha writes technical content for a webpage and uploads it to the webpage. What should she do to ensure that the content, wh
    11·2 answers
  • Directions for starting the computer and opening a word processor document
    5·1 answer
  • Interactive sites where users write personal topics and comments to a threadded discussion are called?
    11·1 answer
  • What is runtime error in Python? Provide an example
    14·1 answer
  • #11. Write a program that prompts the user to input a four-digit positive integer. The program then outputs the digits of the nu
    6·1 answer
  • How to get the home button on your screen?
    13·1 answer
  • You are given a 5-letter word (for example, abcde). Write a C-Program which outputs all possible unique 5 letter permutations of
    13·1 answer
  • Which function would you use to make sure all names are prepared for a mailing label? TODAY UPPER PROPER LOWER
    11·1 answer
  • If anyone gotta ps4, i'm a 15 yr old female n if u wanna b frens, hmu :))
    8·2 answers
  • Describe the plot of the Matrix
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!