icon

Usetutoringspotscode to get 8% OFF on your first order!

Fuunctions and stub

Fuunctions and stub

1. Your task is to write a C++ program which performs one of three operations based

on the input values. Once again we will only input integers. All of the inputs will

be non-negative. This program will run in a loop, asking the user for values, making

computations, printing results, until the user inputs the sentinel value of -9999.

(a) Your program will prompt the user for a non-negative integer.

This prompt and input MUST be done with a function.

If the user inputs a negative value that is not the sentinel value you will

display the prompt again and read another value until either a non-negative

value is input or the sentinel value is input.

This function will have no arguments (void).

It will return an integer.

Its prototype is exactly

int myPrompt( void );

The return value will be either a non-negative integer or the sentinel value.

(b) If the user inputs a value from 10 to 50 (inclusive), then you will compute the

sum of the numbers between 1 and the input value.

This computation MUST be done with a function.

This function will take as an argument a single integer.

It will return an integer.

Its prototype is exactly

int mySum( int );

(c) If the user inputs a non-negative value less than 10, then you will compute the

product of the values between 1 and the number.

This computation MUST be done with a function.

This function will take as an argument a single integer.

It will return an integer.

Its prototype is exactly

int myProd( int );

Note that if the user enters 0, the result should still be 1.

(d) If the user inputs a value greater than 50, then you will compute the remainder

of that value divided by 13.

This computation MUST be done with a function

This function will take as an argument a single integer

It will return an integer.

Its prototype is exactly

int myMod( int );

(e) Once you have made a computation, you will print the result. This print out

will be one of

1. The sum from 1 to 13 is 91

2. The product from 1 to 7 is 5040

3. The remainder of 68 / 13 is 3

This output MUST be all generated by a function.

This function will take as arguments two integers. The rst argument will

be used to determine which output line to print. The second argument is

actual value that is being printed.

It will return void.

Its prototype is exactly

void myPrint( int, int );

(f) All of the function prototypes will be before main().

(g) There will be NO global variables. All the information the functions need or

supply will be in their arguments or return values.

(h) All of the function denitions will occur after main().

Should look like

Enter a non-negative integer (-9999 to end): 8

The product from 1 to 8 is 40320

Enter a non-negative integer (-9999 to end): 9

The product from 1 to 9 is 362880

Enter a non-negative integer (-9999 to end): 10

The sum from 1 to 10 is 55

Enter a non-negative integer (-9999 to end): 11

The sum from 1 to 11 is 66

Enter a non-negative integer (-9999 to end): 12

The sum from 1 to 12 is 78

Enter a non-negative integer (-9999 to end): 13

The sum from 1 to 13 is 91

Enter a non-negative integer (-9999 to end): 50

The sum from 1 to 50 is 1275

Enter a non-negative integer (-9999 to end): 51

The remainder of 51 / 13 is 12

Enter a non-negative integer (-9999 to end): 52

The remainder of 52 / 13 is 0

Enter a non-negative integer (-9999 to end): -9878

Enter a non-negative integer (-9999 to end): 0

The product from 1 to 0 is 1

Enter a non-negative integer (-9999 to end): 1

The product from 1 to 1 is 1

Enter a non-negative integer (-9999 to end): 2

The product from 1 to 2 is 2

Enter a non-negative integer (-9999 to end): 3

The product from 1 to 3 is 6

Enter a non-negative integer (-9999 to end): -9999

You can leave a response, or trackback from your own site.

Leave a Reply

Fuunctions and stub

Fuunctions and stub

1. Your task is to write a C++ program which performs one of three operations based

on the input values. Once again we will only input integers. All of the inputs will

be non-negative. This program will run in a loop, asking the user for values, making

computations, printing results, until the user inputs the sentinel value of -9999.

(a) Your program will prompt the user for a non-negative integer.

This prompt and input MUST be done with a function.

If the user inputs a negative value that is not the sentinel value you will

display the prompt again and read another value until either a non-negative

value is input or the sentinel value is input.

This function will have no arguments (void).

It will return an integer.

Its prototype is exactly

int myPrompt( void );

The return value will be either a non-negative integer or the sentinel value.

(b) If the user inputs a value from 10 to 50 (inclusive), then you will compute the

sum of the numbers between 1 and the input value.

This computation MUST be done with a function.

This function will take as an argument a single integer.

It will return an integer.

Its prototype is exactly

int mySum( int );

(c) If the user inputs a non-negative value less than 10, then you will compute the

product of the values between 1 and the number.

This computation MUST be done with a function.

This function will take as an argument a single integer.

It will return an integer.

Its prototype is exactly

int myProd( int );

Note that if the user enters 0, the result should still be 1.

(d) If the user inputs a value greater than 50, then you will compute the remainder

of that value divided by 13.

This computation MUST be done with a function

This function will take as an argument a single integer

It will return an integer.

Its prototype is exactly

int myMod( int );

(e) Once you have made a computation, you will print the result. This print out

will be one of

1. The sum from 1 to 13 is 91

2. The product from 1 to 7 is 5040

3. The remainder of 68 / 13 is 3

This output MUST be all generated by a function.

This function will take as arguments two integers. The rst argument will

be used to determine which output line to print. The second argument is

actual value that is being printed.

It will return void.

Its prototype is exactly

void myPrint( int, int );

(f) All of the function prototypes will be before main().

(g) There will be NO global variables. All the information the functions need or

supply will be in their arguments or return values.

(h) All of the function denitions will occur after main().

Should look like

Enter a non-negative integer (-9999 to end): 8

The product from 1 to 8 is 40320

Enter a non-negative integer (-9999 to end): 9

The product from 1 to 9 is 362880

Enter a non-negative integer (-9999 to end): 10

The sum from 1 to 10 is 55

Enter a non-negative integer (-9999 to end): 11

The sum from 1 to 11 is 66

Enter a non-negative integer (-9999 to end): 12

The sum from 1 to 12 is 78

Enter a non-negative integer (-9999 to end): 13

The sum from 1 to 13 is 91

Enter a non-negative integer (-9999 to end): 50

The sum from 1 to 50 is 1275

Enter a non-negative integer (-9999 to end): 51

The remainder of 51 / 13 is 12

Enter a non-negative integer (-9999 to end): 52

The remainder of 52 / 13 is 0

Enter a non-negative integer (-9999 to end): -9878

Enter a non-negative integer (-9999 to end): 0

The product from 1 to 0 is 1

Enter a non-negative integer (-9999 to end): 1

The product from 1 to 1 is 1

Enter a non-negative integer (-9999 to end): 2

The product from 1 to 2 is 2

Enter a non-negative integer (-9999 to end): 3

The product from 1 to 3 is 6

Enter a non-negative integer (-9999 to end): -9999

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Fuunctions and stub

Fuunctions and stub

1. Your task is to write a C++ program which performs one of three operations based

on the input values. Once again we will only input integers. All of the inputs will

be non-negative. This program will run in a loop, asking the user for values, making

computations, printing results, until the user inputs the sentinel value of -9999.

(a) Your program will prompt the user for a non-negative integer.

This prompt and input MUST be done with a function.

If the user inputs a negative value that is not the sentinel value you will

display the prompt again and read another value until either a non-negative

value is input or the sentinel value is input.

This function will have no arguments (void).

It will return an integer.

Its prototype is exactly

int myPrompt( void );

The return value will be either a non-negative integer or the sentinel value.

(b) If the user inputs a value from 10 to 50 (inclusive), then you will compute the

sum of the numbers between 1 and the input value.

This computation MUST be done with a function.

This function will take as an argument a single integer.

It will return an integer.

Its prototype is exactly

int mySum( int );

(c) If the user inputs a non-negative value less than 10, then you will compute the

product of the values between 1 and the number.

This computation MUST be done with a function.

This function will take as an argument a single integer.

It will return an integer.

Its prototype is exactly

int myProd( int );

Note that if the user enters 0, the result should still be 1.

(d) If the user inputs a value greater than 50, then you will compute the remainder

of that value divided by 13.

This computation MUST be done with a function

This function will take as an argument a single integer

It will return an integer.

Its prototype is exactly

int myMod( int );

(e) Once you have made a computation, you will print the result. This print out

will be one of

1. The sum from 1 to 13 is 91

2. The product from 1 to 7 is 5040

3. The remainder of 68 / 13 is 3

This output MUST be all generated by a function.

This function will take as arguments two integers. The rst argument will

be used to determine which output line to print. The second argument is

actual value that is being printed.

It will return void.

Its prototype is exactly

void myPrint( int, int );

(f) All of the function prototypes will be before main().

(g) There will be NO global variables. All the information the functions need or

supply will be in their arguments or return values.

(h) All of the function denitions will occur after main().

Should look like

Enter a non-negative integer (-9999 to end): 8

The product from 1 to 8 is 40320

Enter a non-negative integer (-9999 to end): 9

The product from 1 to 9 is 362880

Enter a non-negative integer (-9999 to end): 10

The sum from 1 to 10 is 55

Enter a non-negative integer (-9999 to end): 11

The sum from 1 to 11 is 66

Enter a non-negative integer (-9999 to end): 12

The sum from 1 to 12 is 78

Enter a non-negative integer (-9999 to end): 13

The sum from 1 to 13 is 91

Enter a non-negative integer (-9999 to end): 50

The sum from 1 to 50 is 1275

Enter a non-negative integer (-9999 to end): 51

The remainder of 51 / 13 is 12

Enter a non-negative integer (-9999 to end): 52

The remainder of 52 / 13 is 0

Enter a non-negative integer (-9999 to end): -9878

Enter a non-negative integer (-9999 to end): 0

The product from 1 to 0 is 1

Enter a non-negative integer (-9999 to end): 1

The product from 1 to 1 is 1

Enter a non-negative integer (-9999 to end): 2

The product from 1 to 2 is 2

Enter a non-negative integer (-9999 to end): 3

The product from 1 to 3 is 6

Enter a non-negative integer (-9999 to end): -9999

Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by WordPress | Designed by: Premium WordPress Themes | Thanks to Themes Gallery, Bromoney and Wordpress Themes