程序代做CS代考 compiler concurrency algorithm SOFT3410 Tutorial 1 Introduction to C – cscodehelp代写

SOFT3410 Tutorial 1 Introduction to C
Question 1: Setting up
By now, you should have your C compiler set up and an access to a version of Linux, if you have not done this or you have ran into some issues, please notify your tutor about your problems.
Question 2: Hello From C
As a simple starter question for the semester, you are tasked with writing a simple Hello World program. You should utilise the printf or puts function for this task. Discuss with your tutor about the following.
• How are strings represented in C?
• What is #include’s function?
• How does our program get access to puts or printf
Question 3: Maintain a running average
Write a program that can calculate the mean, variance and standard deviation for a given set of num- bers. Your program should read the numbers from standard input until EOF. You can assume that the input will always contain valid numbers, and ignore any invalid input. You should print all results to 4 decimal places.
Mean
m(X) = 􏰀X N
Variance
Var(X)=N1 􏰀Ni=0(xi−m)2 Standard Deviation
σ(X) = 􏱂Var(X)
1

SOFT3410 Introduction to C
Question 4: Pointer and Arrays
Given these pointer statements, can you provide an equivalent statement?
*p =
(p+10)[0] =
&r[20] =
&(g[0]) =
&*p =
p++ =
&((r[5])[5]) = (&(p+10)[20])[1] =
What is the difference between pointers and arrays? Can we mix notation?
Question 5: 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 }
Concurrency
Page 2 of 5

Question 6: Oh my grid!
Construct a path from a source to destination, you will display your map as a grid to standard out- put. Your application will receive source and destination coordinates as commannd line arguments. The first two arguments will relate to the source location and last two arguments will relate to the destination.
Your poinits should be within a 7×6 grid, if the coordinates are out of bounds, your program should outputtheerrorInvalid Coordinatestostandardoutput.
You should utilise Manhattan distance to solve this problem.
1 $ ./grid 1 1 3 4
1 ||||||||
2 ||S||||||
3 ||||||||
4 ||||||||
5 ||||D||||
6 ||||||||
Question 7: Flip Matrix
Given the following code segment, construct a few functions that can perform the following operations on a matrix. You may assume the matrix is a fixed size.
int main() {
int matrix[3][3] = {
1, 2, 3,
4, 5, 6,
7, 8, 9
};
//… horizontal flip, vertical flip, matrix reverse
/*
Horizontal Flip
3, 2, 1,
6, 5, 4, 9, 8, 7
Vertical Flip
7, 8, 9,
4, 5, 6, 1, 2, 3
Matrix Reverse
9, 8, 7,
6, 5, 4,
SOFT3410 Introduction to C
Concurrency
Page 3 of 5

3, 2, 1
*/
return 0; }
• Matrix Reverse • Horizontal Flip • Vertical Flip
Try not to create a second matrix to store the different values.
Afterwards, discuss characteristics of two-dimensional arrays with your peers and tutors.
• How is a two-dimensional array laid out in memory?
• How could we create a jagged array?
• Is the data laid out different between a jagged array and a two-dimensional array?
SOFT3410 Introduction to C
Concurrency
Page 4 of 5

Question 8: Sorting
You are required to implement sorting algorithm using the following types and function parameters. You have been given the a set of structs that will contain x and y coordinates which will named
location. There will be an origin point given to your function that you will need to maintain. What are we sorting? You are sorting using the distance between the origin and the set of locations.
Sort the locations based on their distance to the origin point.
struct location { int x;
int y;
char* name; };
void sort(int origin_x, int origin_y, struct location* locs, unsigned len);
Question 9: Shortest Path in a grid
Using your solution from question 5, you will now modify it and now include a few different tiles that will create a barrier between the source and destination and implement a shortest path algorithm. After finding the shortest, try to record the steps taken so you can draw the pathway from source to destination with these barriers in place.
• X tiles are walls and you will be unable to pass through this
• = tiles show the path between source and destination (You will draw this tile)
• After solving for the case where typical paths are blocked off, introduce a cost associated with each tile (a number between 1-9), this should influence how the path is found
Example of a grid with walls.
1 ||||||||
2 ||S||||||
3 ||||X||||
4 |X|X|X|X|X| | |
5 ||||D||||
6 ||||||||
A possible path from S to D.
1 ||||||||
2 | |S|=|=|=| | |
3 ||||X|=|=||
4 |X|X|X|X|X|=| |
5 ||||D|=|=||
6 ||||||||
SOFT3410 Introduction to C
Concurrency
Page 5 of 5

Leave a Reply

Your email address will not be published. Required fields are marked *