CSIS2101_assgn9
.docx
keyboard_arrow_up
School
Nova Southeastern University *
*We aren’t endorsed by this school
Course
2101
Subject
Computer Science
Date
Jan 9, 2024
Type
docx
Pages
3
Uploaded by the831unit
Assignment 9: Strings
Qn.1 ( 35 points )
In Python operation on strings when you use <string>.replace( old substring, new substring )
function it replaces all instances of the old string with the new string. But write your own
replace
function which takes three arguments the original string and the old sub string and new
sub string replace only the second instance of the old substring with the new substring. If the
string has no instance or only one instance of the substring return the original string.
The method
should use the count function to check whether the count of the old substring is more than 1.
If
less than 2 return the original string or else method should iterate over the string and
replace the second instance of the old sub string and replace with the new sub string. The
only string function you can use for this replace function is the find function to find the
index of the substring.
find function can be used more than once.
For example The input string is "Mississippi" Sub String to replace is "ss" and new sub string is
“zz”, The function should return “Missizzippi” where second instance of ss is replaced with zz.
If no instance or 1 instance, return the original string. For example The input string is
"Mississippi" Substring to replace is "k" with “kk” return “Mississippi” as there is no “k” in the
string. And similarly for example The input string is "Mississippi" Substring to replace is "pp"
with the new sub string “qq” then return original string “Mississippi” as there is only one “pp” in
the string.
If more than two instances found again replace the second instance of the old substring with the
new substring. For example The input string is "Mississippi" and substring to replace is "i" with
1 it returns Miss1ssippi.
Name the python function that does it
as FirstNameFirstAlphabet
LastNameLastAlphabet(UpperCase)_replace( Original String, old substring, new substring).
So for example your name is John Doe the function should be jE_replace
Qn 2. (35 points)
Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their
customers to remember. On the dial pad the alphabetic letters are mapped to numbers in the
following fashion:
A B and C – 2
D E and F –
3
G H and I
– 4
J K and L – 5
M N and O – 6
P Q R and S – 7
T U and V – 8
W X Y and Z – 9
Write a program that asks the user to enter a 10 character telephone number in the format XXX-
XXX-XXXX
or XXX XXXXXXX (In both formats with or without the hyphen “-“). You don’t
have to validate the format. It can be all alphabets or mixture of alphabet and Numbers. The
application should display the telephone number with any alphabetic character that appeared in
the original translated into their numeric equivalent.
For example if user enters 555-GET-FOOD, the application should display 555-438-3663.
Another example is 800 flowers should display 800 3569377
The program should handle upper case and lower case alphabets. The phone number can contain
hyphens ( “-“) like in the first example or spaces like in the second example.
Name the python function that does it
as FirstNameFirstAlphabet
LastNameLastAlphabet(UpperCase)_Number_Converter and this function needs to be called
from main.
Do not use a dictionary or use replace function to do the conversion
. Once again
iterate over the string.
So for example your name is John Doe the program and the function should be
jE_Number_Converter. Start with an empty string as the converted number. Go through each
character in the old number, if it is an alphabet convert into a number and add it to the converted
number or else add the original character to the converted number. You need to please follow this
method for conversion.
Qn 3. (30 points)
Write a program that accepts a sentence as an input and converts each word to pig latin. In this
version to convert a word into pig latin, you make the whole sentence upper case and exchange
the last letter and first letter of each word and place the letters at the beginning of the word. Then
you append the string “2101” to the word. Here is an example:
English:
I SLEPT MOST OF THE NIGHT.
Pig Latin:
I2101 TLEPS2101 TOSM2101 FO2101 EHT2101 TIGHN2101
The program should handle upper case and lower case alphabets.
Name the python function that does it
as FirstNameFirstAlphabet
LastNameLastAlphabet(UpperCase)_Pig_Latin and this function needs to be called from main.
So for example your name is John Doe the program and the function should be jE_Pig_Latin.
Assume there are no punctuations like !, ? comma, period etc in the given sentence.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
String Pair
// Problem Description
// One person hands over the list of digits to Mr. String, But Mr. String understands only strings. Within strings also he understands only vowels. Mr. String needs your help to find the total number of pairs which add up to a certain digit D.
// The rules to calculate digit D are as follow
// Take all digits and convert them into their textual representation
// Next, sum up the number of vowels i.e. {a, e, i, o, u} from all textual representation
// This sum is digit D
// Now, once digit D is known find out all unordered pairs of numbers in input whose sum is equal to D. Refer example section for better understanding.
// Constraints
// 1 <= N <= 100
// 1 <= value of each element in second line of input <= 100
// Number 100, if and when it appears in input should be converted to textual representation as hundred and not as one hundred. Hence number…
arrow_forward
Exercise Objectives
Problem Description
Write a program that reads a string and mirrors it around the middle character.
Examples:
abcd becomes cdab.
abcde becomes deCab
AhmadAlami becomes AlamiAhmad
Page 1 of 2
Your program must:
• Implement function void reflect (char* str) which receives a string (array of characters) and
mirrors it. This function does not print anything.
•
Read from the user (in main()) a string and then print the string after calling function reflect().
•
Use pointers and pointer arithmetic only. The use of array notation and/or functions from the string.h
library is not allowed.
arrow_forward
remove_substring_from_string(s, substr): This function takes two strings s and substr as input.
It creates a new string from the original string s by removing all instances, if any, of the string
substr, and then returns the new string.
>>> remove_substring_from_string("Python is best language except for C++.
except for C++")
'Python is best language. '
arrow_forward
vowelIndex
Write a function vowelIndex that accepts a word (a str) as an argument and returns the index
of the first vowel in the word. If there is no vowel, -1 is returned. For this problem, both upper
and lower case vowels count, and 'y' is not considered to be a vowel. Sample usage:
>>> vowelIndex('hello')
1
>>> vowelIndex('string')
3
>>> vowelIndex('string')
3
>>> vowelIndex('BUY')
1
>>> vowelIndex('APPLE')
0
>>> vowelIndex('nymphly')
-1
>>> vowelIndex('string')==3
True
>>> vowel Index ('nymphly')==-1
True
arrow_forward
Objective: string and character manipulation, string.h and ctype.h libraries
For each of the problems, create a user-defined function. Then write a driver program for the functions inside the main.
1- Write a function that takes a word less than 25 characters long and returns the letter that word starts with (in capital letters).
2- Write a function that has a string as formal parameter. The function then replaces all spaces and punctuation marks in the string with the asterisk (*).
3- Write a function that takes as input one line and reverses the words of the line
4- Write a function that takes nouns (a string) as inputs and forms their plurals based on these rules: a. If noun ends in “y”, remove the “y” and add “ies”. b. If noun ends in “s”, “ch”, or “sh”, add “es”. c. In all other cases, just add “s”.
Now create the driver program
- Ask the user for their first and last name. Store the names in separate arrays. - Greet the user by their full names. - Let them know what their…
arrow_forward
In c++
arrow_forward
Question >
Not complete
Marked out of
1.50
Flag question
Previous page
Write a recursive function named get_palindromes (words) that takes a list of words as a parameter. The function should return a list of all the palindromes in the list. The function returns an
empty list if there are no palindromes in the list or if the list is empty. For example, if the list is ["racecar", "hello", "noon", "goodbye"], the function should return ["racecar", "noon"].
A palindrome is a word that is spelled the same forwards and backwards.
Note: The get_palindromes() function has to be recursive; you are not allowed to use loops to solve this problem.
For example:
Test
words = ["racecar", "hello", "noon", "goodbye", "test", 'aibohphobia'] ['racecar', 'noon', 'aibohphobia']
print (get_palindromes (words))
print (get_palindromes ([]))
print (get_palindromes (['this', 'is', 'test']))
Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %)
Result
Precheck Check
[]
[]
Next page
arrow_forward
Pyth code
arrow_forward
Write a function recursively_count_vowels() which accepts a pointer to a string, and any other parameters you see fit, and recursively counts the number of vowels in the provided string. This function should return the number of vowels in the string. (programming language c)
arrow_forward
String Manipulation
In this question, you will be implementing the following functions
int findChar(char * str, char c);
Searches for the character c in the string str and returns the index of the character in the string. If the character does not exist, returns -1
int replaceChar(char * str, char c1, char c2);
Searches for the character c1 in the string str and if found, replace it with c2.The function returns the number of replacements it has performed. If the character does not exist, returns 0.
int removeChar(char * str1, char * str2, char c);
Creates a copy of str1 into str2 except for the character c that should be replaced with ‘*’
For example, if
str1=”Hello World” and
c=’l’ then the function should make
str2=”He**o Wor*d”
int isPalindrome(char * str)
Checks to see if a string is Palindrome(reversible). If it is, returns 1, otherwise returns 0. A palindrome string reads similarly from left to right and from right to left like madam, level, radar, etc.
int reverseString(char…
arrow_forward
C++ Code: DNA Sequence
The main() function is already written for you. You will implement the function int numOccurrences(string& STR, string& sequence). Without even understanding what functions do in C++, all you need to know, at this point, is that you have access to the string STR of which you have to find the length of the largest consecutive occurrence in the string sequence.
For example,
if input sequence is:
AGACGGGTTACCATGACTATCTATCTATCTATCTATCTATCTATCTATCACGTACGTACGTATCGAGATAGATAGATAGATAGATCCTCGACTTCGATCGCAATGAATGCCAATAGACAAAA
then
numOccurrences("AGAT", sequence) should return 5
numOccurrences("TATC", sequence) should return 8
if input sequence is:
AACCCTGCGCGCGCGCGATCTATCTATCTATCTATCCAGCATTAGCTAGCATCAAGATAGATAGATGAATTTCGAAATGAATGAATGAATGAATGAATGAATG
then
numOccurrences("AATG", sequence) should return 7
numOccurrences("TATC", sequence) should return 4
if input sequence is:…
arrow_forward
C++
arrow_forward
C language
arrow_forward
def swap_text(text):
Backstory:
Luffy wants to organize a surprise party for his friend Zoro and he wants to send a message to his friends, but he wants to encrypt the message so that Zoro cannot easily read it. The message is encrypted by exchanging pairs of characters.
Description: This function gets a text (string) and creates a new text by swapping each pair of characters, and returns a string with the modified text. For example, suppose the text has 6 characters, then it swaps the first with the second, the third with the fourth and the fifth with the sixth character.
Parameters: text is a string (its length could be 0)Return value: A string that is generated by swapping pairs of characters. Note that if the
Examples:
swap_text ("hello") swap_text ("Party for Zoro!") swap_text ("") def which_day(numbers):
→ 'ehllo'→ 'aPtr yof roZor!' → ''
length of the text is odd, the last character remains in the same position.
arrow_forward
Help now please
Python
arrow_forward
C++ programming
arrow_forward
Problem DNA: Subsequence markingA common task in dealing with DNA sequences is searching for particular substrings within longer DNA sequences.
Write a function mark_dna that takes as parameters a DNA sequence to search, and a shorter target sequence to find within the longer sequence. Have this function return a new altered sequence that is the original sequence with all non-overlapping occurrences of the target surrounded with the characters >> and <<.
Hints:
● String slicing is useful for looking at multiple characters at once.
● Remember that you cannot modify the original string directly, you’ll need to build a copy.
Start with an empty string and concatenate onto it as you loop.
Constraints:
● Don't use the built-in replace string method. All other string methods are permitted.
>>> mark_dna('atgcgctagcatg', 'gcg') 'at>>gcg<<ctagcatg' >>> mark_dna('atgcgctagcatg', 'gc')…
arrow_forward
COMMON PREFIX
Two strings s1, s2 are passed as a parameter to the given function. Return the largest common prefix of the strings sl and s2.
string commonPrefix(string s1, string s2){
// write your CPP code here
}
arrow_forward
Design a function that accepts a list of numbers as an argument. The function should recursively calculate the sum of all the numbers in the list and return that val
arrow_forward
Instructions:
In the code editor, you are provided with a main() function that asks the user for a string and passes this string and the size of this string to a function call of the function, preserveString().
This preserveString() function has the following description:
Return type - void
Name - preserveString
Parameters
The string
Length of the string
Description - this is a recursive function that prints the string repeatedly. Each time it prints the string, it excludes the last character of the string until only one character is left.
This preserveString() function has already been partially implemented. Your only task is to add the recursive case of this function.
Please Finish the code ASAP:
This is my current given code:
#include<stdio.h>#include<string.h>
#define STR_MAX_SIZE 100
void preserveString(char*, int);
int main(void) { char str[STR_MAX_SIZE];
printf("Enter string: "); fgets(str, STR_MAX_SIZE, stdin);
preserveString(str,…
arrow_forward
emacs/lisp function
Write a function that takes one parameter that is a list of numbers and returns true (t) if all the elements of the list are multiples of the first one and nil otherwise.
arrow_forward
python
arrow_forward
c++
arrow_forward
Multiples of ten in a list
(python) Write a program that reads a list of integers, and outputs whether the list contains all multiples of 10, no multiples of 10, or mixed values. Define a function named is_list_mult10 that takes a list as a parameter, and returns a boolean that represents whether the list contains all multiples of ten. Define a function named is_list_no_mult10 that takes a list as a parameter and returns a boolean that represents whether the list contains no multiples of ten.
Then, write a main program that takes an integer, representing the size of the list, followed by the list values. The first integer is not in the list.
Ex: If the input is:
5
20
40
60
80
100
the output is:
all multiples of 10
Ex: If the input is:
5
11
-32
53
-74
95
the output is:
no multiples of 10
Ex: If the input is:
5
10
25
30
40
55
the output is:
mixed values
The program must define and call the following two functions. is_list_mult10() returns true if all integers in the list are multiples…
arrow_forward
C++ - Vowels and Consonants
arrow_forward
In C++
Write a recursive function that displays a string reversely on the console using the following header:void reverseDisplay(const string& s) For example, reverseDisplay("abcd") displays dcba. Write a test programthat prompts the user to enter a string and displays its reversal.
arrow_forward
C code blocks
Implement a function which receives a character array and determines if the word is a palindrome or not. A palindrome is a string that is spelt the same way forwards and backwards (see the example below). The function should return 1 if the character array is a palindrome and 0 if it is not. Write the entire function in the space below. Your answer should not include the function prototype, the main function or any include statements. The function should not contain any printf statements.
Define your function in the same way as the given function prototype.
Function prototype:
int palindrome(char a[]);
For example:
Input
Result
hello
0
radar
1
acca
1
arrow_forward
C programing number of characters question
int NumDistinctChar(char x[]){
}
(like this)
arrow_forward
C++ Format Please
Write a function (named "Lookup") that takes two const references to vectors. The first vector is a vector of strings. This vector is a list of words. The second parameter is a list of ints. Where each int denotes an index in the first vector. The function should return a string formed by concatenated the words (separated by a space) of the first vector in the order denoted by the second vector.
Input of Test Case provided in PDF:
arrow_forward
5. use c code to Write a stringSearch function that gets two strings one called needle and the other called haystack. It then searches in the Haystack for the needle. If it finds it, it returns the index of where the needle starts in the haystack. If the needle cannot be found, it should return -1
Prototype: int stringSearch(char needle[], char haystack)
Example1:
Haystack: “This is just an example”
Needle: “just”
Result: 8
Example2:
Haystack: “This is just an example”
Needle: “This”
Result: 0
Example3:
Haystack: “This is just an example”
Needle: “this”
Result: -1
Hint: all the answer need to include an output and use c code to answer
arrow_forward
Part 3
plase skip it if you dont know the correct answer i need it urgent. Will doewnvote in case of wrong or copied answers from chegg or bartleby!
A regular expression (shortened as regex or regexp; also referred to as rational expression) is a sequence of characters that specifies a search pattern. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation.
using regex create a python program to verify the string having each word start from 'f'? It should return True otherwise false.
arrow_forward
Don't copy. Posted answer is wrong
arrow_forward
C Programming Language
Write a function that takes 2 strings, word1 and word2 as parameters. The function must return if,starting from word1, by only deleting some characters you can get word2.Example: word1: pineapple and word2:nap result: true; word1: orange, word2: one; results: true;word1: cyberspace; word2: peace, result: false
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Related Questions
- String Pair // Problem Description // One person hands over the list of digits to Mr. String, But Mr. String understands only strings. Within strings also he understands only vowels. Mr. String needs your help to find the total number of pairs which add up to a certain digit D. // The rules to calculate digit D are as follow // Take all digits and convert them into their textual representation // Next, sum up the number of vowels i.e. {a, e, i, o, u} from all textual representation // This sum is digit D // Now, once digit D is known find out all unordered pairs of numbers in input whose sum is equal to D. Refer example section for better understanding. // Constraints // 1 <= N <= 100 // 1 <= value of each element in second line of input <= 100 // Number 100, if and when it appears in input should be converted to textual representation as hundred and not as one hundred. Hence number…arrow_forwardExercise Objectives Problem Description Write a program that reads a string and mirrors it around the middle character. Examples: abcd becomes cdab. abcde becomes deCab AhmadAlami becomes AlamiAhmad Page 1 of 2 Your program must: • Implement function void reflect (char* str) which receives a string (array of characters) and mirrors it. This function does not print anything. • Read from the user (in main()) a string and then print the string after calling function reflect(). • Use pointers and pointer arithmetic only. The use of array notation and/or functions from the string.h library is not allowed.arrow_forwardremove_substring_from_string(s, substr): This function takes two strings s and substr as input. It creates a new string from the original string s by removing all instances, if any, of the string substr, and then returns the new string. >>> remove_substring_from_string("Python is best language except for C++. except for C++") 'Python is best language. 'arrow_forward
- vowelIndex Write a function vowelIndex that accepts a word (a str) as an argument and returns the index of the first vowel in the word. If there is no vowel, -1 is returned. For this problem, both upper and lower case vowels count, and 'y' is not considered to be a vowel. Sample usage: >>> vowelIndex('hello') 1 >>> vowelIndex('string') 3 >>> vowelIndex('string') 3 >>> vowelIndex('BUY') 1 >>> vowelIndex('APPLE') 0 >>> vowelIndex('nymphly') -1 >>> vowelIndex('string')==3 True >>> vowel Index ('nymphly')==-1 Truearrow_forwardObjective: string and character manipulation, string.h and ctype.h libraries For each of the problems, create a user-defined function. Then write a driver program for the functions inside the main. 1- Write a function that takes a word less than 25 characters long and returns the letter that word starts with (in capital letters). 2- Write a function that has a string as formal parameter. The function then replaces all spaces and punctuation marks in the string with the asterisk (*). 3- Write a function that takes as input one line and reverses the words of the line 4- Write a function that takes nouns (a string) as inputs and forms their plurals based on these rules: a. If noun ends in “y”, remove the “y” and add “ies”. b. If noun ends in “s”, “ch”, or “sh”, add “es”. c. In all other cases, just add “s”. Now create the driver program - Ask the user for their first and last name. Store the names in separate arrays. - Greet the user by their full names. - Let them know what their…arrow_forwardIn c++arrow_forward
- Question > Not complete Marked out of 1.50 Flag question Previous page Write a recursive function named get_palindromes (words) that takes a list of words as a parameter. The function should return a list of all the palindromes in the list. The function returns an empty list if there are no palindromes in the list or if the list is empty. For example, if the list is ["racecar", "hello", "noon", "goodbye"], the function should return ["racecar", "noon"]. A palindrome is a word that is spelled the same forwards and backwards. Note: The get_palindromes() function has to be recursive; you are not allowed to use loops to solve this problem. For example: Test words = ["racecar", "hello", "noon", "goodbye", "test", 'aibohphobia'] ['racecar', 'noon', 'aibohphobia'] print (get_palindromes (words)) print (get_palindromes ([])) print (get_palindromes (['this', 'is', 'test'])) Answer: (penalty regime: 0, 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 %) Result Precheck Check [] [] Next pagearrow_forwardPyth codearrow_forwardWrite a function recursively_count_vowels() which accepts a pointer to a string, and any other parameters you see fit, and recursively counts the number of vowels in the provided string. This function should return the number of vowels in the string. (programming language c)arrow_forward
- String Manipulation In this question, you will be implementing the following functions int findChar(char * str, char c); Searches for the character c in the string str and returns the index of the character in the string. If the character does not exist, returns -1 int replaceChar(char * str, char c1, char c2); Searches for the character c1 in the string str and if found, replace it with c2.The function returns the number of replacements it has performed. If the character does not exist, returns 0. int removeChar(char * str1, char * str2, char c); Creates a copy of str1 into str2 except for the character c that should be replaced with ‘*’ For example, if str1=”Hello World” and c=’l’ then the function should make str2=”He**o Wor*d” int isPalindrome(char * str) Checks to see if a string is Palindrome(reversible). If it is, returns 1, otherwise returns 0. A palindrome string reads similarly from left to right and from right to left like madam, level, radar, etc. int reverseString(char…arrow_forwardC++ Code: DNA Sequence The main() function is already written for you. You will implement the function int numOccurrences(string& STR, string& sequence). Without even understanding what functions do in C++, all you need to know, at this point, is that you have access to the string STR of which you have to find the length of the largest consecutive occurrence in the string sequence. For example, if input sequence is: AGACGGGTTACCATGACTATCTATCTATCTATCTATCTATCTATCTATCACGTACGTACGTATCGAGATAGATAGATAGATAGATCCTCGACTTCGATCGCAATGAATGCCAATAGACAAAA then numOccurrences("AGAT", sequence) should return 5 numOccurrences("TATC", sequence) should return 8 if input sequence is: AACCCTGCGCGCGCGCGATCTATCTATCTATCTATCCAGCATTAGCTAGCATCAAGATAGATAGATGAATTTCGAAATGAATGAATGAATGAATGAATGAATG then numOccurrences("AATG", sequence) should return 7 numOccurrences("TATC", sequence) should return 4 if input sequence is:…arrow_forwardC++arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning