1. AimThe aim of this assignment is for you to gain some practice in C programming, to use C libraries and system calls, and to demonstrate your understanding of C and how to program to a defined interface.2. Learning/skills outcomesC programming skillsProgramming to defined interfacesFormulate problems and identify suitable approaches to solving themCognitive/intellectual skills and self management (see graduate skills framework)3. SpecificationThis assignment has three parts:1. Write a library of simple arithmetic functions (4 marks)2. Write a library of utilities to read and process user input (8 marks)3. Write a simple command line shell (8 marks)Note we will test your solution programmatically on MINIX. It is very important that you follow the rules below for the form of your solutions and their submission. For example, do not deviate from the file names specified. If you do not adhere to the rules, you will loose marks even if your solution is logically correct. An important purpose of this assignment is for you to demonstrate that you can understand an interface definition and program to that definition. It is also important that your code executes correctly on MINIX.You will also have to test your solutions yourself. We will not mark these tests and they should not be submitted. The files that you submit are:intmath.h ? unmodified, provided for youintmath.c ? your implementation of the functions defined in intmath.hutils.h ? unmodified, provided for youutils.c ? your implementation of the functions defined in utils.hmyshell.c ? your implemenation of a simple shel that uses the functions defined in utils.hIn intmath.c, utils.c and myshell.c you may find it useful to define and implement additional helper functions additional that are not defined in the header files. That is OK. It is up to you how you organise your solution provided you implement the functions defined in the header files and the simple shell program that uses the functions defined in utils.h.Part 1 ? Library of simple arithmetic functionsIn this part you will implement the following four simple arithmetic functions:int add(int x, int y)adding x to y and returning the resultint subtract(int x, int y)subtracting y from x and returning the resultint divide(int n, int d)integer division of the numerator (dividend) n by the denominator (divisor) d and returning the resultint modulo(int n, int d)integer division of the numerator (dividend) n by the denominator (divisor) d and returning the remainderint division(int n, int d, int &r)integer division of the numerator (dividend) n by the denominator (divisor) d, returning the result and recording the remainder on rTo get full marks for this part you must follow the following rules. Any deviation from the rules could result in a mark of 0 for this part.Rules for part 11. The functions are defined in intmath.h. The comments to each function define the contract between yourself and the user of these functions. Your implementations must satisfy the contract. For example, you must detect and signal integer overflow using the ERANGE value for errno. Division by zero is a domain error, which you must signal with the EDOM errno.2. You must implement the functions in a separate intmath.c file that includes intmath.h.CLICK HERE FOR MORE INFORMATION ON THIS PAPER? PRICE?..3. intmath.c must not have a main function.4. You can only use the ++ and ? unary increment and decrement operators in your calculations. That is, you must not use +, -, / or % in any of your calculations. You can use ? as a unary operator to negate a number.To emphasise, the following are allowed in your implementation of the arithmetic functions:x++ x? ?x ++x -x No other built-in arithmetic operators are allowed. That is, the following are forbidden:x ? y x + y x / y x % y x * y You may use the full range of built-in arithmetic operators to test your solution. In fact, you will almost certainly have to use all the operators to test your solution (with the possible exception of multiplication).HintsYou can avoid code duplication in this task. E.g. think about how to use subtract for certain inputs to add and how to write some functions in terms of others.Be particularly careful when INT_MIN is the numerator or denominator in division.Part 1 deliverablesThe deliverables for part 1 are the files intmath.h and intmath.cPlan your time and do not spend too long on this part. Parts 2 and 3 do not depend on it. However, you should find it easier to approach the other parts if you complete this part.Part 2 ? Library of user input utilsIn this part you will implement the following three utility functions:int getaline(char* linebuf, int bufsize)to read a line of user input from stdin into the character buffer linebuf. After execution, the function should return the count of characters read into the buffer and linebuf should represent a string, terminated with the null character (??). The returned count does not include the null character. bufsize is the size of linebuf. Therefore, the returned count will be at most bufsize ? 1int split(char *s, int start, char sep, char **substrings, int max)to split the null-terminated input string s into at most max substrings. The string should be split at each occurrence of the sep character until at most max substrings are found. The first substring should start at position start (which may be 0). The use of a start position allows for pre-processing of s (e.g. to ignore leading characters ? see trim). After execution, the function should return the number of substrings identified. The input string s will now be a buffer of null-terminated substrings. Each element of the substrings array will be a pointer to the start of a substring in s up to max substrings. If there are less than max substrings, the unused elements at the end of substrings should be set to NULL. When splitting the input string, multiple consecutive occurrences of the sep character within the string (as opposed to at the beginning or end of the string) should be ignored. It is possible for there to be more thanmax substrings in s, in which case the final string in the substrings array will contain separator characters.int trim(char *s, char c)to trim the null-terminated input string s (removing leading and trailing runs of the specified character, c). This function returns the position of the first character that is not the specified character in string s and terminates the string s after the last character that is not the specified character. In effect, trim allows the user of the function to skip a sequence of leading characters at the start of s and truncates s at the first occurrence of a trailing sequence of 1 or more of the specified character(s). s is modified as a result. The string from the returned start value may contain the specified character but there will leading or trailing sequences of the character. If the return value is -1, then s is a string that only contains the specified character and no other characters (apart from the string terminator character). A return value of 0 means that there is no leading sequence of separator characters.Rules for part 21. The functions are defined in utils.h. The comments to each function define the contract between yourself and the user of these functions. Your implementations must satisfy the contract and the descriptions above.2. You must implement the functions in a separate utils.c file that includes utils.h3. utils.c must not contain a main function.4. The only C library function you can use in your implementation is getchar in stdio to read characters one at a time from stdin. You must not use any other library functions. That is, use of the C library getline function or any string processing library functions is forbidden.CLICK HERE FOR MORE INFORMATION ON THIS PAPER? PRICE?..Example usageThe following program shows example usage of the three functions: getaline, trim and split.#include
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.Read more
Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.Read more
Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.Read more
Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.Read more
By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.Read more