Code in C++
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.
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:
Sample Output
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
Code to fill in
main.cpp
#include <iostream>
#include "solutions.h"
using namespace std;
int main()
{
int a1[1] = { 1 };
int a2[2] = { 1,2 };
int a3[3] = { 0,0,1 };
int a4[3] = { 2,3,4 };
int a5[4] = { 1,3,5,10 };
int a6[4] = { 1,3,5,11 };
int a7[9] = { 9,8,7,6,5,4,3,2,1 };
int a8[9] = { 9,8,7,6,12,4,3,2,1 };
cout << "All calls must result in a 1 in order to pass the
problem." << endl;
cout << endl;
cout << "Double Or Nothing." << endl;
cout << "1. " << (doubleOrNothing(a1, 1) == false)
<< endl;
cout << "2. " << (doubleOrNothing(a2, 2) == true)
<< endl;
cout << "3. " << (doubleOrNothing(a3, 3) == true)
<< endl;
cout << "4. " << (doubleOrNothing(a4, 3) == false)
<< endl;
cout << "5. " << (doubleOrNothing(a5, 4) == true)
<< endl;
cout << "6. " << (doubleOrNothing(a6, 4) == false)
<< endl;
cout << "7. " << (doubleOrNothing(a7, 9) == false)
<< endl;
cout << "8. " << (doubleOrNothing(a8, 9) == true)
<< endl;
cout << endl;
cin.ignore();
cin.get();
return 0;
}
solutions.cpp
#include "solutions.h"
bool doubleOrNothing(int* array, int size)
{
return true;
}
solutions.h
#pragma once
#ifndef SOLUTIONS_H
#define SOLUTIONS_H
#include <string>
bool doubleOrNothing(int*, int);
#endif
//solutions.cpp
#include "solutions.h"
bool doubleOrNothing(int* array, int size)
{ //if size of list = 1 return false
if(size==1)return false;
if(2*array[size-2] == array[size-1])return true;
return doubleOrNothing(array , size-1);
}
//sample output

Code in C++ Instructions This assignment will be different than previous assignments (and most assignments which...