Enter your first andlast name when prompted. then modify the source code so that
ID: 3611745 • Letter: E
Question
Enter your first andlast name when prompted. then modify the source code so that theprogram also asks the user to type in his/her major after enteringthe first and last name. then, add the code to display the majorentered by the user. Display it in the "Hello" box on the lineafter the name.(Source Code)
//-----------------------------------------------------------------------
// FILE NAME : pgm1b.cpp
// PURPOSE : Displays ahello greeting including the user's name.
//INPUT : Asks the user to enter his/her first and last name.
// PROCESSING : None
//OUTPUT : Displays a hello greeting and the user's first and lastname
// in a box of asterisks on the screen.
// AUTHOR : Put your name here
// DUE DATE : 01/23/2009
//----------------------------------------------------------------------
#include <iostream>
#include <string>
using namespace std;
int main ( )
{
string firstName, lastName;
// Get user's Name
cout << "Please enter your first name: ";
cin >> firstName;
cout << "Please enter your last name: ";
cin >> lastName;
// Display hello greeting
cout <<"****************************************" << endl;
cout <<"** Hello **" << endl;
cout <<"** " << firstName << " " << lastName
<<" ** " << endl;
cout << "*************************************"<< endl;
return 0;
}
(Expected output on the screen)
(Before modifying the code)
Please enter your first name : Tiger
Please enter your last name : Woods
**********************************************
** Hello **
** TigerWoods **
**********************************************
(After modifying the code)
Please enter your first name: Tiger
Please enter your last name: Woods
Please enter your major: CS
*******************************************
** Hello **
** TigerWoods **
** Your majoris : CS **
******************************************* Enter your first andlast name when prompted. then modify the source code so that theprogram also asks the user to type in his/her major after enteringthe first and last name. then, add the code to display the majorentered by the user. Display it in the "Hello" box on the lineafter the name.
(Source Code)
//-----------------------------------------------------------------------
// FILE NAME : pgm1b.cpp
// PURPOSE : Displays ahello greeting including the user's name.
//INPUT : Asks the user to enter his/her first and last name.
// PROCESSING : None
//OUTPUT : Displays a hello greeting and the user's first and lastname
// in a box of asterisks on the screen.
// AUTHOR : Put your name here
// DUE DATE : 01/23/2009
//----------------------------------------------------------------------
#include <iostream>
#include <string>
using namespace std;
int main ( )
{
string firstName, lastName;
// Get user's Name
cout << "Please enter your first name: ";
cin >> firstName;
cout << "Please enter your last name: ";
cin >> lastName;
// Display hello greeting
cout <<"****************************************" << endl;
cout <<"** Hello **" << endl;
cout <<"** " << firstName << " " << lastName
<<" ** " << endl;
cout << "*************************************"<< endl;
return 0;
}
(Expected output on the screen)
(Before modifying the code)
Please enter your first name : Tiger
Please enter your last name : Woods
**********************************************
** Hello **
** TigerWoods **
**********************************************
(After modifying the code)
Please enter your first name: Tiger
Please enter your last name: Woods
Please enter your major: CS
*******************************************
** Hello **
** TigerWoods **
** Your majoris : CS **
*******************************************
Explanation / Answer
//-----------------------------------------------------------------------// FILE NAME : pgm1b.cpp
// PURPOSE : Displays ahello greeting including the user's name.
//INPUT : Asks the user to enter his/her first and last name.
// PROCESSING : None
//OUTPUT : Displays a hello greeting and the user's first and lastname
// in a box of asterisks on the screen.
// AUTHOR : Put your name here
// DUE DATE : 01/23/2009
//----------------------------------------------------------------------
#include <iostream>
#include <string>
using namespace std;
int main ( )
{
string firstName, lastName, major;
// Get user's Name
cout << "Please enter your first name: ";
cin >> firstName;
cout << "Please enter your last name: ";
cin >> lastName;
cout << "Please enter yourMajor: ";
cin >> major;
// Display hello greeting
cout <<"****************************************" << endl;
cout <<"** Hello **" << endl;
cout <<"** " << firstName << " " <<lastName <<" ** " << endl; cout <<"** " <<"your Major is : "<< Major <<" ** " << endl;
cout << "*************************************"<< endl;
return 0;
} //====================== // it isdone //======================
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.