CS计算机代考程序代写 python You must satisfactorily answer a question below which says it meets the linked lists hurdle requirement.

You must satisfactorily answer a question below which says it meets the linked lists hurdle requirement.

Multiple questions are marked as meeting the linked lists hurdle requirement. answering any one of these

questions satisfactorily will meet the hurdle requirement.

Exam Environment
You may complete the exam questions anywhere you wish. You should ensure they work correctly, and pass

autotests, on VLab, or over SSH.

Autotests are available for all questions to assist you in your testing.

Passing autotests does not guarantee any marks.

Some Questions may deliberately exclude important autotests. If a question says it does excludes some

autotests, make sure you check it works correctly.

Submission
Answer each question in a SEPARATE file. Each question specifies the name of the file to use. These are

named after the corresponding question number, i.e. Question 1 is in a file called q1.c

Make sure you use EXACTLY this file name.

Submit these files using the submit command as described in each question. You may submit your answers

as many times as you like. The last submission ONLY will be marked.

Ensure that you have submitted your files before signing out. Running the autotests does not automatically

submit your code.

Language Restrictions
All questions must be answered entirely in C. You may not use other programming languages, e.g. you may not

use Python.

Your C program can not run external programs, e.g. it can not call the function system().

You are not permitted to use functions from C libraries other than the standard C libraries (stdio.h, stdlib.h,

string.h, math.h, ctype.h, assert.h).

Individual questions may specify C features you are not permitted to use or C functions you are not permitted

to use.

You can not use the -l option to dcc.

Setup
This exam comes with starter files. You can access them by running:

1091 fetch-pracexam

This gives you a file in which to write answers to the short answer questions. This file, named prac_mc.txt, is
the template into which you should put your responses to each multiple-choice question.

This also gives you starter files for each programming question.

To test your code, run the command:

1091 autotest-pracexam prac_q1

Short Answer Questions (10 marks total)

Note: The files mentioned in the following questions are not copied by 1091 fetch-pracexam. The file
names are just to show how they were compiled.

Short Answer Question 1 (1 mark)
Imagine a file named part1_q1.c contains this C Code (amongst other code):

int x = 11;
int y = 3;
printf(“%d\n”, x / y);

part1_q1.c is compiled with dcc on a CSE machine like this:

$ dcc part1_q1.c -o part1_q1
$

It compiles successfully. No errors or warnings are produced by dcc. The program is run like this:

$ ./part1_q1

What does this program print?

Enter as your answer the output the code snippet produces.

Enter this answer in the file prac_mc.txt, after the [q1], inside the curly brackets.

Do not enter any extra characters. Do not write \n for a newline character. Do not enter any explanation.

Enter just the output the program produces.

If the program prints an error message just write ERROR. Do not enter the exact error message.

Short Answer Question 2 (1 mark)
Imagine a file named part1_q2.c contains this C Code:

#include

#define STOP_NUMBER 100

int main(int argc, char *argv[]) {
int monkey = 1;
int i = 0;
while (i < STOP_NUMBER) { monkey += i; i++; } printf("Total is: %d\n", monkey); } Which of the following Code Style Issues are present in this code? A: Inconsistent Indentation B: Bad Variable name(s) C: Overly Deep Nesting D: Lack of use of constants Practical Questions Enter the answer(s) in the file prac_mc.txt, after the [q2], inside the curly brackets. This question can have more than one answer and a correct answer will identify all the issues in the code. For example, if you think that A and C are the correct answers, your answer will be: AC If you think that D alone is the correct answer, your answer will be: D Short Answer Question 3 (1 mark) The file part1_q3.c contains this C Code: #include
#include

struct node {
int data;
struct node *next;
};

int main(void) {
struct node *head = malloc();
}

What code should replace ?

Enter as your answer as the exact text you would write in this program.

Enter this answer in the file prac_mc.txt, after the [q3], inside the curly brackets.

Do not enter any extra characters. Do not write \n for a newline character. Do not enter any explanation.

You can check your answers are in the correct format with 1091 autotest-pracexam prac_mc
You can submit the question with give dp1091 prac_mc prac_mc.txt

There will be 20 Short Answer questions in the exam. See the lab exercise for more information.

Question 1
Passing this question, or question 3, is sufficient to pass the Arrays Hurdle.

Your task is to add code to this function:

// Return the maximum sum of a row in the 2D array.
int max_row_sum(int array[TEST_ARRAY_SIZE][TEST_ARRAY_SIZE], int side_length) {
// PUT YOUR CODE HERE (you must change the next line!)
return 42;
}

Add code so that max_row_sum finds the row in the square two dimensional array with the highest

sum, and returns that value. You are guaranteed the array will only contain positive numbers.

For example if the array is a 3 height by 3 width array

6, 7, 8,
1, 1, 9,
3, 2, 8

Your function should return 21 because:

6 + 7 + 8 == 21
1 + 1 + 9 == 11
3 + 2 + 8 == 13

As you can see, the largest row sum is 21.

Testing
prac_q1.c also contains a simple main function which allows you to test your max_row_sum function.

Your max_row_sum function will be called directly in marking. The main function is only to let you test

your max_row_sum function

Assumptions/Restrictions/Clarifications.
max_row_sum should return a single integer.

max_row_sum should not change the array it is given.

max_row_sum should not call scanf (or getchar or fgets).

max_row_sum can assume the array contains at least one integer.

max_row_sum function should not print anything. It should not call printf.

Your submitted file may contain a main function. It will not be tested or marked.

You can autotest this code with 1091 autotest-pracexam prac_q1
You can submit this code with give dp1091 prac_q1 prac_q1.c
You can check your submission has been accepted with 1091 classrun -check prac_q1
You can see your previous autotests here

Question 2
Passing this question, or question 4, is sufficient to pass the Linked Lists Hurdle.

Note prac_q2.c uses the following familiar data type:

struct node {
struct node *next;
int data;
};

count_last is given one argument, head, which is the pointer to the first node in a linked list. You are

guaranteed the list will not be empty.

Add code to count_last so that its returns the number of values which are the same as the last value in

the list.

For example if the linked list contains these 8 values:

16, 12, 8, 12, 13, 19, 21, 12

https://cgi.cse.unsw.edu.au/~dp1091/21T2/flask_tutors.cgi/student/dpst1091/5331710/autotest/prac_q1/

Question 3
Passing this question, or question 1, is sufficient to pass the Arrays Hurdle.

count_last should return 3, because 12 is the last value, and 12 occurs 3 times in the list (including the

last number).

Testing
prac_q2.c also contains a main function which allows you to test your count_last function.

This main function:

converts the command-line arguments to a linked list

assigns a pointer to the first node in the linked list to head

calls count_last(head)

prints the result.

Do not change this main function. If you want to change it, you have misread the question.

Your count_last function will be called directly in marking. The main function is only to let you test your

count_last function

Here is how you use main function allows you to test count_last:

$ cp -n prac_q2.c .
$ dcc prac_q2.c -o prac_q2
$ ./prac_q2 16 12 8 12 13 19 21 12
3
$ ./prac_q2 2 4 6 2 4 6
2
$ ./prac_q2 3 5 7 11 13 15 17 19 23 29
1
$ ./prac_q2 2 2 2 3 2
4

Assumptions/Restrictions/Clarifications.
count_last will never receive a linked list with no nodes. That is, the head will never be NULL

count_last should return a single integer.

count_last should not change the linked list it is given. Your function should not change the next or data

fields of list nodes.

count_last should not use arrays.

count_last should not call malloc.

count_last should not call scanf (or getchar or fgets).

count_last should not print anything. It should not call printf.

Do not change the supplied main function. It will not be tested or marked.

You can autotest this code with 1091 autotest-pracexam prac_q2
You can submit this code with give dp1091 prac_q2 prac_q2.c
You can check your submission has been accepted with 1091 classrun -check prac_q2
You can see your previous autotests here

https://cgi.cse.unsw.edu.au/~dp1091/21T2/flask_tutors.cgi/student/dpst1091/5331710/autotest/prac_q2/

In the final exam, question 3 will be an arrays question, more difficult than question 1.

Question 4
Passing this question, or question 2, is sufficient to pass the Linked Lists Hurdle.

Note prac_q4.c uses the following familiar data type:

struct node {
struct node *next;
int data;
};

delete_last is given one argument, head, which is the pointer to the first node in a linked list.

Add code to delete_last so that it deletes the last node from list.

delete_last should return a pointer to the new list.

If the list is now empty delete_last should return NULL.

delete_last should call free to free the memory of the node it deletes.

For example if the linked list contains these 8 elements:

16, 7, 8, 12, 13, 19, 21, 12

delete_last should return a pointer to a list with these elements:

16, 7, 8, 12, 13, 19, 21

Testing
prac_q4.c also contains a main function which allows you to test your delete_last function.

This main function:

converts the command-line arguments to a linked list

assigns a pointer to the first node in the linked list to head

calls delete_last(head)

prints the result.

Do not change this main function. If you want to change it, you have misread the question.

Your delete_last function will be called directly in marking. The main function is only to let you test your

delete_last function

cp -n prac_q4.c .
dcc prac_q4.c -o prac_q4
./prac_q4 16 7 8 12 13 19 21 12
[16, 7, 8, 12, 13, 19, 21]
./prac_q4 2 4 6 2 4 6
[2, 4, 6, 2, 4]
./prac_q4 42
[]
./prac_q4
[]

Assumptions/Restrictions/Clarifications.
delete_last should call free to free the memory for the node it deletes

Question 5
This question will not satisfy either hurdle.

Question 6
This question will not satisfy either hurdle.

Question 7
This question will not satisfy either hurdle.

Question 8
This question will not satisfy either hurdle.

delete_first should not change the data fields of list nodes.

delete_last should not use arrays.

delete_last should not call malloc.

delete_last should not call scanf (or getchar or fgets).

delete_last should not print anything. It should not call printf.

Do not change the supplied main function. It will not be tested or marked.

You can autotest this code with 1091 autotest-pracexam prac_q4
You can submit this code with give dp1091 prac_q4 prac_q4.c
You can check your submission has been accepted with 1091 classrun -check prac_q4
You can see your previous autotests here

In the final exam, question 5 will be an arrays question, more difficult than question 3.

In the final exam, question 6 will be a linked lists question, more difficult than question 4.

In the final exam, question 7 will be a challenging question.

In the final exam, question 8 will be a very challenging question.

https://cgi.cse.unsw.edu.au/~dp1091/21T2/flask_tutors.cgi/student/dpst1091/5331710/autotest/prac_q4/