Question

In: Computer Science

C++ Question 4. Formulate the following conditions • A last name starts with the letter H....

C++ Question

4. Formulate the following conditions

• A last name starts with the letter H.

• A last name starts with the letters Mac.

• A last name comes before "Jones".

Solutions

Expert Solution

I have done this program to best of your requirement as mentioned by you.

If anything more is needed leave comments.

#include <iostream>

using namespace std;

int main(){

char choice = 'y';

string previousLastName = "";

do{

string firstName;

string lastName;

cout << "Enter First Name: ";

cin >> firstName;

cout << "Enter Last Name: ";

cin >> lastName;

// 1. A last name starts with the letter 'H'

if( lastName[0] == 'H')

cout << "Last Name ["<< lastName <<"] starts with the letter H.\n";

// 2. A last name starts with "Mac"

if ( lastName[0] == 'M' )

if ( lastName[1] == 'a' )

if ( lastName[2] == 'c' )

cout << "\nLast Name ["<< lastName <<"] starts with the letters ""Mac \n";

// 3. A Last Name comes before "Jones"

if ( 0 == lastName.compare("Jones") ){

if ( 0 == previousLastName.compare(""))

cout << "\nThere was no Last Name before 'Jones' \n";

else

cout << "\nLast Name ["<< previousLastName <<"] comes before 'Jones'.\n";

}

cout << "Do you want to enter again ? y/n : ";

cin >> choice;

previousLastName = lastName;

}while(choice == 'y' || choice == 'Y');

return 0;

}


Related Solutions

Select a Fortune 500 company whose name starts with the first letter in your last name...
Select a Fortune 500 company whose name starts with the first letter in your last name and obtain the company’s most recent 10-K report. (You may use the same company that you used previously.) Be sure that the company has a complex capital structure. Attach the equity section of the balance sheet and the notes relevant to answering the following questions: (a) Does the company have preferred stock and common stock (or different classes of common stock)? Do its stocks...
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other.
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other
Based on the letter of your last name in ASAP will be how you are assigned...
Based on the letter of your last name in ASAP will be how you are assigned your state: a. Last Name starts with the letter A-D, you choose from one of these states i. Alabama, Alaska, Arizona, Arkansas, California, Colorado, Connecticut, Delaware Introduction Portion (10%) a. Discuss where and how the Coronavirus originated. b. Explain why you chose the state from the given list above; in other words, reasoning based on area, peaked at the better stats first, etc. c....
Let M be the integer corresponding to the first letter of your last name. For example,...
Let M be the integer corresponding to the first letter of your last name. For example, if your last name begins with "A", M=1 and if your last name begins with "Z", M=26. Let k=1/M and consider the logistic equation dy/dt = k y (M - y). Construct a single figure including Title "Logistic Equation Slope Field and Euler's Method solutions by FirstName LastName" with your actual first and last names, along the top Labels for the axes a slope...
Let M be the integer corresponding to the first letter of your last name. For example,...
Let M be the integer corresponding to the first letter of your last name. For example, if your last name begins with "A", M=1 and if your last name begins with "Z", M=26. Let k=1/M and consider the logistic equation dy/dt = k y (M - y). Construct a single figure including Title "Logistic Equation Slope Field and Euler's Method solutions by FirstName LastName" with your actual first and last names, along the top Labels for the axes a slope...
4. C and D are equal partners in the CD partnership. C starts the year with...
4. C and D are equal partners in the CD partnership. C starts the year with an adjusted basis of $400 in the partnership while D starts the year with an adjusted basis of $700. (a) The partnership distributes cash of$ 500 to C and land, adjusted basis $300 fair market value $500 to D. The partnership thereafter continues operations. What consequences? (b) Same as (a) except that the land had an adjusted basis of $800 (fair market value still...
4. Balance the following redox equations using the half reaction method under basic conditions: a. H+...
4. Balance the following redox equations using the half reaction method under basic conditions: a. H+ + Cu(s) + NO3 - → Cu2+ + NO2 + H2O b. MnO4 - + Cl- + H+ → Mn2+ + Cl2 + H2O c. Zn(s) + ClO3 - + H+ → Zn2+ + Cl- + H2O d. Cl- + H+ + Cr2O7 2- → Cr3+ + Cl2 + H2O e. Mn2+ + NaBiO3 + H+ → MnO4 - + Bi3+ + Na+ +...
C++ Write a program that asks a teacher to input a student’s first name, last name,...
C++ Write a program that asks a teacher to input a student’s first name, last name, and four test scores. The program should find the average of the four test scores and should then write the following information to a file named “students.txt” last_name first_name average A student's first name of “XX” should be used as a sentinel value and no numeric grades less than 0 or greater than 100 should be accepted.  The program should then read the information in...
C++ Change the program to take user input for first name and last name for five...
C++ Change the program to take user input for first name and last name for five employees. Add a loop to read the first name and last name. // EmployeeStatic.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <string> #include <iostream> #include <string> using namespace std; class Employee { public:    Employee(const std::string&, const std::string&); // constructor    ~Employee(); // destructor    std::string getFirstName() const; // return first name    std::string getLastName() const; // return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT