Question

Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a...

Part 2: Processing Strings (Individual work)

Processing user-entered data to follow a specific format is a common task. Often this involves using string functions to manipulate a set of input strings.

Create a MATLAB script named namephone.m and place these lines of code at the beginning:

name  = input('Enter your first and last name: ','s');

phone = input('Enter your area code and phone number: ','s');

Tasks

Here are useful string functions:  length, strcat, strtrim, lower, upper, strcmp, findstr, strrep

As you work through this, test your code with different badly formed name and phone strings.

  • Assume the user enters his or her name as a single string like this: FirstName LastName. To keep it simple, you may also assume the user is not entering just a single name or more than two names. There will always be at least one space character between the two names.
    • Separate the full namestring into two, separate string variables. Store the first name in a variable named FirstName, and store the last name in a variable named LastName.
    • Remove all leading and trailing spaces from both of the new strings.
    • Example:  name is '  kAthY JonES '            FirstName --> 'kAthY'        LastName --> 'JonES'

Show a sequence of MATLAB commands to do this in the box below.

  • It is possible that the user entered his or her name in a mixture of uppercase and lowercase characters that does not make sense.
    • Modify the FirstName and LastName strings so that only the first letter of each is capitalized.
    • Example:  FirstName --> 'Kathy'   LastName --> 'Jones'

Show your commands below.

  • Suppose the program requires the user’s name be put in last name first and first name last order.
    • Construct a new string named UserNamein this order: LastName, FirstName  (comma is needed)
    • Example: UserName ---> 'Jones, Kathy'

Show the commands need to create UserName.

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Part 2: Processing Strings (Individual work) Processing user-entered data to follow a specific format is a...
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
  • Write a Python program to create userids: You work for a small company that keeps the...

    Write a Python program to create userids: You work for a small company that keeps the following information about its clients: • first name • last name • a user code assigned by your company. The information is stored in a file clients.txt with the information for each client on one line (last name first), with commas between the parts. In the clients.txt file is: Jones, Sally,00345 Lin,Nenya,00548 Fule,A,00000 Your job is to create a program assign usernames for a...

  • 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 =...

  • 1. Write a program to input a list of names (strings) from the user and store...

    1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or by entering the string “quit”. 2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part...

    Objectives: 1. Classes and Data Abstraction?2. User-defined classes?3. Implementation of a class in separate files Part 1: In this assignment, you are asked: Stage1:?Design and implement a class named memberType with the following requirements: An object of memberType holds the following information: • Person’s first name (string)?• Person’s last name (string)?• Member identification number (int) • Number of books purchased (int)?• Amount of money spent (double)?The class memberType has member functions that perform operations on objects of memberType. For the...

  • You are asked to define a user-defined data type for students, that will contain the following...

    You are asked to define a user-defined data type for students, that will contain the following information about a student: ID number, first name, last name, major, GPA. Your structure should be cal Student. Based on the defined structure, user name on the command line, show how you will use a loop to search for the given name within the array of 5 students. use an array to record information about 5 students. Then, given a Write a C program...

  • Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user...

    Using Python INST-FS-IAD-PROD.INS LAB1 Lab: Create User Account 2. get-password() #promt the user and create password, check the password fits the requirement USE the EXACT file names! Create a user login system. Your code should do the following: 3, create-user_name() #use this function to create the user name 1.Create your user database called "UD.txt", this should be in CSV format 4, write-file() #user this function to save the user name and password into "UD.txt" Deliverables: Sample: the data you saved...

  • Write a Java program that reads a series of strings from a user until STOP is...

    Write a Java program that reads a series of strings from a user until STOP is entered. Each input consists of information about one student at the ABC Professional School. The input consists of the student’s last name (the first 15 characters with extra blanks on the right if the name is not 15 characters long), the student’s number (the next 4 characters, all digits, a number between 1000 and 5999), and the student’s program of study (one character, either...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

  • Requirements Create an Address Book class in Java for general use with the following behaviors: 1....

    Requirements Create an Address Book class in Java for general use with the following behaviors: 1. Constructor: public Address Book Construct a new address book object. • A contact has four fields: first name, last name, email and phone. (There could be more information for a real contact. But these are sufficient for the assignment.) . The constructor reads from the disk to retrieve previously entered contacts. If previous contacts exist, the address book will be populated with those contacts...

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