CSCI 159: exam practice questions

These are just meant as a way to get some practice answering exam-style questions with pen/paper. I'd encourage students to attempt them with minimal references to their notes, but for the final exam you will be permitted one double-sided sheet of notes.

There is one question on each side of the page.

After you've attempted the question, a good way to evaluate your answer while also getting additional practice is to coding and compiling/running the answer you came up with.

Question 1: struct definitions

(i) Write the declaration for a struct datatype, ItemData, with three fields: (ii) In a main routine, write code to declare a variable of type ItemData and set its field contents to "Fancy Widget", 19.99, and 314.
(Suggestion: strcpy(str, "blah blah blah") can be used to copy a text string into a char array.)

Question 2: Arrays of structs

Write a function that takes two parameters: an array of ItemData elements and the array size, and for each item in the array displays the item name and the value of the in-stock items (i.e. that item's price times its quantity).