Question: Problem 1 In this problem, you will write two functions. The first function takes in a string and returns that string without any dashes. The

Problem 1

In this problem, you will write two functions. The first function takes in a string and returns that string without any dashes. The second function takes in the first and last name and returns a string that is lastname_firstname and uses the previous function to remove any dashes (-) in the name.

Note that youll be testing it by calling it from the command line; youll call it from a script in problem 3.

Deliverables:

  1. Function file that takes in a string and returns a string without a dash

    1. A script is not necessary for this problem

  2. Call that function from the command line and show that it works

    1. strNoDash = RemoveDash(first-name);

      1. For this problem, you will not need to create a script to show your function works.

  3. Function file that takes in first and last name and returns the joined name

    1. This should include the RemoveDash function ran for both the first and last name

  4. Call the function from the command line and show that it works

    1. str = JoinName(first, last)

    2. str = JoinName(first, last-name);

    3. str = JoinName(first-name, last-name);

Step by Step Instructions:

Create a function file that takes in a string and returns the same string with no dashes.

  • Add code to your function to check for the dash (-) in either the first or last name

    • Try strfind(first). What do you get?

    • try strfind(first-dash). What do you get?

    • Youll need isempty to check for an empty return

  • If you have a dash, you need to delete it. Theres two ways to do this. Either set that element to the empty array

    • array(k) = [] - deletes the kth element from array

    • array = strcat( array(1:k-1), array(k+1:end) ) set the array to the first and second halves

Create another function file. It should take in two variables and return one.

  • The inputs should be the first and last names as strings

  • Start with using strcat or sprintf to join the names together. Check that it works with first and last (call from the command line)

    • Note: One trick is to copy the first line of the function file, delete the function key word, and then put your own variable values in. This makes sure that you have the inputs and the outputs in the right order

    • I.e., copy function function [strOut] = JoinNames( strFirst, strLast ) to the command line,

    • And then edit to be

      • strOut = JoinNames(first, last)

  • Make sure to implement the RemoveDash function for both names in the JoinNames function

    • Call this on both inputs from within your join string function

Self-check:

>> strOut = RemoveDash('first-dash')

strOut =

firstdash

>> str = JoinName('first', 'last')

str =

last_first

>> str = JoinName('first-dash', 'last')

str =

last_firstdash

>> str = JoinName('first-dash', 'last-dash')

str =

lastdash_firstdash

>>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!