// Programming exam 1
// In the exam you will be given a program that already has some
// functions, but they have no functionality. It is up to you to
// actually implement them.

// Please put your name in the next line:
// Your Name: Max Berger


#include <iostream>
using namespace std;


void printFancy()
/* This function will print:
I like C++
very much.
In to lines formatted exactly as shown, with a newline after the "much.".
It will use only ONE cout statement.
*/
{
  cout << "I like C++" << endl << "very much." << endl;
}


void dwi(float percent)
/*
  This function checks if our are legal to drive based on your blood alcohol content
  If percentage given is less than 0.01 print something like "your albsolutely sober"
  if it is more than that but less than 0.08 print something like "be carefull"
  if it is more than that print "you better stay and sober off  
  use only one consecutive if / else if / else statement. 
*/
{
  if (percent < 0.01) cout << "sober" << endl;
  else if  (percent < 0.08) cout << "carefull" << endl;
  else cout << "stay a while" << endl;
}

void loopFromTo(int from, int to)
/*
  This function will print the numbers from "from" to "to" (inclusively) in one line, seperated by spaces
*/
{
  int i;
  for (i = from; i<= to;i++) cout << i << " ";
  cout << endl;
}

enum operation { add, multiply };
int math(operation o, int a, int b)
/*
  This function will return a+b if the operation is add, and a*b if the operation is 
  multiply.
  use a case statement.
*/
{
  switch (o) {
    case add: return a+b;
    case multiply: return a*b;
  }
}

void gramsToPounds(float &weight)
/*
  This function converts weight from grams into pounds,
  using call-by-reference.
  1 pound = 454 grams.
*/
{
  weight = weight / 454;
}

int largestElement(int a[], int size)
/*
  this function will find the largest element in the array a in the range 0..size-1
  it will return the VALUE of the largest element,
  not the INDEX
*/
{
   int i;
   int greatestElementValue = a[0];
   for (i = 0;i<size;i++) {
      if ( a[i] > greatestElementValue) greatestElementValue = a[i];
   }

   return greatestElementValue;
}


int main()
{
  cout << "--- The next two lines should be: " << endl;
  cout << "--- I like C++" << endl;
  cout << "--- very much." << endl;
  printFancy();
  
  cout << "--- The next line should be: sober"<< endl; dwi(0.0);
  cout << "--- The next line should be: carefull"<< endl; dwi(0.04);
  cout << "--- The next line should be: stay"<< endl; dwi(0.1);

  cout << "--- The next line should be 4 5 6 7" << endl; loopFromTo(4,7);

  cout << "--- The next line should be 7 12" << endl;
  cout << math(add,3,4) << " " << math(multiply,3,4) << endl;
  
  cout << "--- The next line should be 2" << endl;
  float w = 908;
  gramsToPounds(w);
  cout << w << endl;
  
  int a[10] = {1,2,5,7,3,5,6,8,3};
  cout << "--- The next line should be 8"<< endl;
  cout << largestElement(a,10);
  
  return 0;
}
