Question

Write a function removeEggs to remove eggs from an egg carton that holds up to 12...

Write a function removeEggs to remove eggs from an egg carton that holds up to 12 eggs. The function has two parameters – the current number of eggs in the egg carton and the number of eggs to remove. The function should return true when the remove function is successful. When the remove function fails, the number of eggs in the egg carton should not change and returns false. Need it written in c++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

bool removeEggs(int & currentEggs,int eggsToRemove)//passing by reference to make changes to reflect in the main
{
if (eggsToRemove>currentEggs)
{
return false;
}
else
{
currentEggs-=eggsToRemove;
return true;
}
}

Add a comment
Know the answer?
Add Answer to:
Write a function removeEggs to remove eggs from an egg carton that holds up to 12...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • COSC 112 Test #3 Spring 2019 20. It is not necessary to specify the parameter name...

    COSC 112 Test #3 Spring 2019 20. It is not necessary to specify the parameter name in the parameter list of a function prototype even 21. Which of following is not a situation when reference parameters are useful? though there is a default parameter. (True/False) a. When you don't want to have side effects b. When you need to change the actual parameter c. When you need to return more than one value d. When you want to save memory...

  • Make a public class called ManyExamples and in the class... Write a function named isEven which...

    Make a public class called ManyExamples and in the class... Write a function named isEven which takes in a single int parameter and returns a boolean. This function should return true if the given int parameter is an even number and false if the parameter is odd. Write a function named close10 which takes two int parameters and returns an int. This function should return whichever parameter value is nearest to the value 10. It should return 0 in the...

  • To produce cake, you need eggs E and premixed ingredients I. Each cake needs exactly two eggs and one package of i...

    To produce cake, you need eggs E and premixed ingredients I. Each cake needs exactly two eggs and one package of ingredients. When you add three eggs to one package of ingredients, you still produce only one cake. Similarly, when you add two packages of ingredients to two eggs, you still produce only one cake. Please CLEARLY write out each step and make sure your handwriting is LEGABLE. Thank you! Write down the production function that describes the technology of...

  • Write a class named Month. The class should have an int field named monthNumber that holds...

    Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example. January would be 1. February would be 2. and so forth. In addition, provide the following methods A no-arg constructor that sets the monthNumber field to 1 A constructor that accepts the number of the month as an argument. It should set the monthNumber field to the value passed as the argument. If a value less than...

  • Write a function in python that takes a set A and a relation R(x, y) on...

    Write a function in python that takes a set A and a relation R(x, y) on A (as a python function such that R(x, y) returns true if and only if the relation xRy holds), and returns True if and only if the relation R is reflexive. Here is the function signature you need to use. def is reflexive(A, R): You can test your code as follows. s = {1,2,3} def y(x, y): return x == y def n(x, y):...

  • (C++) Write a function, remove, that takes three parameters: an array of integers, the number of...

    (C++) Write a function, remove, that takes three parameters: an array of integers, the number of elements in the array, and an integer (say, removeItem). The function should find and delete the first occurrence of removeItem in the array. (Note that after deleting the element, the number of elements in the array is reduced by 1.) Assume that the array is unsorted. Also, write a program to test the function. Your program should prompt the user to enter 10 digits...

  • C++ Write a function sleepIn with two parameters 'weekday' and 'vacation'. The parameter 'weekday' is True...

    C++ Write a function sleepIn with two parameters 'weekday' and 'vacation'. The parameter 'weekday' is True if it is a weekday, and the parameter 'vacation' is True if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return True if we can sleep in. function prototype: bool sleepIn(bool weekday, bool vacation): Function Call Function Returns sleepIn(false, false); true OK      sleepIn(true, false); false OK      sleepIn(false, true); true OK      sleepIn(true, true);...

  • Write a function to check if a number is multiple of 3 The function name is...

    Write a function to check if a number is multiple of 3 The function name is isMultipleOf3 The function returns a Bool value The function takes one integer argument The function will check if the number passed in is a multiple of 3. If it is multiple of 3, return true, otherwise return false A number is multiple of 3 if it can be divided by 3 evenly, such as 3, 30, 15, 21, etc. You only need to write...

  • in C++ and also each function has its own main function so please do the main...

    in C++ and also each function has its own main function so please do the main function as well. Previously when i asked the question the person only did the function and didn't do the main function so please help me do it. 1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...

  • Hello. I have written the following function to remove a value from a Binary Search Tree using re...

    Hello. I have written the following function to remove a value from a Binary Search Tree using resources my professors gave and stuff I found online. The problem is I don't know how it works and I need to know how it works to finish the rest of the project. public boolean remove(T value){ if(value == null) return false; class RemoveBSTObj{ private boolean found = false; private Node removeBST(Node root, T value){ if(root == null) return root; //IF there is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT