Starting from:

$16

COMP 2401 -- Assignment #2

Goal
You will write a program in C, in the Ubuntu Linux shell environment, to simulate the use and operation of a function call stack. Every time a function is called, a new stack frame is created to contain information about that function, and the stack frame is added to the function call stack in LIFO (last-in-first-out) order. When the function returns, the corresponding frame is removed from the call stack.In this assignment, you will:• define the data types and structures required to represent the function call stack; you will use arrays to represent all collections of data• write a main function that prompts the user for a collection of integers and calls one of two given sum functions (one iterative and one recursive) to add the integers together• modify the given sum functions to call instrumentation functions upon entry and return• write two instrumentation functions: one that initializes and adds a frame to the function call stack when a sum function is entered, and one that removes a frame from the call stack when a sum function returns; both instrumentation functions output the contents of the call stackLearning Objectives• understand and modify existing code• work with arrays and perform simple pointer manipulations• get familiar with the basic operation of the function call stack mechanism• compare the operation of the call stack using iterative and recursive function calls• practice pass-by-value and pass-by-reference parameter passing• use standard I/O function calls to interact with a user• integrate basic error checking with user I/OInstructions1. Main and supporting functionsWrite a main function and supporting functions that do the following:• define the function call stack variableo there must be only one instance of the function call stack in the entire program; do not make copies!o this is not a global variable• prompt the user to input the values of an integer array; you can start by prompting for the number of integers• prompt the user to select which sum function to call (iterative or recursive)• call the appropriate sum function; you will use the code for the sum functions found here: a2Loop.c• display the resulting sum to the userYour program must use the definitions in the header file found here: a2Defs.hCOMP 2401 -- Assignment #2 Fall 2013 2/32. Data typesModify the given header file to define the following data types required to simulate the function call stack:• StackType corresponds to the function call stack and holds the frames currently on the stack• FrameType holds the data for a frame corresponding to a specific function; this includes the function name and information about its parameters• VarType holds the information for a specific parameterThe data types that you define must work with the stack utility functions found here: a2Stack.c3. Instrumenting the sum functionsModify both sumIterative and sumRecursive functions (found in a2Loop.c) to call the instrumentation functions on entry and return. The sum functions must call enterSumFunc immediately upon entry to initialize a stack frame corresponding to the sum function. They must call leaveSumFunc when the sum function returns.4. Instrumentation functionsImplement the two instrumentation functions:void enterSumFunc(StackType *stkPtr, char *fname, int num, int *arr, int *sum)void leaveSumFunc(StackType *stkPtr)• enterSumFunc creates a new stack frame to store information about one of the sum functions, including its name (sumIterative or sumRecursive) and the parameters passed to it; enterSumFunc must:o initialize a new stack frameo set the frame’s function name to the value in fnameo initialize the frame’s parameter data with information about the parameters passed to the sum function num represents the number of elements to be added together by the sum function arr is the array of integers to be added together sum points to the result of the sum functiono add the new frame as the next frame in LIFO sequence on the call stack pointed to by stkPtro output the contents of the function call stack, using the given dumpStack function• leaveSumFunc prints out the contents of the function call stack when one of the sum functions returns, using the given dumpStack functionConstraints• Design:o you must separate your code into modular, reusable functionso never use global variableso compound data types must be passed by reference, not by value• Reuse:o you must include the given header file in your program and use its function prototypes exactly as definedo you must use the sum functions found here: a2Loop.co you must use, without modification, the stack utility functions found here: a2Stack.c• Implementation:o your program must perform all basic error checkingo it must be thoroughly commented• Executiono programs that do not compile, do not execute, or violate any constraint are subject to severe deductionsCOMP 2401 -- Assignment #2 Fall 2013 3/3SubmissionYou will submit in cuLearn, before the due date and time, one tar file that includes all the following:• all source and header files• a readme file, which must include:o a preamble (program author(s), purpose, list of source/header/data files)o exact compilation command(s)o launching and operating instructionsGrading• Marking breakdown:ComponentMarksmain and support functions25data types20instrumenting sum functions20instrumentation functions35• Assignment grade: Your grade will be computed based on two criteria:o completeness of the program functionality and its executiono quality of the implementation You must familiarize yourself with the grading rules• Bonus marks: Up to 5 extra marks are available for fun and creative additional features

More products