Question

In: Computer Science

C++ homework URGENT Select ONE of the following scenarios and write an appropriate function to produce...

C++ homework

URGENT

Select ONE of the following scenarios and write an appropriate function to produce the required result.

Please write down which scenarios you have selected (a, b or c).

a) Write a function that will accept a sentence and a letter and the function return will be the number of times the sent letter appears in the sent sentence. Example; if the sentence is "hello world" and the letter is “o” the return value should be 2.

b) OR Write a function that will receive a minimum and maximum value and returns a random number between them. Example; if the minimum value is 5 and and maximum value is 10, the function should return a random number between [5 and 10].

c) OR Write a function that will receive a string value and return a single character response based on user input. The function must validate the user’s input before it returns the user’s response.

Solutions

Expert Solution

Answer b.

rand() function is used in C++ to generate random integers.

rand()%a + b; //here a random number is generated between a and b where a>b.

The function :

int func(int min,int max){
int temp = rand()%max+min;
return(temp);
}

Entire Code :

#include <iostream>

using namespace std;

int func(int min,int max){
int temp = rand()%max+min;
return(temp);
}

int main()
{
int min,max;
cout<<"Enter the smaller number : ";
cin>>min;
cout<<"Enter the larger number : ";
cin>>max;
  
cout<<func(min,max);

return 0;
}


Related Solutions

Select whether a chi-square test for association is the most appropriate for the following scenarios: Most...
Select whether a chi-square test for association is the most appropriate for the following scenarios: Most appropriate or Not appropriate a) Emma wishes to know whether gender has any relation with whether one prefers wine, beer, or liqueur. She surveys a group of men and women and records the number of participants who prefer wine, the number who prefer beer and the number who prefer liqueur. (yes or no) b) Danielle surveys a group of people on how often they...
Select that appropriate terms from the list provided to the following scenarios the best represent each...
Select that appropriate terms from the list provided to the following scenarios the best represent each term. Hint – Each term can only be used once. 1. Lela Yeoman has been asked to lead her audit team in the audit of the Toronto Raptors basketball team. She performed a review of their risks and found that the team’s risks tend to be driven by the nature of certain significant accounts or business activities that the Raptors pursue. Analytical procedures, Computer...
For the following scenarios write an appropriate null and alternative hypothesis and identify what type of...
For the following scenarios write an appropriate null and alternative hypothesis and identify what type of test statistic will be used. (Steps 1 & 3 of the six step hypothesis test.) a. A nationwide sample of influential Republicans and Democrats was asked as part of a comprehensive survey whether they favored lowering environmental standards so that high-sulfur coal could be burned in coal-fired plants. The results were: Republicans Democrats No. Sampled 1100 1400 No. in Favor 115 158 At the...
For which of the following scenarios would it be appropriate to use a one-sample z-test? A....
For which of the following scenarios would it be appropriate to use a one-sample z-test? A. Comparing the average weight of newborns in Hospital A to the average weight of newborns in Hospital B B. Comparing the political affiliation of ASU students against the political affiliation of all college students C. Comparing the number of packs of cigarettes smoked per day by residents of urban areas with the number of cigarettes smoked per day by all persons in the USA...
A. Write a C++ with a menu (using switch) that asks the user to select one...
A. Write a C++ with a menu (using switch) that asks the user to select one of the following choices to the user: 1. Options ‘S’ or ‘s’ 2. Option ‘T’ or ‘t 3. Options ‘P’ or ‘p’ 4. print in the Matrix format B. When 1 is selected, prompt the user to enter the starting value st (int value). Use a single FOR loop to count numbers from 1 to st. When the loop is finished, find the average...
This is for C++ A static main() function defined in your homework assignments means: 1.The function...
This is for C++ A static main() function defined in your homework assignments means: 1.The function is always invisible to all functions outside of the class. 2.The function cannot declare any variables. 3.The function can be called without an instance. 4.The function can access all variables and methods. 5.The function can be called by the superclass.
Write a function in C that takes one argument, an array of 50 elements. Your function...
Write a function in C that takes one argument, an array of 50 elements. Your function should print out the index and value of the smallest element in the array.
Section 1: Scenarios Read the following scenarios and state the appropriate test to analyze the data...
Section 1: Scenarios Read the following scenarios and state the appropriate test to analyze the data from the list of 7 tests below. One-sample t-test Two-way ANOVA Independent-samples t-test Repeated-measures ANOVA Paired-samples t-test Correlation One-way ANOVA Squirrel weight: You are a behavioral ecologist interested in the eating habits of squirrels. You hypothesize that squirrels will eat more when the days are longer (e.g., eat more when there is 12 hours of daylight relative to 8 hours of daylight). You record...
Choose one of the scenarios below and respond in an appropriate way to the prejudiced comment....
Choose one of the scenarios below and respond in an appropriate way to the prejudiced comment. Also, explain why you have chosen to respond as you have. Scenario 1 Background: Two women were hanging out after school and went to get coffee. They were discussing various topics, and the discussion turned to a sibling who is gay. Speaker: The student’s sister (college-aged) Responder: A female college student Comment: "I don’t know if I can hang out with Kate in public...
C++ Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following...
C++ Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following order: An array of integer values (array1). An integer representing the size of array1 (size1). An array of integer values (array2). An integer representing the size of array2 (size). The function creates a dynamic array of integers of size size1+size2 to store all the values in array1, followed by all the values in array2. The function returns the pointer used to create the dynamic...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT