COMP103 Revision: Exam-Style Revision Questions
COMP103 Revision: Exam-Style Revision Questions
Steve, a friend of yours, wants a small C# application built to keep track of who
he loans things to. It needs to store what each person has borrowed, when and
what their phone number is, so he can ring them to get it back. He has made a
start at the application, but he dropped out of 103 and so has got stuck, and has
asked you to help finish the program.
The program will use a data file with the following information: item, name,
phone, date and whether it was returned, e.g.
Pen,Bob Jones,555-1212,08/02/2012,False
Coat,Mary,021-555-999,21/11/2009,True
1
COMP103 intro to Computer Science 1 Revision Questions
1. Indicate on the above screen shot the order of tab index you would assign, what
access keys you would use and what tool tips you would add.
try
{
openFileDialog1.Filter = "Data files|*.dat|All files|*.*";
openFileDialog1.FileName = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
infile = File.OpenText(openFileDialog1.FileName);
if (infile.Peek() != -1)
{
this.Text = "Items borrowed from " +
openFileDialog1.FileName;
}
}
}
catch(Exception error)
{
MessageBox.Show(error.Message, "Error Warning",
MessageBoxButtons.OK, MessageBoxIcons.Exclamation);
}
}
3. Write code for the “List of Items Currently Borrowed” command button click
event. It should read from a file that is already opened in the class variable infile,
each of the items in the file. It should add to the Results Display list box, called
listBoxResults, any items that are currently borrowed (i.e. have not been
returned). Use the following format for the list box entry:
i) Function,
ii) Procedure,
iii) Event Handler,
iv) Method,
v) Object-Oriented Event-Driven Programming Paradigm.
Define each term and give an example.
2
0657.153 Practical Programming Practical Test
5. Describe why, from a GUI design point of view, Steve’s current form interface
is bad. Show on the form below how you could improve his design.
6. Steve is not sure if he wants the results section displayed on the same form or
not. Discuss whether the results should be on the same form, or in a modal
dialogue box, or in a second modeless form. What are the advantages and
disadvantages of each.
7. Steve wants the Find Item command button to only be enabled when an item is
typed in the textBoxItem text box. The text box control has the following events:
i) Change,
ii) Click,
iii) Drag Over,
iv) Got Focus,
v) Lost Focus,
vi) Key Press.
Explain when each event is triggered and which would be best to use to code the
enable action.
3
COMP103 intro to Computer Science 1 Revision Questions
8. Write a ConvertDate method to be used in the following code. Use the Split
command to break up the date given in the format “dd/mm/yyyy” into days,
months and years. For each parameter to this method, indicate whether the
parameter should be by value, out or ref.
10. Steve finds that with the Calc Length Borrowed command, items borrowed over
a year do not change to red like they are supposed to. Describe how the
Debugger tool could be used to help find the error. What is the bug in the code,
and how can he fix it.
11. Steve wonders if storing the information in a list would be better than always
reading from a data file. Design a struct to hold the same information as the file,
showing what fields are required and their type. Write example code to create
and initialise a list of your structs.