Question

String array operations a. Create a string array called myInformationcontaining the following entries in order: Your...

String array operations

a. Create a string array called myInformationcontaining the following entries in order:

  • Your full name
  • The name of the town or city where you were born
  • Your major
  • The name of this university with only the first letter of each word capitalized; don’t forget the “The”!

b. Use the Matlab function strcmp to compare the name of the university as you defined it against the following two strings:

i. “The Ohio State University”

ii. “THE OHIO STATE UNIVERSITY”

Use variables called prob2bi and prob2bii to store the results of the comparisons.

c. Use the Matlab function strcmpi to compare the name of the university as you defined it against the following two strings:

i. “The Ohio State University”

ii. “THE OHIO STATE UNIVERSITY”

Use variables called prob2ci and prob2cii to store the results of the comparisons.

If the difference between strcmp and strcmpi is not obvious from the example, look them up in the Matlab documentation.

d. Extract your name from the string array and convert it to a char array called myName.

e. Change the part of myName containing your first name to 'Brutus'. (For example, if your name was originally 'James E. Toney', it will now be 'Brutus E. Toney'.) YOU SHOULD BE ABLE TO DO THIS WITHOUT RE-CREATING THE WHOLE CHAR ARRAY FROM SCRATCH - USE CONCATENATION AS NEEDED

Homework Answers

Answer #1

a. Create a string array called myInformation containing the following entries in order:

  • Your full name
  • The name of the town or city where you were born
  • Your major

myInformation = ["James E. Toney", "Florida", "CS", "The Ohio State University"]

b. Use the Matlab function strcmp to compare the name of the university as you defined it against the following two strings:

  1. “The Ohio State University”
  2. “THE OHIO STATE UNIVERSITY”

prob2bi = strcmp(myInformation(4), “The Ohio State University”)

prob2bii = strcmp(myInformation(4), “THE OHIO STATE UNIVERSITY”)

c. Use the Matlab function strcmpi to compare the name of the university as you defined it against the following two strings:

  1. “The Ohio State University”
  2. “THE OHIO STATE UNIVERSITY”

prob2ci = strcmpi(myInformation(4), “The Ohio State University”)

prob2cii = strcmpi(myInformation(4), “THE OHIO STATE UNIVERSITY”)

strcmp is case sensitive wheras strcmpi is case insensitive

d. Extract your name from the string array and convert it to a char array called myName.

myName = char(myInformation(1))

e. Change the part of myName containing your first name to 'Brutus'.

myNametemp = split(myName)

myName=char(strcat("Brutus ",myNametemp(2)," ",myNametemp(3)))

Know the answer?
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
Similar Questions
1. Please write the following in C++ also please show all output code and comment on...
1. Please write the following in C++ also please show all output code and comment on code. 2. Also, use CPPUnitLite to write all test and show outputs for each test. Write CppUnitLite tests to verify correct behavior for all the exercises. The modifications are aimed at making the exercises more conducive to unit tests. Write a function that swaps (exchanges the values of two integers). Use int* as the argument type. Write a second swap function using a reference...
DESCRIPTION: You will be given a 2D array, called matrix, of Strings. The array has an...
DESCRIPTION: You will be given a 2D array, called matrix, of Strings. The array has an unknown number of cells filled with data. Your goal is to iterate through the 2D array and keep a count of how many cells are full. You will be given the dimensions of the array. INPUT: All input has been handled for you: Two integers denoting the dimensions of the array. These are the integer variables rows and cols. A partially filled 2-D array....
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs and compares the character by character. If the two strings are exactly same it returns 0, otherwise it returns the difference between the first two dissimilar characters. You are not allowed to use built-in functions (other than strlen()) for this task. The function prototype is given below: int compare_strings(char * str1, char * str2); Task 3: Test if a string is subset of another...
Write in C++. Define a class called Text whose objects store lists of words. The class...
Write in C++. Define a class called Text whose objects store lists of words. The class Text will be just like the class StringVar except that the class Text will use a dy- namic array with base type StringVar rather than base type char and will mark the end of the array with a StringVar object consisting of a single blank, rather than using '\0' as the end marker. Intuitively, an object of the class Text represents some text consisting...
In the following C code, Which variable if NOT of primitive data type? A. a B....
In the following C code, Which variable if NOT of primitive data type? A. a B. b C. c D. d int a = 10; double b = 20.0; float c = false; char d[5] = "Hello"; // here we define a string In programming language C, the implementation of a string data type is limited dynamic length, which means the length of a string variable is fixed once it has been defined. A. True B. False In C# programming...
Strings The example program below, with a few notes following, shows how strings work in C++....
Strings The example program below, with a few notes following, shows how strings work in C++. Example 1: #include <iostream> using namespace std; int main() { string s="eggplant"; string t="okra"; cout<<s[2]<<endl; cout<< s.length()<<endl; ​//prints 8 cout<<s.substr(1,4)<<endl; ​//prints ggpl...kind of like a slice, but the second num is the length of the piece cout<<s+t<<endl; //concatenates: prints eggplantokra cout<<s+"a"<<endl; cout<<s.append("a")<<endl; ​//prints eggplanta: see Note 1 below //cout<<s.append(t[1])<<endl; ​//an error; see Note 1 cout<<s.append(t.substr(1,1))<<endl; ​//prints eggplantak; see Note 1 cout<<s.find("gg")<<endl; if (s.find("gg")!=-1) cout<<"found...
Use Rstudio to create a script by following the instruction below. I've created the first question...
Use Rstudio to create a script by following the instruction below. I've created the first question code but I can not continue it further. Thank you. ## Write a function called `make_introduction` that takes in two arguments: name, and age. ## This function should return a string value that says something like "Hello, my name is {name}, and I'm ## {age} years old". make_introduction <- function(name, age){ print(paste("Hello, my name is", name, "and I'm", age, "years old")) } ## Create...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
1) Describe an example of each of the following that may be found of your kitchen:...
1) Describe an example of each of the following that may be found of your kitchen: Explain how your choice falls into this category, and if there is a chemical name or symbol for it, provide that as well. Provide a photo of your example with your ID card in it. a) a compound b) a heterogeneous mixture c) an element (symbol) Moving to the Caves… Lechuguilla Caves specifically. Check out this picture of crystals of gypsum left behind in...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...