Showing posts with label Strings. Show all posts
Showing posts with label Strings. Show all posts

Saturday, 2 April 2016

Write a program that asks the user to enter his or her first name and then last name, and that then constructs, stores, and displays a third string consisting of the user’s last name followed by a comma, a space, and first name. Use string objects and methods from the string header file. A sample run could look like this:

Leave a Comment


Questions:

Write a program that asks the user to enter his or her first name and then last name, and that then constructs, stores, and displays a third string consisting of the user’s last name followed by a comma, a space, and first name. Use string objects and methods from the string header file. A sample run could look like this:

Explanation:

Below mention code is compiled in Visual Studio 2015 and Code Blocks 13.12,output snap is attached.. If any problem you feel and you want some explanation feel free to contact us.

Code:

/**************************************************|
/*************C++ Programs And Projects************|
***************************************************/



#include <iostream>
#include <string>

using namespace std;

int main() {
       cout << "Enter your first name: ";
       string firstName;
       getline(cin, firstName);
       cout << "Enter your last name: ";
       string lastName;
       getline(cin, lastName);

       string name = lastName;
       name += ", ";
       name += firstName;

       cout << "Here's the information in a single string: "
              << name << endl;
       return 0;
}



Output:


Related Articles:

C++ Primer Plus Sixth Edition Complete Solution Manual 

C++ Books Solution

Read More

Write a C++ program that requests and displays information as shown in the following example of output: What is your first name? Betty Sue What is your last name? Yewe What letter grade do you deserve? B What is your age? 22 Name: Yewe, Betty Sue Grade: C Age: 22

Leave a Comment


Questions:

1. Write a C++ program that requests and displays information as shown in the following example of output:
What is your first name? Betty Sue
What is your last name? Yewe
What letter grade do you deserve? B
What is your age? 22
Name: Yewe, Betty Sue
Grade: C
Age: 22
Note that the program should be able to accept first names that comprise more than one word. Also note that the program adjusts the grade downward—that is, up one letter. Assume that the user requests an A, a B, or a C so that you don’t have to worry about the gap between a D and an F.

Explanation:

Below mention code is compiled in Visual Studio 2015 and Code Blocks 13.12,output snap is attached.. If any problem you feel and you want some explanation feel free to contact us.

Code:

/**************************************************|
/*************C++ Programs And Projects************|
***************************************************/


#include <iostream>
#include <string>

using namespace std;

int main() {
       cout << "What is your first name? ";
       string firstName;
       getline(cin, firstName);

       cout << "What is your last name? ";
       string lastName;
       getline(cin, lastName);

       char grad;
       cout << "What letter grade do you deserve? ";
       cin >> grad;
       grad = grad + 1;

       cout << "What is your age? ";
       int age;
       cin >> age;


       cout << "Name: " << lastName << ", " << firstName << endl
              << "Grade: " << grad << endl
              << "Age: " << age << endl;

       return(0);
}



Output:


Related Articles:

C++ Primer Plus Sixth Edition Complete Solution Manual 

C++ Books Solution

Read More