CS计算机代考程序代写 concurrency SOFT3410 Tutorial 0

SOFT3410 Tutorial 0
Exercises

These are a set of problems to get started with before your first lab. Feel free to discuss these problems
on Ed.

Question 1: Hello From C

Write a Hello, World! program in C that outputs the following.

int main() {
puts(“Hello, World!”);

}

Question 2: Reverse Array

Write a function that reverses an integer array,

I would encourage you write a reverse function that is in place. By this we mean that you do not copy
the contents into another array and only use the array given.

1 If you have an array that is:
2 { 1, 2, 3, 4, 5, 6, 7, 8 }
3

4 the reverse:
5 { 8, 7, 6, 5, 4, 3, 2, 1 }

Question 3

Ordering from the centre Your friend has proposed a nasty question, they want you to rearrange an
array so that the elements are ordered from the centre of the array. Given an array of [1, 2, 3,
4, 5], they want the array to be rearranged to [5, 3, 1, 2, 4].

State your assumptions while developing a solution and discuss your approach with your tutor and
peers.

1

SOFT3410 Exercises

Question 4: Tiles

You will need to compose a character image where segments of the image are tiles. A tile itself is
composed of y rows of x length of a single character.

The maximum resolution of your image is 128 x 128 and can support up to 32 tiles. If a tile’s character
changes, the image itself will be different. A tile can be used multiple times in an image.

Since it is possible for tiles to over-lap each other, you can assume a tile draw queue where the first
draw will be beneath any subsequent draw.

Example of a 30×10 image with the following tile set, where each element is specified by (width,
height, character).

(4, 4, @), used at (0, 0), (15, 2)

(3, 2, #), used at (2, 1)

(2, 4, *), used at (14, 2)

1 ——————————
2 @@@@
3 @@###
4 @@### **@@@
5 @@@@ **@@@
6 **@@@
7 **@@@
8

9 ——————————

If the first tile in the tile set, has their character changed to ,̂ we will see the following result.

1 ——————————
2 ^^^^
3 ^^###
4 ^^### **^^^
5 ^^^^ **^^^
6 **^^^
7 **^^^
8

9 ——————————

Concurrency Page 2 of 3

SOFT3410 Exercises

Question 5: Linked List

Implement a singularly linked list in C, the last element of the list must point to NULL to indicate the
end of the list and a condition to stop when traversing. You can use the following definition to get
started.

struct linkedlist_node {
struct linkedlist_node* next;
int element.

};

struct linkedlist {
struct linkedlist_node* head;
size_t size;

};

void list_add(struct linkedlist* l, int element);
void list_remove(struct linkedlist* l, size_t index);
void list_destroy(struct linkedlist* l);
int list_get(struct linkedlist* l, size_t index);

Concurrency Page 3 of 3