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
  • You are given a file consisting of students’ names in the following form: lastName, firstName middleName....

    You are given a file consisting of students’ names in the following form: lastName, firstName middleName. (Note that a student may not have a middle name.) Write a C++ program that converts each name to the following form: firstName middleName lastName. Your program must read each student’s entire name in a variable and must consist of a function that takes as input a string, consists of a student’s name, and returns the string consisting of the altered name. Use the...

  • JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you...

    JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you created in the previous lab. In this lab, create a Student class with the following class variable: Student name: Name (Note: Name is a datatype) Student Id: String Create the getter and setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Complete...

  • 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; }

  • in c++Many documents use a specific format for a person's name. Write a program whose input...

    in c++Many documents use a specific format for a person's name. Write a program whose input is: firstName middleName lastName, and whose output is: lastName, firstName middleInitial. Ex: If the input is: Pat Silly Doe the output is: Doe, Pat S. If the input has the form firstName lastName, the output is lastName, firstName. Ex: If the input is: Julia Clark the output is: Clark, Julia

  • 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]f1.l1.m1@abc.com;[f2.l2.m2]f2.l2.m2@abc.com BELOW IS THE EXPECTED OUTPUT IF LAST NAME IS NULL: String strOut = [f1.m1]f1.m1@abc.com;[f2.m2]f2.m2@abc.com

  • 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

  • My module page is correct but I don't believe I am using the main() function properly....

    My module page is correct but I don't believe I am using the main() function properly. One of my .py files is supposed to contain my definitions, which is the module file. My second .py file is supposed to properly call a main function that does what my program asks it to: First name, last name, age, and respond based off of input. For some reason I am struggling with using the main() function so that my program works. Any...

  • You must use C Language. The Main Objective: Make the first and last name ALL CAPITALS...

    You must use C Language. The Main Objective: Make the first and last name ALL CAPITALS even if the user types in lower case letters. Lastly, flip the first name and last name around. So: HEIDI, HATFIELD to HATFIELD, HEIDI. (PLEASE uppercase all the letters) End Goal: HATFIELD, HEIDI KAISER, RUSSELL LIPSHUTZ, HOWARD PENKERT, DAWN WRIGHT, ELIZABETH Please use this reference below, to fix the code given. Code given is below, I want the user to be able to enter...

  • 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; }

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