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]
3 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]3 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
Chức năng của hàm MOD(number, divisor)?
Kryger [21]

Answer:

MOD -> modulo, là phần dư, vì vậy hàm / phương thức MOD () xuất ra thương của số bằng số chia.

8 0
3 years ago
What is the difference between algorithm and program?
Dennis_Churaev [7]

Answer: The difference is that an algorithm is a precise step-by-step plan for a computational procedure that mainly begins with input value, yields, and output value. While a program is instructions written in code to explain to a computer what to do. Like how the CPU can send a command to the GPU to tell it what image to make. The better the CPU the better and faster it can read and complete it's given instructions.

Explanation: Trust me with this.

8 0
2 years ago
Each pixel includes 3 colors; Red, Green and Blue. Each color uses 8 bits to store it's intensity. How many Bytes are needed for
PtichkaEL [24]

Answer: 3 bytes

Explanation:

A Pixel uses 3 colors and each of these colors uses 8 bits to store their intensity.

One pixel will therefore have:

= 8 * 3

= 24 bits

1 byte = 8 bits

24 bits will therefore be:

= 24/8

= 3 bytes

6 0
3 years ago
To enforce the concept of separating class definition from its function implementations, where should the function implementatio
zzz [600]
D(in a .c file ) because that is where it should be placed :)
4 0
2 years ago
Irene establishes a wireless connection between her laptop and smartphone for sharing files. She has created a LANWANPAN, which
stira [4]

Irene created a LAN , which generally uses Ethernet cables for communication.

<h3>What is LAN about?</h3>

The LAN ports are known to be employed to link computers that do not have Wi-Fi access and it is one that make use of an Ethernet cable.

Note that Irene created a LAN , which generally uses Ethernet cables for communication to access the internet.

Learn more about  wireless connection from

brainly.com/question/26956118

#SPJ1

3 0
2 years ago
Other questions:
  • What is UNIX? A program for writing documents Graphical interface Internet browser Operating system
    8·2 answers
  • Which are considered regulatory agencies? Check all that apply. WHO PPO HMO CMS CDC NIOSH
    11·2 answers
  • What can search the internet and select elements based on important words
    10·1 answer
  • An alteration threat violates information integrity. <br> a. True <br> b. False
    13·1 answer
  • Can you awnser this question
    15·1 answer
  • 334. Universal Containers uses a custom field on the account object to capture the account credit status. The sales team wants t
    12·1 answer
  • You are asked to write a program that prompts the user for the size of two integer arrays, user input for the size must not exce
    13·1 answer
  • When you login to your blogging account. The first screen with all controls, tools and functions is called .... Select one: a. D
    10·1 answer
  • Can you please help me with this crossword puzzle, I am having trouble with numbers 5 down and 22 across.
    5·2 answers
  • Suppose we used an internet addressing protocol that used 4 bits to encode a single address. How many devices would be supported
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!