Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Do you guys have any idea with number 2?? we are using C in this work. Assignment 1 (5% of Course Total) Due date: 11:59pm,

image text in transcribedimage text in transcribedDo you guys have any idea with number 2??

we are using C in this work.

Assignment 1 (5\% of Course Total) Due date: 11:59pm, Jan 27, 2023 The assignment will be graded automatically. Make sure that your code compiles without warnings/errors and produces the required output. Also use the file names and structures indicated as requested. Deviation from that might result in 0 mark. Your code MUST compile and run in the CSIL machines with the Makefile provided. It is possible that even with warnings your code would compile. But this still indicates there is something wrong with you code and you have to fix them, or marks will be deducted. Your code MUST be readable and have reasonable documentation (comments) explaining what it does. Use your own judgement, for example, no need to explain i+=2 is increasing i by 2 , but explain how variables are used to achieve something, what a certain loop is doing, and the purpose of each \#include. Description There is a total of 3 questions in this assignment. For each question, write your answer in a single file that contains your student information. Unless otherwise specified, do not include any libraries. You can however write your own helper functions. Also do not print anything unless the question asks you to do so. None of these files should contain the main function. Question 1 [5 marks] Write a function that inserts a provided digit into a positive int up to 4 digits long and returns the result as a positive int with this rule: insert as first, third, fifth, ...etc. Use this function header: unsigned int insert_digit(unsigned int digit, unsigned int number) For example (you can assume the number does not have leading zeros, but the digit can be zero): insert_digit (1,3) should return 131 insert_digit(2,123) should return 2122232 insert_digit(0, 4444) should return 40404040 (no leading zero) Only include the function definition (and your helper functions, if any) in the source file and name it as a1_question1.c. Do not use recursion in your answer. Question 2 [5 marks] Write a function that takes in 6 parameters: a char* array, its size, another char* array, its size, a char array as the target, and an int array of size 2 ; and performs the following: Find the index of a cstring from the first char* array and the index of another cstring from the second char* array, where those two cstrings will form the target cstring, and put those indexes into the int array. If there are multiple answers, any answer will do. If no answer exists, put the values 1,1 in the int array. Use this function header: void findElements(char* arrA[], unsigned int sizeA, char* arrB[], unsigned int sizeB, char* target, int* result) For example: For example: Given the arrA: {"ch","a,"A,N cat", "jump", "rep", "c"\} and the arrB: {"3", "at", "ch", "ed", "I", "hat" } Given the 4220 array matrix1: {{1,1},{1,1},{1,1},{1,1}} findelements[arra, 7 , arrB, 6, "chat", result) should put the values 0,1 in result (6, 5 will also work, but calculateAreaShoelace (4, matrix 1,1) returns 2.0 (area of a triangle with the second point removed) not 0,5 ) calculateAreaShoelace (4, matrix1,4) returns 4.0 (area of a square as 4 is an invalid index) findElements[arrA, 7, arrB, 6, " AlN, result) should put the values 2,4 in result calculateAreaShoelace (4, matrix 1,0) retums 2.0 (area of a different triangle with the first point removed) findElements(arrA, 7, arrB, 6,!A, result) should put the values 1,1 in result Note that the area can be zero if the points are all in a straight line or there are not enough points to form findelements(arrA, 7 , arrB, 6,N CMMPT 3", result) should put the values 1,0 in result for partial match a polygon. You can assume that the row argument is correct for the array, and the points in the 2D array findElements[arrA, 7, arrB, 6, "hat ", result) should put the values 1,5 in result for partial match are arranged in a clockwise or anticlockwise manner (required for the Shoelace Formula to work). You can findElements(arrA, 7 , arrB, 6 , "chach", result) should put the values 1,1 in result because two partial also assume that the number of points will not be more than 128. The index can be invalid (negative or matches with extra characters in-between should not be confused with an exact match larger than row-1 and if that is the case it means no row is being removed. findElements(arrA, 7,arrB,6,, result) should put the values 1,1 in result Do not use dynamic arrays and the keyword continue in your answer (if you use any of those you get 0 for You can assume all elements (estrings) in the first and second arrays have at least one character and up this question). Your answer must first calculate S1, then S2, then the area (failure to do so will also get 0 ). to 63 characters, and there is no repetition within the same array. Letters are case-sensitive. Only include the function definition (and your helper functions, if any) in the source file and name it as Only include the function definition (and your helper functions, if any) in the source file and name it as a1_question3.c. a1_question2.c. Do not use recursion in your answer. Coding Style [4 marks] Question 3 [6 marks] Your program should be properly indented, have clear and meaningul variable names (e.g., no single- In mathematics there are formulas for calculating the area of a polygon formed by any number of points. letter variable names except loop iterators) and enough white space and comments to make it easy to One popular formula is called "the shoelace Formula": read. Named constants should be used where appropriate. Each line of code should not exceed 80 characters. White space should be used in a consistent manner. To help you to get into the habit of good coding style, we will read your code and marks will be deducted if your code is not styled properly. Using the Makefile and Other Supplied Files The Makefile provided in this assignment is used by a command in the CSIL machines called "make" to quickly compile your code. It is especially useful if you have multiple source files. To use it, type the following command in the prompt (make sure you are in the directory with all the files of Assignment 1): $ make test1 The example above illustrates how Question 1 is compiled into an executable called "test1" when using Makefile. Replace the "test1" with "test2", "test3", wetc. for other questions. You can then run the executable by typing "./test1" to test your code for Question 1 . If you make changes to your code, use the make command again. You can also use "make all" if you want to compile all your code at once. Write a function that takes in the number of rows (number of columns is fixed at 2) of a 2D array of ints, The test files (test1.c, test2.c, ...etc.) are provided in this assignment for you to test your code. Each the array itself, an integer as the index, and calculates the area of the polygon formed by the points typically contains a main function along with other tester functions and/or calls. You can modify them to represented in the 20 array with the row indicated by the index removed. Use this function header: further test your code, but do not submit these test files because we will be using our test files that are float calculateAreashoelacefunsigned int rows, int points[][2], int index) similar but not identical to grade your assignment. This makes sure that your code is not written to produce hard-coded output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions