162k views
5 votes
Write a program that has the following String variables: firstName, middleName, and lastName. Initialize these with your first, middle, and last names. The program should also have the following char variables: firstInitial, middleInitial, and lastInitial. Store your first, middle, and last initials in these variables. The program should display the contents of these variables on the screen.

User Ersan
by
5.9k points

1 Answer

3 votes

Answer:

The programming language is not stated; However, I'll answer your question using C++ programming language.

Comments are used for explanatory purpose

Program starts here

#include<iostream>

#include <string>

using namespace std;

int main()

{

//Declare Variables

string firstName, middleName, lastName;

char firstInitial, middleInitial, lastInitial;

/*Initialize firstName, middleName and lastName (Replace values with your details)*/

firstName = "First Name";

middleName = "Middle Name";

lastName = "Last Name";

// Get Initials

firstInitial = firstName.at(0);

middleInitial = middleName.at(0);

lastInitial = lastName.at(0);

//Print Results

cout<<"Lastname: "<<lastName<<endl;

cout<<"Firstname: "<<firstName<<endl;

cout<<"Middlename: "<<middleName<<endl;

cout<<"Last Initial: "<<lastInitial<<endl;

cout<<"First Initial: "<<firstInitial<<endl;

cout<<"Middle Initial: "<<middleInitial<<endl;

return 0;

}

User Ian Walter
by
5.0k points