#include #include using namespace std; //Print given phrase n times void annoying(string s, int n) { for (int i = 0; i < n; i++) { cout << s << endl; } } //Compute and return take home pay. //Not anything else, NO cout statements double takeHomePay(double basePay, double tax) { return basePay * (1 - tax); } //return factorial of given positive integer int factorial(int n) { int prod=1; for (int i = 1; i <= n; i++) { prod = prod * i; } return prod; } //A function that returns true if the first number is greater than the //2nd, and false otherwise bool isGreater(double x, double y) { if (x > y) { return true; } else { return false; } } //return x squared double squared(double x) { double result; result = x * x; return result; } //increment value of given variable by 1 //& means pass by reference void increment(int &n) { n = n + 1; } int main() { //Quiz: //1: Write a function that take as input a phase and a number n, //and prints that phase n times. annoying("Are we there yet?", 5); //Should print: //Are we there yet? //Are we there yet? //Are we there yet? //Are we there yet? //Are we there yet? //Quiz question 2: //Write function that takes as input your money earned //before taxes, as well as the tax rate, //and returns the takehome pay amount. cout << "I get to take home " << takeHomePay(500, .10) << " dollars." << endl; //I get to take home 450 dollars //Challenge #1: cout << "Factorial of your number is: " << factorial(4) << endl; //24 cout << "Factorial of your number is: " << factorial(6) << endl; //720 cout << "Factorial of your number is: " << factorial(10) << endl;//3.6 million cout << "Factorial of your number is: " << factorial(15) << endl;//2 billion cout << "Factorial of your number is: " << factorial(20) << endl;//uh oh, too big for a positive int (31-bits) //Challenge #2: isGreater, squared, printRange if (isGreater(70, 3.14)) { cout << "Yep 70 is bigger than 3.14" << endl; } else { cout << "Nope, 70 is not bigger than 3.14" << endl; } cout << isGreater(2, 15) << endl; //false cout << isGreater(3.14, 3.14) << endl; //false cout << isGreater(50, 20) << endl; //true //squared cout << squared(5) << endl; //25 cout << squared(12) << endl; //144 cout << squared(-4) << endl; //16 //Challenge #3: summation //Challenge #4: pow ///////////// Pass by reference ///////////// //Challenge #5: Write a function to increment an int variable by one. int x = 5; increment(x); cout << x << endl; //6 increment(x); increment(x); cout << x << endl; //8 //Challenge #6: squareIt //Challenge #7: swap //hwk questions? return 0; }