Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Please provide the code. Question 1 Write a function called setToValue( ... ) that will work with the following section of code. You need

C++ Please provide the code.

Question 1

Write a function called setToValue( ... ) that will work with the following section of code.

You need to write a complete function that will change the value of the first parameter passed into it to the value of the second parameter.

It only needs to work with double types, nothing else.

You don't need to put in the prototype

Only turn in the function you have written, NOT THE WHOLE PROGRAM.

 
#include 
using namespace std;
// assume your answer put is here so you don't need a // prototype declaration  
// nothing in main() can change! int main() { 
 double weight, height, pi, avagadrosNumber;
 
// here are some possible calls to the function you need to write  setToValue(height, 65.7);  setToValue(weight, 210);  setToValue(pi, 3.14156);  setToValue(avagadrosNumber, 6.02e-23);
 
// here's the code that tests the above calls  cout << "This should be 65.7 --> " << height << endl;  cout << "This should be 210 --> " << weight << endl;  cout << "This should be 3.14156 --> " << pi << endl;  cout << "This should be 6.02e-23--> " << avagadrosNumber << endl;
}

Question 2

Write a function called countGenerator( ... ) that will work with the following section of code.

It will take a string parameter and return an integer accord to the following rules:

If the string passed to it is exactly "Red", the function will return a random number from 1 to 4.

If the string passed to it is exactly "Blue", the function will return a random number from 1 to 6.

If the string passed to it is exactly "Green", the function will return a random number from 1 to 8.

If the string passed to it is anything else, the function will return a 0 (zero).

You don't need to put in the prototype.

Only turn in the function you have written, NOT THE WHOLE PROGRAM!

 
#include  #include  #include 
 
using namespace std;
 
// assume your answer is here so you don't need a // prototype declaration// nothing in main() can change!
int main() {  // seed the random number generator  srand(time(0));
 
 
 // test "Red" parameter  cout << "I will now print 20 numbers from 1 to 4:" << endl;  for (int i=0;i<20;i++)  {  cout << countGenerator("Red") << " ";  }  cout << endl;
 
 
 // test "Blue" parameter  cout << "I will now print 20 numbers from 1 to 6:" << endl;  for (int i=0;i<20;i++)  {  cout << countGenerator("Blue") << " ";  }  cout << endl;
 
 
 // test "Green" parameter  cout << "I will now print 20 numbers from 1 to 8:" << endl;  for (int i=0;i<20;i++)  {  cout << countGenerator("Green") << " ";  }  cout << endl;
 
 
 // test the returning a zero if the name isn't valid  cout << "I will now print 5 zeros:" << endl;  cout << countGenerator("green") << " ";  cout << countGenerator("red") << " ";  cout << countGenerator("blue") << " ";  cout << countGenerator("BLUE") << " ";  cout << countGenerator("") << " ";  cout << endl; }

Question 3

Write a function called divisors( ... ) that will work with the following section of code.

It will take three integer parameters and return nothing.

The first pararmeter is the number we are looking for divisors of.

The second parameter is where to start looking

The third parameter is where to stop looking. This number is included in the checking for divisors!

It will print a list of all the divisors of the first number that are between the second and third parameter. (Include those parameters in the check.)

Print the numbers out with a single space between them.

If there are no divisors, nothing will be printed.

The third parameter will always be greater than the second parameter, so you can check from low to high numbers.

You can use the % operator to determine if one number is a divisor of another.

Something is a divisor when there is a remainder or zero when they are divided.

You don't need to put in the prototype

Only turn in the function you have written, NOT THE WHOLE PROGRAM!

#include 
using namespace std;
// assume your answer is here so you don't need a // prototype declaration
 
// nothing in main() can change! int main() { cout << "Divisors of 12 from 1 to 10 "; cout << "(should be 1 2 3 4 6)"; divisors(12, 1, 10); cout << endl;
 
 cout << "Divisors of 24 from 6 to 12 "; cout << "(should be 6 8 12)"; divisors(24, 6, 12); cout << endl;
 
 cout << "Divisors of 100 from 26 to 49 "; cout << "(nothing should be printed )"; divisors(100, 26, 49); cout << endl; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Genomes Browsers And Databases Data Mining Tools For Integrated Genomic Databases

Authors: Peter Schattner

1st Edition

0521711320, 978-0521711326

More Books

Students also viewed these Databases questions

Question

In eukaryotes, what types of modifications occur to pre-mRNAs?

Answered: 1 week ago

Question

What is dividend payout ratio ?

Answered: 1 week ago

Question

Explain the factors affecting dividend policy in detail.

Answered: 1 week ago

Question

Describe your ideal working day.

Answered: 1 week ago