Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions