Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

W3 A box of cookies can hold 24 cookies, and a container can hold 75 boxes of cookies. Include a program that prompts the user

W3

A box of cookies can hold 24 cookies, and a container can hold 75 boxes of cookies.

Include a program that prompts the user to enter:

The total number of cookies

The program then outputs:

The number of boxes and the number of containers to ship the cookies.

Note that each box must contain the specified number of cookies, and each container must contain the specified number of boxes. If the last box of cookies contains less than the number of specified cookies, you can discard it and output the number of leftover cookies.

Similarly, if the last container contains less than the number of specified boxes, you can discard it and output the number of leftover boxes.

The roots of the quadratic equation ax + bx + c = 0, a 0 are given by the following formula:

Quadratic Formula

In this formula, the term b - 4ac is called the discriminant. If b - 4ac = 0, then the equation has a single (repeated) root. If b - 4ac > 0, the equation has two real roots. If b - 4ac < 0, the equation has two complex roots.

Instructions

Include a program that prompts the user to input the value of:

a (the coefficient of x)

b (the coefficient of x)

c (the constant term)

The program then outputs the type of roots of the equation, utilizing pow.

Furthermore, if b - 4ac 0, the program should output the roots of the quadratic equation.

a program that mimics a calculator. The program should take as input:

The first integer

The second integer

The operation to be performed (+, -, *, /)

It should then output the numbers, the operator, and the result. (For division, if the denominator is zero, output an appropriate message. The message should contain the word "error")

Some sample outputs follow:

3 + 4 = 7

13 * 5 = 65

4.9

a program that mimics a calculator. The program should take as input:

Two floating-point numbers

The operation to be performed (+, -, /, *).

It should then output the numbers, the operator, and the result.

Additional notes:

Format output to two decimal places.

For division, if the denominator is zero, output an appropriate message. The message should contain the word "error"

Some sample outputs follow:

3.5 + 4.0 = 7.50

13.973 * 5.65 = 78.95

Redo Programming Exercise 18 of Chapter 2, taking into account that your parents buy additional savings bonds for you as follows:

a. If you do not spend any money to buy savings bonds, then because you had a summer job, your parents buy savings bonds for you in an amount equal to 1% of the money you save after paying taxes and buying clothes, other accessories, and school supplies.

b. If you spend up to 25% of your net income to buy savings bonds, your parents spend $0.25 for each dollar you spend to buy savings bonds, plus money equal to 1% of the money you save after paying taxes and buying clothes, other accessories, and school supplies.

c. If you spend more than 25% of your net income to buy savings bonds, your parents spend $0.40 for each dollar you spend to buy savings bonds, plus money equal to 2% of the money you save after paying taxes and buying clothes, other accessories, and school supplies.

The program should prompt the user to enter:

The pay rate for an hour

The number of hours you worked each week.

The percent of net income spent to buy savings bonds

The program then outputs the following:

Your income before and after taxes from your summer job.

The money you spend on clothes and other accessories.

The money you spend on school supplies.

The money you spend to buy savings bonds.

The money your parents spend to buy additional savings bonds for you.

Since your program handles currency, make sure to use a data type that can store decimals with a decimal precision of 2.

Instructions for Programming Exercise 18 of Chapter 2 have been posted below for your convenience.

Exercise 18

You found an exciting summer job for five weeks. It pays, say, $15.50 per hour. Suppose that the total tax you pay on your summer job income is 14%.

After paying the taxes, you spend 10% of your net income to buy new clothes and other accessories for the next school year and 1% to buy school supplies.

After buying clothes and school supplies, you use 25% of the remaining money to buy savings bonds. For each dollar you spend to buy savings bonds, your parents spend $0.50 to buy additional savings bonds for you

5.1

a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits.

For example, it should output the individual digits of:

3456 as 3 4 5 6

8030 as 8 0 3 0

2345526 as 2 3 4 5 5 2 6

4000 as 4 0 0 0

-2345 as 2 3 4 5

The value of can be approximated by using the following series:

Series to approximate pi

The program below uses this series to find the approximate value of . However, the statements are in the incorrect order, and there is also a bug in this program.

Rearrange the statements and remove the bug so that this program can be used to approximate .

#include

#include

using namespace std;

int main()

{

double pi = 0;

long i;

long n;

cin >> n;

cout << "Enter the value of n: ";

cout << endl;

if (i % 2 == 0)

pi = pi + (1 / (2 * i + 1));

else

pi = pi - (1 / (2 * i + 1));

for (i = 0; i < n; i++)

{

pi = 0;

pi = 4 * pi;

}

cout << endl << "pi = " << pi << endl;

return 0;

The program Telephone Digits outputs only telephone digits that correspond to uppercase letters.

Rewrite the program so that it processes both uppercase and lowercase letters and outputs the corresponding telephone digit.

If the input is something other than an uppercase or lowercase letter, the program must output an appropriate error message (The error message should contain the phrase Invalid input).

//**********************************************************

// Program: Telephone Digits

// This is an example of a sentinel-controlled loop. This

// program converts uppercase letters to their corresponding

// telephone digits.

//**********************************************************

#include

using namespace std;

int main()

{

char letter;

int digit, num;

cout << "Program to convert uppercase letters to "

<< "their corresponding telephone digits."

<< endl;

cout << "To stop the program enter #." << endl;

cout << "Enter an uppercase letter: ";

cin >> letter;

cout << endl;

while (letter != '#')

{

cout << "Letter: " << letter;

cout << ", Corresponding telephone digit: ";

num = static_cast(letter)

- static_cast('A');

if (0 <= num && num < 26)

{

digit = (num / 3) + 2;

if (((num / 3 == 6 ) || (num / 3 == 7))

&& (num % 3 == 0))

digit = digit - 1;

if (digit > 9)

digit = 9;

cout << digit << endl;

}

else

cout << "Invalid input." << endl;

cout << " Enter another uppercase "

<< "letter to find its corresponding "

<< "telephone digit." << endl;

cout << "To stop the program enter #."

<< endl;

cout << "Enter a letter: ";

cin >> letter;

cout << endl;

} //end while

return 0;

}

a program that uses do...while loops to perform the following steps:

Prompt the user to input two integers: firstNum and secondNum

(firstNum must be less than secondNum).

Output all odd numbers between firstNum and secondNum.

Output the sum of all even numbers between firstNum and secondNum.

Output the numbers and their squares between 1 and 10.

Separate the numbers by any amount of spaces.

Output the sum of the square of the odd numbers between firstNum and secondNum.

Output all uppercase letters.

The program in the Programming Example: Fibonacci Number does not check:

Whether the first number entered by the user is less than or equal to the second number and whether both the numbers are nonnegative.

Whether the user entered a valid value for the position of the desired number in the Fibonacci sequence.

fix the program so that it checks for these things.

NOTES:

If an invalid number is entered for case 1 above, prompt the user to enter both numbers again.

If an invalid number is entered for case 2, prompt the user to enter a value until a valid value is entered

#include

using namespace std;

int main()

{

//Declare variables

int previous1;

int previous2;

int current;

int counter;

int nthFibonacci;

cout << "Enter the first two Fibonacci numbers: "; //Step 1

cin >> previous1 >> previous2; //Step 2

cout << endl;

cout << "The first two Fibonacci numbers are " << previous1 << " and " << previous2 << endl; //Step 3

cout << "Enter the position of the desired Fibonacci number: " ; //Step 4

cin >> nthFibonacci; //Step 5

cout << endl;

if (nthFibonacci == 1) //Step 6.a

current = previous1;

else if (nthFibonacci == 2) //Step 6.b

current = previous2;

else //Step 6.c

{

counter = 3;

//Steps 6.c.2 - 6.c.5

while (counter <= nthFibonacci)

{

current = previous2 + previous1;

previous1 = previous2;

previous2 = current;

counter++;

}//end while

}//end else

/* Output the Fibonacci number at nth position */

return 0;

}//end main

Let n be an integer. The value of the expression: Limit equation for e

is written as e. This number e appears in many places in mathematics.

For example, it appears in the formula A = Pert to compute the total amount accumulated when the interest is compounded continuously.

It also appears in problems relating to exponential growth and decay. It is known that e is an irrational number.

The value of e to nine decimal places is e = 2.718281827.

Instructions

Include a program that computes the value of the expression:

Limit equation for e

between certain values of n and then compare the values with e.

For example, you can compute the values of the expression between:

100 and 10,000 with an increment of 100

or between 1,000 and 1,000,000 with an increment of 1,000.

The program should accept as input:

The start value for n

The end value for n

(Note: The increment value of 100 should be hardcoded in the program upon final submission.)

The program should then output the value of the expression for each value of n in the specified range with a decimal precision of 8.

If you decide to format your output with setw, use a value of at least 15 to ensure that your outputs don't get mashed together!

(Chapter 5) defines the number e. The value of e can be approximated using the following expression:

Approximation of e

where n is a positive integer.

Include a program that prompts the user for the value of n.

The program then uses the formula above to approximate the value of e.

Test program for n = 4, 8, 10, and 12.

Format your output with setprecision(15) to ensure the proper number of decimals for testing!

defines the number e and shows how to approximate the value of e using a different expression.

Interestingly, the value of e can also be approximated using the following expression:

a program that uses this formula to approximate the value of e.

The program should prompt the user to input a value for n and then output the approximate value of e. Use setprecision(15) to format the output for the tests.

Test program for n = 3, 5, 10, 50, and 100.

_________________________________________________________________________________

5.33

Bianca is preparing special dishes for her daughter's birthday.

It takes her a minutes to prepare the first dish, and each following dish takes b minutes longer than the previous dish. She has t minutes to prepare the dishes.

For example, if the first dish takes a = 10 minutes and b = 5, then the second dish will take 15 minutes, the third dish will take 20 minutes, and so on.

If she has 80 minutes to prepare the dishes, then she can prepare four dishes because 10 + 15 + 20 + 25 = 70.

A program that prompts the user to enter the values of a, b, and t, and outputs the number of dishes Bianca can prepare.

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

Step: 3

blur-text-image

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions