CIS220 Lab 1: This is a 2 week lab Due Tuesday, Sept 20, at midnight. Submit all files through Sakai. For this lab you may work with a partner. Choose a partner with a working laptop, and with Eclipse working, so at least one of you has a working laptop with a working c++ compiler. Note that you may choose to work alone, but if you choose to work alone, you are still responsible for the entire content of the lab. “I was working alone” is not an excuse. If you want a partner but can’t find one, ask your TA. Problem 0: Install Eclipse + CDT. Follow the instructions on my web site. Note: If you choose to install some other c++ editor and compiler, I’m fine with that, as long as it works. But it may make it more difficult to work with a partner. Hints: From L. Hsu: When installing, when you select the Basic Setup, Select all the packages for installation. Also make sure you’ve got the java jdk installed (should be installed from 181) and the environment path including the path to your jdk (should be something like, C:\Program Files\Java\jdk1.8.0_101\bin From me: if you don’t have java installed, you must install it. The instructions are on my https://www.eecis.udel.edu/~yarringt/181 web site, under “Installing Eclipse”. From D. Sorenson: On Macs, you may need to open a terminal window and type in the command, "xcode- select --install". From C. Clayton: Under All Packages, select the 3 mingw32-pthreads-w32 packages From J. Buxton: If not working, try uninstalling and reinstalling MinGW Note: Problems 1-7 can be done in a word document and turned into Sakai in the word document. Problem 1: (2 pts) Define “Data Structures”. I only expect maybe a sentence or two here, but you’re taking a course in it… I think you should at least know what it is. List at least 2 applications that currently need to use efficient data structures. Problem 2: (4 pts) Pick 2 of the 4 Computer Scientists and write a paragraph about their contributions to computer science: 1. Lovelace 2. Turing 3. Hopper 4. Babbage Note: Here I expect a paragraph or two. These people are amazing. Read a bit. Write a paragraph that does not involve copying so I know the information went in, got processed, and then came out in a different form. Problem 3: (2 pts) C and C++ are compiled languages. Give me a paragraph on the advantages of a compiled language. Problem 4: (1 pts) What is your TA’s name and email address? Problem 5: (6 pts): List and describe (briefly – 1 sentence or less) 6 functions in stdlib.h Problem 6: (11 pts) Memory (addresses and values at those addresses) 3 (x) 0x24e2d2 0x24e2d6 0x24e2da 0x24e2de (a) 0x24e2e2 0x24e2e6 0x2634e0 0x2634e4 0x2634e8 0x2634ec 0x2634f0 (z)0x2634f4 Given the following code, using the memory model above, what is printed at each of the couts?: int x = 4;, int *a = &x; cout << "x: "<< x << endl; cout <<"&x:"<<&x << endl; cout <<"a: "<< a << endl; cout << "&a: "<<&a << endl; cout << "*a: "<< *a << endl; int **z = &a; cout << "&z: "<<&z << endl; cout << "z: " << z << endl; cout << "*z: " << *z << endl; cout << "**z: " << **z << endl; Part b: Given the following code (associated with the previous code): x += 4; Which of the following variables change and how? x, &x, a, &a, *a, z, &z, *z, **z Memory 3 4 7 1 5 0x28fedc 0x28fee0 0x28fee4 0x28fee8 0x28feec 0x28fef0 72 0x293a1c 0x293a20 0x293a24 0x293a28 0x293a2c 0x293a30 0x28fedc 0x37232a 0x37232e 0x372332 0x372336 0x37233a 0x37233e Problem 7 (9 pts): Given the following memory model, write the code that: a. (1 pt) Write the code that would have created the array (called x) of 5 ints (assume it gets placed in memory as shown (along the first row)) b. (1 pts) Write the code that prints out the address of the first value in the array c. (1 pts) Write the code that prints out the address of the third value in the array d. (1 pts) Write the code that creates this variable (called y) (aka a pointer): e. (1 pts) Write code that uses the variable y to print out the value 4 f. (1 pts) Write code using the variable y to print out 0x28fedc g. (1 pts) Write code using the variable y to print out 0x37232a h. (1 pt) Create a new variable (z) that holds 72 (assume it gets placed in memory as shown) i. (1 pts) Change the variable y so that it points to z (holds the address of z). Problem 7 part b (2 pts): Using the array x (created above, step a.) and the following code, what is printed out? int *B[] = {x,x,x}; x[2] += 3; cout << B[0] << endl; cout << B[1] << endl; cout << B[2] << endl; Coding: Programming Problems: Notes: when writing functions, all functions should go below your main function in the order of the lab. All function declarations should be at the top of your program, right above your main function. All functions should be called and tested from the main function. All code should be formatted according to the rules of formatting (on my web site). Equally, all code should be commented. Problem 1. (2 pts) Make sure you can get the “Hello World” problem to work. In other words, write a basic program function that outputs to the console window the text, “Hello World”. If you can get this to work, we’ll know you’ve gotten a c++ compiler to work correctly on your computer. Plus everyone has to write the “hello world” problem in c at some point in their programming lives. Problem 2: (3 pts) The Collatz Conjecture states that, given any positive natural number, you will always eventually reach 1 if you follow the following formula: if the number is even, divide by 2, and if the number is odd, multiply by 3 and add 1. Continue the process indefinitely or until the number is equal to 1. This problem has never been proven, and someone did actually prove that a generalization of the problem is unprovable. That said, no one’s found an exception either. In your main, ask the user to input a natural positive number. Convert the string to an int, then pass that int into a function that will follow the above formula until the number is equal to 1. Count how many times you loop until you get to 1, and return that number from your function. Make sure you print out the count in your main function. Keep functions you’re creating below the main function, and make sure you include function declarations in your program. Problem 2b: (4 pts) Create a second function below the Collatz Conjecture function. This function takes no input parameters. Inside the function, ask the user to input 2 separate integers (one at a time). This function should call the Collatz Conjecture function for every value between the two integers, including the smaller integer and excluding the larger integer (you may not assume that the first input is less than the second input integer). If, for every number, the Collatz Conjecture function returns a number, the program should print out the number input into the Collatz Conjecture function, the number returned from that function, and, “Collatz Conjecture is still working”. (Now, if it doesn’t, the Collatz Conjecture function will loop infinitely and your program will hang. You should write down the number you sent in, because you just did something really amazing and found a number that doesn’t work with the Collatz Conjecture. Or you did something wrong. You decide which is more likely). ****************************************************************************************** Generating Random Numbers: In order to create random numbers you need to “seed” the random number generator first. You need to do this once and only once: #include#include . . . (other code goes here, e.g., function declarations) int main() { srand(time(NULL)) // creates a seed based on the current time (down to the millisecond) // Only need to create a seed once in a program // Must create seed BEFORE you use rand for the first time. Once this is created, when you need a random number you can use this: int x = rand(); // now rand uses this seed in the calculation of the random number. // Now you won’t always get the same sequence of random numbers //rand generates a random number between 0 and some number defined in stdlib. ****************************************************************************************** Problem 3: (4 pts) Write a function that takes as input 3 numbers using call by Pointer. The function will return a Boolean value indicating whether the first parameter is less than the second, and the second is less than the third. In addition, if they are not in order, the function will change the values of the parameters so that the first parameter is the smallest of the three parameters, the third parameter is the largest of the three parameters, and the middle parameter is the value in the middle (or put the parameters in order). Now in main, generate 3 random numbers. Print them out (so we know what we started with) and then send them into your function. If the function returns False, print out the 3 numbers again. This time they should be in order. Problem 4: (6 pts) A perfect number is a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3. The next one is 28, which is the sum of 7, 14, 2, 4, and 1. Other perfect numbers are 496, and 8,128. Write a recursive function that determines whether a number is perfect or not. Assume the number is positive, and an input parameter. This function should return a Boolean value indicating whether this number is perfect (true) or not (false). Make sure your main function calls this function with values 3-30 (including 3, excluding 30) (so it’s calling your perfectNumber function 27 times), and prints out the original number and the Boolean value returned from the function for each number. Problem 5: (3 pts) Repeat Problem 3, only use call by Reference. Arrays: Problem 6: (3 pts) In your main, generate a random number between 20-50 (including…excluding), then create an array of that size. Call a function with that array and the size of the array. In the function, modify the array by filling in the entire array with random numbers between -50 and 50 (including, excluding). This function should have a void return type. Problem 6b: (2 pts) Write a second function that prints out each value in the array. This function should take as input an array of ints, and a size, and it should have a void return type. Problem 7: (5 pts)Write a function that takes as an input parameter the array created in problem 6 (along with the array’s size) and reverses the order of the values in the array (without creating a new array). This function’s return type should be void. Make sure you call function 6b after you’ve called this function to compare the array’s values before and after this function has been called. Problem 8:(4 pts) Write a function that takes as input the array and the size, and finds the minimum value in the array and returns that value. (again, don’t use a built-in min function. Write your own code). Problem 9: (3 pts)Write a recursive function that uses the array created in problem 6 and sums the values in the array of ints and returns that sum (note:. you may use as many input parameters as you need). (Write your own code, no built-in sum function use) Problem 10: (6 pts) Recreate the sort you wrote for the Assessment in last Thursday’s class. On the assessment you wrote a sort that sorted values from smallest to largest. This is the sort I want you to get working here. Of course, write a function for this. In the function, keep a count of every time you make a comparison (i.e., >, <, ==, >=, <=, ! are all comparators). Return the count of the number of comparisons necessary. Use the function you wrote in problem 6 to generate a number of arrays, and keep track of the average number of comparisons your sort used. Ask other classmates how many comparisons their sort used for a similarly sized array. How did you do? (you can tell me in the comments). Problem 11: (8 pts) (Do not use a built-in sum function. Write your own.) Write a low pass filter function. The function will take as input an array of integers, and an int representing the window size for the filter. (Note that for this function you’ll have to create a new array of random numbers, because you sorted the old array in problem 10). Generate a random number between 3-7 in the main function, and pass that into your filter function. That will be your window size. A low pass filter will take a “noisy” array of numbers, and smooth the values in the array. It does this by taking the average of x values before and x values after a particular number and replacing that number with that average in a new array. So, for instance, if we had a noisy array that looked like this: {3,2,7,0,4,2,1,6,4,2,9,5,4,2,3} And a window size of five, then in the new array 1. The first two and last two values in the array would be replaced in the new array with 0, because they don’t have a window of 5 surrounding them. 2. 7 would be replaced with 3 (the average of 3,2,7,0,4 truncated) 0 would be replaced with 3 (the average of 2,7,0,4,2 truncated) 4 would be replaced with 2 (the average of 7,0,4,2,1 truncated) Etc. The function should return the newly created smoothed array. Note: for this you can use the built-in property .length to find the length of the array NOTE2: the size of the window is not necessarily 5. It is the value passed into the function Problem 12: (10 pts)In main, create a 3 dimensional array (of unknown size). Create 3 integer variables, all initialized to -1. Now write a function that takes as input parameters the array and 3 integer variables, in the form of call by reference. Within the function generate 3 random numbers, each between 2 and 6, and set the parameters to each of the random numbers respectively. Now allocate memory for your 3 dimensional array. Fill in the 3-dimensional array with the sum of the x,y, and z index at each location within the array. Now write a second function that prints out each of the values in your 3 dimensional array. You’ll need the dimensions set in the createMatrix function in order to print out the array. Make sure you call both functions to test them. In your main, after you’re done printing the matrix, free up the memory.