Question

In: Computer Science

Using cs Cstring and c character as arguments in functiuon strfind(cs,c). The function should return the...

Using cs Cstring and c character as arguments in functiuon strfind(cs,c). The function should return the index of wanted letter in string. For example, strfind("hello world", 'o') would return 4. If the character is not found, the funtion returns -1. Please code in c++

Solutions

Expert Solution

#include <iostream>

using namespace std;
int strfind(string cs,char c){
int i=0;
int l=0;
while(cs[i]!='\0'){//finding the length of the string cs
l++;
i++;
}
for(i=0;i<l;i++){//for each character of string cs
if(cs[i]==c)//if character is found return i
return i;
}
return -1;//return -1 if character is not found
}
int main()
{
cout<<strfind("hello world", 'o');
return 0;
}

Screenshots:

The screenshots are attached below for reference.

Please follow them for proper output.

Please upvote my answer .

Thank you.


Related Solutions

Please, write this code in c++. Using iostream and cstring library. Write a function that will...
Please, write this code in c++. Using iostream and cstring library. Write a function that will delete all words in the given text that meets more that one time. Also note than WORD is sequence of letters sepereated by whitespace. Note. The program have to use pointer. Input: First line contains one line that is not longer than 1000 symbols with whitespaces. Each word is not longer than 30 symbols. Output: Formatted text. example: input: Can you can the can...
Please, write code in c++. Using iostream and cstring library Write a function that will find...
Please, write code in c++. Using iostream and cstring library Write a function that will find and return most recent word in the given text. The prototype of the function have to be the following void mostRecent(char *text,char *word) In char *word your function have to return the most recent word that occurce in the text. Your program have to be not case-sensitive(ignore case - "Can" and "CAN" are the same words) Also note than WORD is sequence of letters...
***IN C++*** Create student structure with the following fields:  Name (cstring or null-terminated character array)...
***IN C++*** Create student structure with the following fields:  Name (cstring or null-terminated character array)  Student ID (int – unique random value between 1000 and 9999)  grade (char – Values A thru F)  birthday (myDate – random value: range 1/1/2000 to 12/31/2005)  Home Town (string) Create an array of pointers to students of size 10. Example: Student *stuPtr[10]; Write a function that populates the array with 10 students. Example: populate(stuPtr); Write a display function that...
Write a function in JAVASCRIPT that accepts two arguments (a string array and a character). The...
Write a function in JAVASCRIPT that accepts two arguments (a string array and a character). The function will check each character of the strings in the array and removes the character, regardless of case. If the first letter of the string is removed the next letter must be capitalized. Your function would return the result as one string, where each element of array is separated by comma. E.G. function([“John”,”Hannah”,”Saham”], “h”); // returns ‘Jon,Anna,Saam Use of any built in string function...
In C++, cstring is implemented as an array of characters. What is the difference between cstring...
In C++, cstring is implemented as an array of characters. What is the difference between cstring and a regular array of characters? In other words, how do you distinguish them?
Requirements: C++ Array/File Functions Write a function named arrayToFile. The function should accept 3 arguments: The...
Requirements: C++ Array/File Functions Write a function named arrayToFile. The function should accept 3 arguments: The name of the file, a pointer to an array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to file, and then close the file. Write another function named fileToArray. This function should accept 3 arguments: the name of the file, a pointer, to an int array, and the size of...
Language C++ Thank You! -Write a function getMeASentence() that takes zero arguments, and its return type...
Language C++ Thank You! -Write a function getMeASentence() that takes zero arguments, and its return type is string. This function will return a randomly generated sentence that abides by certain rules. -The rules of this sentence are that there are 5 randomly generated lowercase letters, a space, a randomly generated inequality symbol, a space, and a randomly generated 1 digit number. -In this context, an inequality symbol is understood to mean the "<", ">", or "=" symbol. -Write a function...
C++ Develop program in C++ using arrays of characters, subscript operator, the cstring library, and functions...
C++ Develop program in C++ using arrays of characters, subscript operator, the cstring library, and functions with arguments. Create programs with small functions where main goes to a series of functions where the real work takes place. Don’t use global variables and don’t use break within a loop (unless working with a switch statement). Functions can’t have more than 30 statements of code, not including comments, blank lines, or variable definitions. Don’t use a return in the middle of the...
Using C++: Write a function that recursively calculates the sum of an array. The function should...
Using C++: Write a function that recursively calculates the sum of an array. The function should have 2 parameters, the array and an integer showing the number of elements (assume they are all integers) in the array. The function will use a recursive call to sum the value of all elements. You must prompt for a series of integers to be entered in the array. As your program reads the numbers in, increment a count so it knows how many...
in Python3 The ord function in Python takes a character and return an integer that represents...
in Python3 The ord function in Python takes a character and return an integer that represents that character. It does not matter what the integer representing the character actually is, but what matters is this: ord('a') is 1 less than ord('b'), so that: x=ord('a') thisLetter = x+1 # thisLetter is the ord('b') This is a powerful fact that is used in encryption techniques, so data transferred over the web is 'ciphered so it is unreadable to others. To decipher data,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT