Question

I have program altered from firstname, middlename, and last name, but I want to reversed to...

I have program altered from firstname, middlename, and last name, but I want to reversed to lastname, middlename, and firstname. Please help me this c++ thank you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include<iostream>
#include<string>
#include<string.h>
using namespace std;
int main(){
   string s;
   cout<<"Enter name(first name middle name last name):";
   getline(cin,s);
   int a=s.length(),u,i,v,j=0,k;
   char g[a];
   for(u=0;u<2;u++){
       for(i=a-1;i>=0;i--){
           if(s[i]==' '){
               break;
           }
       }
       v=i;
       i=i+1;
       for(k=i;k<=a-1;k++){
             g[j++]=s[k];
       }
       g[j++]=' ';
       a=v;
   }
   for(i=0;i<=a;i++){
       g[j++]=s[i];
   }
   cout<<endl<<"Reversed is "<<g;
}

Output:

Add a comment
Know the answer?
Add Answer to:
I have program altered from firstname, middlename, and last name, but I want to reversed to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C program help #include #include #include void PrintName(char firstname[16], char lastname[16]); int main () { char...

    C program help #include #include #include void PrintName(char firstname[16], char lastname[16]); int main () { char firstname[16]; char lastname[16]; printf("please enter your first name:"); scanf("%s",firstname); printf("please enter your last name:"); scanf("%s",lastname); PrintName(firstname,lastname); return 0; } void PrintName(char firstname[16], char lastname[16]){ char fullname[34]; *fullname=*firstname+*lastname; (char*) malloc (sizeof (*fullname)); if (strlen(firstname) > 16||strlen(lastname)>16||strlen(fullname)>16) fflush(stdin); else printf(" the full name is %s %s \n",firstname,lastname); printf(" the full name is-> %s",fullname);/*why is one not run*/ return 0; }

  • You have a file called Names that has names as FirstName LastName FirstName LastName. For example,...

    You have a file called Names that has names as FirstName LastName FirstName LastName. For example, Names could have Bruce Willis Andrew Andrew Samwise Gamgee Duran Duran Write a program that goes through this file and writes all the names that have the same first and last names to a file called SameNames For example, for the file above, the program would write to the file SameNames Andrew Andrew Duran Duran

  • WRITE A JAVA PROGRAM (WILL GUARANTEE A THUMBS UP) BELOW IS WHAT SHOULD BE INCLUDED IN...

    WRITE A JAVA PROGRAM (WILL GUARANTEE A THUMBS UP) BELOW IS WHAT SHOULD BE INCLUDED IN THE CODE: Map m1 = new HashMap(); m1.put("firstName","f1"); m1.put("lastName","l1"); m1.put("middleName","m1"); Map m2 = new HashMap(); m2.put("firstName","f2"); m2.put("lastName","l2"); m2.put("middleName","m2"); BELOW IS THE EXPECTED OUTPUT IF GETTING ALL THE VALUES FROM THE INPUT: String strOut = [f1.l1.m1][email protected];[f2.l2.m2][email protected] BELOW IS THE EXPECTED OUTPUT IF LAST NAME IS NULL: String strOut = [f1.m1][email protected];[f2.m2][email protected]

  • 6. Write a program that inputs the first name, middle initial (wirh period), and last name...

    6. Write a program that inputs the first name, middle initial (wirh period), and last name of a user and displays that person's n first name first, middle initial followed by a period, and last namelt hel will need the following variables: FirstName (a String) MiddleInitial (a String) LastName (a String) name with the

  • Convert this C program to Js (Java script) from Visual Studio Code #include<stdio.h> int main(){ char...

    Convert this C program to Js (Java script) from Visual Studio Code #include<stdio.h> int main(){ char firstName[100]; char lastName[100]; printf("Enter Your Full Name: \n"); scanf("%s %s", firstName, lastName); printf("First Name: %s\n", firstName); printf("Last Name: %s\n", lastName); return 0; }

  • In JAVA #3 Write a program named nameChanger.java. This program will only have a driver class...

    In JAVA #3 Write a program named nameChanger.java. This program will only have a driver class with a main. This program will have the user enter a series of names(first and last), which will then be stored in a String array. You will then change the values of each of the names in the array, so that they are stored lastname, firstname, and then output the revised array. Sample: Enter a name (first and last): Tonya Pierce Enter a name...

  • I have this module of javascript var data = [     {id: 1, firstName: 'John', lastName: 'Smith'},...

    I have this module of javascript var data = [     {id: 1, firstName: 'John', lastName: 'Smith'},     {id: 2, firstName: 'Jane', lastName: 'Smith'},     {id: 3, firstName: 'John', lastName: 'Doe'} ]; module.exports.setid =     function (value) {         data.id = value; }; module.exports.getid = function () {         return data.id;     }; module.exports.setFirstName = function (value) {         data.firstName = value;     }; module.exports.getFirstName = function () {         return data.firstName;     }; module.exports.setLastName = function (value) {         data.lastName = value;     }; I wrote the following to get all first...

  • (TCO 7) Write a query to display the orderid, order date, customer last name and firstname...

    (TCO 7) Write a query to display the orderid, order date, customer last name and firstname for all orders that have shipped. SalesRep Customer ReplD int PK CustomerID int LastName FirstName Commission Rate varchar(20) varchar(20) decimal(10,2) LastName FirstName Street City State Zipcode Balance ReplD varchar(20) varchar(20) varchar(20) varchar(20) char(2) char(5) HO----O decimal(10,2) Order OrderID PK int FK1 int FK1 CustomerID OrderDate ShipDate date date Part PK PartID int Orderline varchar(20) int Description UnitsOnHand Item Class Retail Cost PK,FK1 OrderID PartID...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • read the code and comments, and fix the program by INSERTING the missing code in Java...

    read the code and comments, and fix the program by INSERTING the missing code in Java THank you please import java.util.Scanner; public class ExtractNames { // Extract (and print to standard output) the first and last names in "Last, First" (read from standard input). public static void main(String[] args) { // Set up a Scanner object for reading input from the user (keyboard). Scanner scan = new Scanner (System.in); // Read a full name from the user as "Last, First"....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT