BIT 1400 – Introduction to Programming and Problem Solving Assignment 6: Mini-problems Your job for A6 is to solve each of the mini problems with minimal guidance. You are expected to...

please code the assignment depending on the code thats in the file


BIT 1400 – Introduction to Programming and Problem Solving Assignment 6: Mini-problems Your job for A6 is to solve each of the mini problems with minimal guidance. You are expected to use variables, loops, conditionals, and functions in many places. Personally, I hate problems like these because they are formulaic and encourage rote learning (people also find answers online instead of trying to learn.... please don't do that). A6 is designed to help you think algorithmically and know what you need to review for term test 2. The first questions are also potentially useful for A8 and A9. • Make sure you read ALL the instructions in this file (I know I wrote a lot). The instructions are longer than the code. Submission Save the file as A6_MiscProblems_F22.cpp where name is your first initial and last name. Eg: A6_MiscProblems_MNiknam_F22.cpp Grading Each of the graded questions will be marked: 50% based on code quality (style, use of comments, good variable names, etc) 50% based on code correctness. • 5% for the code compiling and the function being called correctly • 25% for the various calls to the function (tests). This can be asserts or printf statements that clearly show the function works as expected. • You can get input from the user but that is not the same as testing since no one is going to run your program 10 times to do all that testing. o Writing your own tests show us you know how to test code. o It gives you more confidence that your code works as expected. o It makes it easier for you to test your own code thoroughly. General Programming Pattern Here is a reminder about how to program in case anyone is still writing all their code and then trying to compile it at the end….or people believing that compiling code means it is correct. 1. Do one question at a time, compile and test your functions following the format in the following steps. Do not move on until each question is complete. 2. Make a new .cpp file (and new project as well) where you will write your code. 3. Break out the paper: Write pseudocode (or an illustration) for each question. These should be submitted with your program. We like seeing how you think through the process. * Writing pseudocode continues to be a valid exam question. Also, you could use it to get part marks. 4. Make the function but do NOT define it correctly. Just do whatever it takes to make the function compile. For example, here is superBowlConvertLarge (from A5) as a "todo function". Feel free to put the comment “// TODO” at the top that you won’t forget to define it later. // TODO const char* superBowlConvertLarge(unsigned int sbNum) { return ""; } You make the function just enough that you can compile and write tests for it... the tests will fail. Later you write the function and see if the tests pass. This is the basic concept surrounding something called "Test Driven Development". It makes for better code because you design the tests and then figure out the code rather than designing tests FOR the code you wrote. If you write the tests later, you tend to only test things your function will pass. Tests can be asserts or printf statements demonstrating what the functions return. 5. Make sure your functions have comments at the top (and to clarify code) Write tests or what you expect each function to do under different conditions / values. You will do this by calling each function with different inputs from your main function. Put a comment above each of these calls as to what you expect the value to be (or in many cases you could put the whole thing in an assert to prove that the function works as expected). Example: // superBowlConvertLarge(50) returns "L" or // Expect "Superbowl 50 is L" printf("Superbowl %i is %s\n", 50, superBowlConvertLarge(50)); 6. FINALLY, write the code for the function. 7. Make sure the functions you wrote pass your tests. Do you get the results that you expected? You do not have to use the provided code. It is there to help. You will follow this pattern for each function you are asked to write. This assignment has 3 parts (with part 1 being 3 parts) Starter Code Be sure to include the following lines at the start of your .cpp file. IGNORE_VALUE is potentially used by Question 1. After all, if a grade is set to 200 will it be identified as the minimum grade? include #include #include #include const int IGNORE_VALUE = 200; // Array example: //int a_gradesDemo[10] = {80, 80, 90, 0, 100, 80, 70, 0, 70, 70}; // HELPER FUNCTION: minIdx finds the minimum element index (position) in an array. // For the example, a_gradesDemo (above) the value 3 would be returned // (the position of the first 0) int minIdx(int* a_grades, int numGrades) { if (numGrades <= 0)="" {="" return="" -1;="" }="" int="" minidx="0;" for(int="" i="0;" i="">< numgrades;="" i++)="" {="" if(a_grades[minidx]=""> a_grades[i]) { minIdx = i; } } return minIdx; } Questions Question 1: Calculate the Average for Students’ Top N Grades (3 Tasks, 50 points in total) As you probably know, we drop some of your lowest assignment grades (at least 1) to calculate your assignment average. In this question, we want to implement this idea by breaking it down into 3 tasks. The 3 tasks are NOT a step by step instruction to the problem, so make sure you complete all of them, and you can select the appropriate functions from the three parts to solve the problem. But first: how would you remove the n lowest grades from a list of grades? Note, we can’t delete parts of the array (and someone could legitimately get a 0 on an assignment). Two suggested approaches (do one or the other): 1. Change the grade you want to drop to be IGNORE_VALUE. Then ignore/don’t use that value when calculating the average. Thus summing {42, IGNORE_VALUE, 60} would be 102. 2. Swap the last element in the used array with the grade to drop, then just pretend you have one fewer element in your array. Wait….what? I don’t NEED to use the entire array. Often I only use part of an array. Let’s pretend we have 5 grades (60, 0, 0, 0 are ignored): {90, 81, 90, 17, 54, 60, 0, 0 0}. The average would be (90 + 81 + 90+17+54) / 5. Now swap the last element with the minimum element: {90, 81, 90, 54, 17, 60, 0, 0 0} And now change the number of grades from 5 to 4. The average is (90 + 81 + 90+54) / 4 In all cases: please plan on paper first. Notes about provided function sumGrades: • An array of integer numbers can be defined like so: int a_gradesDemo[10] = {80, 80, 90, 0, 100, 80, 70, 0, 70, 70}; // it can be defined other ways too but when a_gradesDemo is sent to a function, it looks like it does in the provided function sumGrades below. We will look at why the syntax looks this way but for now you can just follow the examples. Parameter a_grades just points to the array you made. • In the function sumGrades, the parameter a_grades is the array BUT you don’t know how large it is, so the parameter numGrades indicates how large the array is. o Calling the function sumGrades with a parameter a_gradesDemo and assigning the return value to a variable called demoSum would look like this: int demoSum = sumGrades(a_gradesDemo, 10); // HELPER FUNCTION: function sums grades from an array. // You can use this function to help you write a for loop or use an array. int sumGrades(int* a_grades, int numGrades) {
Nov 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here