# EE2028A ProgrammingGhostwriter ,Programming ProgrammingHelp With ,Ghostwriter C/C++ Course ProgrammingGhostwriter Statistics,,|Debug Matlab Programming

EE2028A C Programming
Lab Exercise 4
Submission instructions:
2. You must use the code skeleton provided fro Question 1.
3. Feel free to write as many functions as needed for Question 2.
4. Deadline: Wednesday, February 24th / Friday, February 26th
Concepts used: Structures, Pointers, Decision-making statements, loops and C Functions.
Question 1: [30 Marks]
Let us work on the menu of a library. Create a structure containing book information like
accession number, name of author, book title and flag to know whether a book is issued or not.
Create an interactive menu in which the following can be done.
1 - Display book information
2 - Add a new book
3 - Display all the books in the library of a particular author
4 - Display the number of books of a particular title
5 - Display the total number of books in the library
6 - Issue a book
(If we issue a book, then its number gets decreased by 1 and if we add a book, its number gets
increased by 1)
1
2
Sample Output:
Further Instructions:
• As shown in the screen-shot above, the initial number of books in the library is 0
• Displaying a book’s information should include its four attributes (shown in skeleton code).
Use proper printf messages (no standard format is enforced).
• Similarly, for adding a book, prompt the user for all four attributes with proper I/O.
• For displaying all books of a given author, first prompt the user for the author’s name, then
use the same display format in question 1 for all books of that author.
• Displaying the total number of books in the library should exclude all books for which the
issued flag was set to 1
3
Question 2: [20 Marks]
Consider a five-element integer array, answer the following questions in order. You can either
take a user input of the array in the range [-9 ; 9] OR hard-code a five-element array in the
range [-9 ; 9].
1) Write the appropriate code to generate all sub-arrays with at least 2 elements of a
given input array. A subarray is defined as an array that is generated from a given array.
Thus, a subarray comprises elements from the given array, and is of smaller length.
For example, for a given array [7, 2, -1, 2], bellow is the expected I/O:
Note that the sample I/O above is for format illustration purposes only. Your actual
answer needs to handle five-element integer arrays.
2) In the example above, if you consider two-element sub-arrays, possible pairs include the
following shown in the table below. Observe that (7,2) is listed twice, one for each
occurrence of 2. Consider each subarray from your list of all generated subarrays with at
4
least 2 elements, and perform the sum of products for each subarray as shown in the
example above in the table. The sum of products is calculated by considering only the
products of the pairs (i.e. for sub-array [7, 2, -1], the sum of products is [7x2] + [7x(-1)] +
[2x(-1)] = 5. Modify your code from question 1 to match the sample output bellow:
3) Complete the function “largestValue” which takes an array and returns an integer
denoting the largest value of the “sum of products” of any of the sub-arrays generated
following guidelines from questions 1&2. Continuing on the same example, your output
should look like this:
5
For your report, take screenshots of your final answer to Q3 only as illustrated above. You are
required to report on three runs of your program with the following inputs:
• 8 4 -2 6 -5
• -9 4 3 -1 2
• 5 -5 0 3 -9