#include <iostream>
#include <vector>
#include <ctime>
#include <cstdlib>
using namespace std;


//only needed to make things compile
//this function was not available on the test
void printInstructions() {
	cout << "dummy function " << endl;
}


//for 3b
double foo(int num1, int num2, int num3) {
	num1--;
	if (num1 < num2)
		num3 = num3 - 2;
	return num3 - num1;

}

//for 3c
int h(int b, int a) {
	return b;
}


//for 3d converted to vectors
void f(vector<int> &arr, int i) {
	if (i < arr.size())
		arr.at(i) = 7;
}


//for 3e

int function2(int a, int b) {
	return a * 2 + b;
}


int function1(int a, int b) {
	a = function2(a, b);
	if (a >= 3) {
		return a;
	}
	else {
		return a + 3;
	}
}


double length(const vector<double> & values) {
	double sum = 0;
	for (int i = 0; i < values.size(); ++i) {
		sum += values.at(i) * values.at(i);
	}
	return sqrt(sum);
}


int main() {
	srand(time(0));
	//some variables to allow things to happen later:
	vector<double> zebras(88);
	vector<int> puppies(149);
	vector<int> choices(234);
	vector<int> sodas(20);
	for (int i = 0; i < zebras.size(); i++) zebras.at(i) = rand()*100.0 / RAND_MAX;
	for (int i = 0; i < puppies.size(); i++) puppies.at(i) = rand();
	for (int i = 0; i < sodas.size(); i++) sodas.at(i) = rand();
	for (int i = 0; i < choices.size(); i++) choices.at(i) = rand();
	



	//answers follow here. Questions which are out of scope for exam 2, will be listed as such

	//1a - 43   You should be able to do the same with vectors
	//1b - out of scope for exam 2 (array names are pointers)
	//1c - out of scope for exam 2 (never return a static array from a function)
	//1d - what happens is undefined as it blows array bounds - same happens with vectors when using []. That's why we use .at with vectors
	//1e - out of scope for exam 2 (static arrays have constant sizes/allocated on stack and dynamic arrays may have variable sizes and are allocated on heap)
	

	//2a - 
	cout << "**********************" << endl;
	cout << "         2a" << endl;
	cout << "**********************" << endl;
	printInstructions();

	//2b - change array to vector in teh question
	//two solutions:
	cout << "**********************" << endl;
	cout << "         2b" << endl;
	cout << "**********************" << endl;
	if(zebras.size() > 0) // usually useful to make sure the vector was big enough
		cout << zebras.at(0) << endl;
	//if you wanted the last element instead:
	cout << zebras.at(zebras.size() - 1) << endl; 
	cout << zebras.back() << endl;

	//2c - out of scope for exam 2 (delete [] arr;)

	//2d - changed question to : writea  function prototype for a function that would print a vector of doubles
	void printVector(const vector<double> &mydoubles);

	//2e - change to a question about vectors
	if (puppies.size() > 1) {
		puppies.at(puppies.size() - 1) = puppies.at(1);
	}

	//2f - out of scope for exam 2 ( double mine[10]; double *mine = new double[10]; )

	//2g - do this for a vector named choices
	for (int i = 0; i < choices.size(); i++) {
		choices.at(i) = -1;
	}

	//2h - print every even-index element of a vector named sodas:
	cout << "**********************" << endl;
	cout << "         2h" << endl;
	cout << "**********************" << endl;
	for (int i = 0; i < sodas.size(); i += 2) {
		cout << sodas.at(i) << " ";
	}
	cout << endl;

	//3a
	cout << "**********************" << endl;
	cout << "         3a" << endl;
	cout << "**********************" << endl;
	for (int q = 10; q > 4; q -= 2) {
		cout << q - 2 << endl;
	}

	//3b
	cout << "**********************" << endl;
	cout << "         3b" << endl;
	cout << "**********************" << endl;
	cout << foo(12, 12, 12) << endl;;

	//3c
	cout << "**********************" << endl;
	cout << "         3c" << endl;
	cout << "**********************" << endl;
	int a = 4;
	int b = 8;
	cout << h(a, b) << endl;

	//3d - given the f function defined for vectors instead above
	cout << "**********************" << endl;
	cout << "         3d" << endl;
	cout << "**********************" << endl;
	vector<int> numbers(4);
	numbers.at(2) = -5;
	f(numbers, 2);
	cout << numbers.at(2) << endl;


	//3e
	cout << "**********************" << endl;
	cout << "         3e" << endl;
	cout << "**********************" << endl;
	a = 2;
	b = 1;
	cout << function1(a, b) << endl;


	//question 4
	//	find the "length"  of a vector as given by the formula as a function
	//the actual answer to 4 is above. This code below just shows that it does something
	cout << "**********************" << endl;
	cout << " Problem 4 - Program!" << endl;
	cout << "**********************" << endl;
	cout << length(zebras) << endl;

	
}