Question

Assignment 6: Recursion Learning Outcomes • Learn how to craft solutions using recursion instead of loops....

Assignment 6: Recursion
Learning Outcomes
• Learn how to craft solutions using recursion instead of loops.
Instructions
This assignment will be different than previous assignments (and most assignments which come after it). In this assignment, you will be crafting four solutions to four different problems.
This assignment will also have special requirements regarding how you may code. You are not allowed to use assignment statements. This includes using preincement, postincrement, predecrement, and postdecrement. You are allowed to use assignment to initialize variables and this is the only exception. Thus,
int x = 2; // This is allowed.
x = 3; // This is not allowed.
x += 1; // This is not allowed.
x--; // This is not allowed.
You are also not allowed to use any loop construct. Thus any use of for, while, and do..while is not allowed. Any C++ trickery which modifies a previously declared variable is also not allowed (such as, but not limited to, the use of pointers to modify variables). Once declared, a variable is never allowed to be changed.
Problem 1: Double or Nothing
Suppose we have a list of integers. Write a function which returns true if the array contains somewhere a value and the next value is doubled. The value could exist anywhere in the list and there could be multiple instances. You need to detect if there is at least one instance of this circumstance. At a minimum, the list will contain one integer.
bool doubleOrNothing(int* array, int size);
Testing
Test your program with the following:
• ([1], 1): false
• ([1,2], 2): true
• ([0,0,1], 3): true
• ([2,3,4], 3): false
• ([1,3,5,10], 4): true
• ([1,3,5,11], 4): false
• ([9,8,7,6,5,4,3,2,1], 9): false
• ([9,8,7,6,12,4,3,2,1], 9): true
Problem 2: Word Separator
Given two strings, word and a separator sep, return a big string made of count occurrences of the word, separated by the separator string. If the count is 0, return an empty string. If the count is 1, return word.
std::string wordSeparator(std::string word, std::string sep, int count);
Testing
• (“Y”, “X”, 3): “YXYXY”
• (“Y”, “X”, 2): “YXY”
• (“Y”, “X”, 1): “Y”
• (“Y”, “X”, 0): ""
Problem 3: McNugget Numbers
A McNugget Number is a number of Chicken McNuggets which can be purchased at McDonalds. The mathematical definition of a McNugget number changes over the years with changes to the menu. When I was researching this problem, I realized that this is too trivial to write, so we are going to invent our own definition of a McNugget number.
In a fictional McDonald’s somewhere in the Universe, you can purchase the following orders of McNuggets:
• 3 piece
• 7 piece
Your task is to write a recursive function which will report of a number is a McNugget number.
bool mcNuggetNumber(int n);
Testing
• These numbers are McNugget numbers: 3, 6, 7, 9, 10, 12
• These are not: 0, 1, 2, 4, 5, 8, 11
Problem 4: Can the array be split?
Given an array of integers, can you evenly divide the list into two arrays, each with a sum equal to half of the original? You don’t have return the two smaller arrays. You need to return true if it can be done and false otherwise.
• 5 2 3 can be divided evenly because we can put 5 in one list and 2 and 3 in the other list. Both lists are half of the sum of the original.
That’s pretty much it. Here are some tips:
• Write a method to compute the sum of the list.
• Make sure that your sum algorithm supports a 0-length array.
• If the sum of the list is odd, return false. There’s no point in doing the rest.
• Write a method that will attempt to iterate through the array, selecting or not selecting each element, each time contributing to a total.
– Once the total equals the desired amount, return true.
– If there are too many values selected, return false.
Sample Output
There is no input on this assignment. Your code will be studied for accuracy. Your output should match mine. (Obviously, don’t copy my output. You don’t learn that way.)
Assignment 5. Recursion.
All calls must result in a 1 in order to pass the problem.

Double Or Nothing.
1. 1
2. 1
3. 1
4. 1
5. 1
6. 1
7. 1
8. 1

Word Separator.
1. 1
2. 1
3. 1
4. 1

McNugget Numbers
1. 1
2. 1
3. 1
4. 1
5. 1
6. 1
7. 1
8. 1
9. 1
10. 1
11. 1
12. 1
13. 1
14. 1
15. 1
Split the rray 1. 1 2. 1 3. 1 4. 1 5. 1 6. 1 7. 1 8. 1 9. 1 10. 1 11. 1 12. 1 13. 1
What to Hand In
Upload a zip file containing the following files to the drop box on D2L:
• Your driver with FirstNameLastNameA6.cpp
• Your solutions header file: solutions.h
• Your solutions implementation file: solutions.cpp
• Make sure your name, CSCI 3250, and Programming Assignment 6 appear in comments in all of your files.
• Note: NO CREDIT will be given to programming assignments that do not compile.
• Make sure you have compiled and tested your program before handing it in.

m nuggets please in c++

i would like mcnuggets program in c++

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

bool doubleOrNothing(int* array, int size) {
    int i = 0;
    while(i < size-1) {
        if(array[i] == array[i+1]) {
            return true;
        }
        i++;
    }
    return false;
}

**************************************************

Answering your first question, as the questions are completely unrelated and require different code. I request you to please post single question in a thread, so that it helps us in explaining the things better to you. Hope you understand!

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Add a comment
Know the answer?
Add Answer to:
Assignment 6: Recursion Learning Outcomes • Learn how to craft solutions using recursion instead of loops....
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
  • Programming Assignment #7 (Recursion) This assignment is to write some methods that perform simple array operations...

    Programming Assignment #7 (Recursion) This assignment is to write some methods that perform simple array operations recursively. Specifically, you will write the bodies for the recursive methods of the ArrayRecursion class, available on the class web page. No credit will be given if any changes are made to ArrayRecursion.java, other than completing the method bodies Note that the public methods of ArrayRecursion – contains(), getIndexOfSmallest(), and sort() – cannot be recursive because they have no parameters. Each of these methods...

  • Unrolling Recursion The objective of this problem is to simulate recursion using stacks and loops...

    Unrolling Recursion The objective of this problem is to simulate recursion using stacks and loops. A synthetic linear recursive procedure for this problem is provided in Code Fragment 1. A recursive function such as the one described is intuitive and easily understandable. On calling myRecursion(input), the execution first checks for the stopping condition. If the stopping condition is not met, then operations inside the recursive call are performed. This can include operations on local variables. The operations inside the function...

  • Using recursion only (no loops allowed!), write a C++ function of the form int count7s(int)

    please do in c++Q4. Using recursion only (no loops allowed!), write a C++ function of the form int count7s(int) that when passed a non-negative integer, returns the number of occurrences of the digit 7 in the number. So, for example: count7s(717) → 2 count75(7) →1 count7s(123) → 0 Q5. Write a C++ function of the form string mirrorEnds(string)that when given a string, looks for a mirror image (backwards) string at both the beginning and end of the given string. In other words, zero or...

  • JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using...

    JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using recursion. The method signatures are included in the starter code below, with a more detailed explanation of what function the method should perform. You will be writing the following methods: stringClean() palindromeChecker() reverseString() totalWord() permutation() You will be using tools in the String class like .substring(), .charAt(), and .length() in all of these methods, so be careful with indices. If you get stuck, think...

  • Recursion Exercises These exercises provide practice with recursion in Java. Objectives Module: To write recursive solutions...

    Recursion Exercises These exercises provide practice with recursion in Java. Objectives Module: To write recursive solutions for basic problems that require iteration. To identify and address base cases in a recursive method. Reminders during development Each of your solutions to the problems below should be in their own method. If a method header is provided for a problem, then your solution should have that exact method header. Any changes to the method header will receive a zero for that problem....

  • Assignment 1 In this assignment you will be writing a tool to help you play the...

    Assignment 1 In this assignment you will be writing a tool to help you play the word puzzle game AlphaBear. In the game, certain letters must be used at each round or else they will turn into rocks! Therefore, we want to create a tool that you can provide with a list of letters you MUST use and a list of available letters and the program returns a list of all the words that contain required letters and only contain...

  • Write a method called printReverse() that takes a string and uses recursion to print the contents...

    Write a method called printReverse() that takes a string and uses recursion to print the contents of the string in reverse order. The string itself should not be reversed; it must be left in its original form. The method has the following header:   void printReverse(String s, int i) where s is a reference to the string, and i is an integer parameter that you may use as you see fit. You do not need to code up this method as...

  • write a program which include a class containing an array of words (strings).The program will search...

    write a program which include a class containing an array of words (strings).The program will search the array for a specific word. if it finds the word:it will return a true value.if the array does not contain the word. it will return a false value. enhancements: make the array off words dynamic, so that the use is prompter to enter the list of words. make the word searcher for dynamic, so that a different word can be searched for each...

  • Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from...

    Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from the previous assignment and modify it so that it uses an array of Car objects as the principal data structure instead of an ArrayList-of-Car. This is an example of the OOP principle of information hiding as your Car and test classes will not have to be modified at all. Unless you broke encapsulationon the previous assignment, that is   II. Specifications Specifications for all 3...

  • Need help in my C language assignment... all I need to do is 1.Use recursion instead...

    Need help in my C language assignment... all I need to do is 1.Use recursion instead 2. NO LOOPS ALLOWED Output _______________________________________ What number shall I start with? 16 sequence: 16 8 4 2 1 length: 5 largest: 16 For start values from 1 to 16: longest: 9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 length: 20 containing largest: 15 46 23 70 35 106 53 160 80...

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