Midterm I CS120 Spring 2021 Due Date 11:59 p.m., Tuesday, April 6th This exam assumes you are using the virtual linux lab environment. If you are not, please review the following document. Although...

1 answer below »
Would it be possible to get this done using basic C mechanics before tomorrow at 11 pm ?


Midterm I CS120 Spring 2021 Due Date 11:59 p.m., Tuesday, April 6th This exam assumes you are using the virtual linux lab environment. If you are not, please review the following document. Although you may work on your own computer, I cannot troubleshoot system specific issues. You will need to make the necessary changes in the exam for your system (i.e. gedit is a linux editor, so replace it with notepad on Windows). If your code does not run on the system in the virtual lab, it is considered non-functioning EVEN IF IT RUNS ON YOUR PERSONAL COMPUTER. Always check that your code runs on the lab machines before submitting. Hello all, As you complete the first exam, please know that I am very proud of how resilient this class has been through all the difficulties this semester (pandemic, server issues, etc.). All it takes to be a good programmer is perseverance, determination, and a willingness to forgo social interaction. You have all shown that in abundance throughout this semester. Thank you for your understanding and patience. Now for the official part: Please make sure you follow ALL the instructions carefully. Failure to follow instructions will, at best, result in a large point deduction and could result in a 0 for the exam. Double check your submission (a couple times). I will not accept a late submission for ANY reason (even 1 second late). Plan ahead. This exam is your chance to show me what you have learned so far this semester. Spend some time to make sure it’s the best you can do. You can find the grading guidelines we will be using at the end of this document. Please note that following instructions and submitting properly is PART OF THE EXAM. IMPORTANT: All your code must go in the test.c file. Do not alter the existing code in test.c file in any way. You will only add your functions (anywhere after the declarations). You do not need a header file because the declarations are in the test.c file. Use those declarations in the test.c file as a function interface guide. Dynamic Memory I have provided you with driver code that explains what you must do for each step. All allocated array memory should be on the heap (using malloc). Below is an overview of the steps: 1. Create an integer array of size on the heap, and insert -1 into every element 2. Increase the size of your array by 1 element: a. allocate space for a new array b. copy the values over c. make the last value 1, instead of negative 1. 3. Double the size of your array, copying the values from the first half to the second half 4. Reduce the size of the array by half, only keeping the first half values 5. Remove the first element from the array, and shrink the array by one. The resulting array should be exactly like the previous, only missing the first element. All of your loops (printing or otherwise) should use only pointer arithmetic to iterate through your list. Valgrind Because C is so flexible, you need to verify that you are using memory properly. Valgrind is a unix memory tool to ensure you are using valid memory (will not work on windows). To get the most out of valgrind, you should use the -g flag when you compile: gcc -g myfile.c -o myprog Once you’ve compiled your code, you can use valgrind to verify your memory usage: valgrind ./myprog Your program will run with additional information. What you are concerned with is the following: lines: HEAP SUMMARY: in use at exit: 10 bytes in 1 blocks ... ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) It should say: in use at exit: 0 bytes in 0 blocks 0 errors. If it says you have errors or leaks, you will have to go back and try to determine what your error is and fix it. Submission 1. Test your code on the virtual lab machines with the -Werror and -Wall flags 2. Complete the README.md file 3. On mycourses, in the ‘text submission’ portion of the submission, please add your commit hash 4. Relax. Grading Guidelines Before grading, run the program and make sure it works. If the program does not run, submit a 0 for the grade. Below is a guide for how I would like you to inspect and grade the exam: TOTAL: 50 pts. 1. Students MUST complete their README.md file. [5 points] 2. Review for each of the following: a. Dynamic Memory: 35 points i. Each test passed: 1-5 (5 points) ii. Only uses pointer arithmetic (10 points) b. Valgrind: 10 points i. No memory leaks or errors reported by Valgrind 3. Submission: a. WARNING: Late Submissions are not accepted b. (-15 points) Incorrect submission, for any reason other than lateness (i.e. incomplete submission, wrong file, etc.)
Answered Same DayApr 05, 2021

Answer To: Midterm I CS120 Spring 2021 Due Date 11:59 p.m., Tuesday, April 6th This exam assumes you are using...

Vibhav answered on Apr 06 2021
139 Votes
dm/1.JPG
dm/readme.md
#test.c
***
The program to demonstrate creating and modifying arrays using
dynamic memory allocation.
***
dm/test.c
#include
#include
#include
#define size 5
/*
Function to print the array created, so that we may know that
array was correctly created/modified
*/
void print(int* arr, int n){
    for(int i=0; i        printf("%d ",...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here