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...
Please write the code in c++ Write a function with one input parameter that is a...
Please write the code in c++ Write a function with one input parameter that is a vector of strings. The function should count and return the number of strings in the vector that have either an 'x' or a 'z' character in them. For example, when the function is called, if the vector argument contains the 6 string values, "enter", "exit", "zebra", "tiger", "pizza", "zootaxy" the function should return a count of 4. ("exit", "zebra", "pizza", and "zootaxy" all have...
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.
Determine the Appropriate Analysis For each of the following scenarios, identify the appropriate analysis. 2. A...
Determine the Appropriate Analysis For each of the following scenarios, identify the appropriate analysis. 2. A guidance counselor at a high school wants to be best informed about the universities and colleges that students prefer most frequently. He glances at the institutions attended by last year’s graduates and notes that the three closet colleges appear to have about equal appeal. To test this assumption, he begins asking students who are planning on postsecondary schooling where they will apply. His data...
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...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT