139k views
0 votes
write a program that does the following: 1. Declare the string variables firstname and last name. 2. Prompt the user for first name and last name. 3. Read in the first name and last name entered by the user. 4. Print out Hello follow by users full name. These questions could be found from this book C++ without fear second edition by Brian overland

User Rutgerm
by
9.1k points

1 Answer

4 votes

Answer:

// here is code in c++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variable declaration

string firstname,lastname;

// ask to enter first name

cout<<"enter the first name:";

// read firs tname

cin>>firstname;

// ask last name

cout<<"enter the last name:";

// read last name

cin>>lastname;

// print the output

cout<<"hello "<<firstname<<" "<<lastname<<endl;

return 0;

}

Step-by-step explanation:

Part 1, declare variables "firstname" and "lastname".Part 2, Ask user to enter first and last name.Part 3, read the value of first and last name and assign to variables "firstname" and "lastname" respectively.Part 4, Print "hello" followed by first name and last name.

Output:

enter the first name:robert

enter the last name:doweny

hello robert doweny

User Xtrinch
by
8.1k points