INF2611 May/Jun 2017 exam paper — questions
The paper, as written
1 / 6 2 / 6 3 / 6 4 / 6 5 / 6 6 / 6
Every question, by topic
Question 1.1 · Widgets and menus · 4 marks
A menu bar is made up of several menus, and each menu contains several entries. Describe two methods that can be used to add entries to the menu bar.Show the full question
Question 1.2(a) · Widgets and menus · 1 mark
Which class is used to create a dock widget?Show the full question
Question 1.2(b) · Widgets and menus · 2 marks
What is the purpose of using a dock widget?Show the full question
Question 1.2(c) · Widgets and menus · 4 marks
List the four allowable dock areas of the dock widget.Show the full question
Question 1.2(d) · Widgets and menus · 1 mark
State whether the following statement is true or false: the user can drag a dock window completely out of the dock area so that it becomes a free-floating window.Show the full question
Question 2.1 · Database handling · 4 marks
For your assignment project in this subject you connected a GUI application to a database. State the advantages of connecting an application to a database, as you did for your assignment project for this subject.Show the full question
Question 2.2 · Database handling · 4 marks
For your assignment project in this subject you connected a GUI application to a database. Give a brief description of each of the following MySQL data types: Smallint; Char; Varchar; Longblob.Show the full question
Question 2.3.1 · Database handling · 4 marks
For your assignment project in this subject you connected a GUI application to a database. Consider the Python script createtable.py, which imports sys and MySQLdb, then opens a connection with conn=MySQLdb.connect(host="localhost", user="root", passwd="psw", db="database"), creates a cursor, and inside a try block executes a CREATE TABLE statement for a table called products with columns prod_id smallint NOT NULL, prod_name char(50), quantity smallint, and price float; if a MySQLdb.Error occurs it prints "Error in creating products table" and exits, after which the cursor and connection are closed. One of the methods used in this code is connect(), which establishes a connection to the database server. State the four parameters required for the connect() method.Show the full question
Question 2.3.2 · Database handling · 6 marks
For your assignment project in this subject you connected a GUI application to a database. Referring to the same createtable.py script described above (which uses conn=MySQLdb.connect(...), cursor=conn.cursor(), cursor.execute(...) to create the products table, followed by cursor.close() and conn.close()), name and explain the three remaining database-related methods used in the code besides connect().Show the full question
Question 3.1 · Database handling · 5 marks
A table called books was created inside a database named bookstore. The books table has four fields: book_isbn defined as smallint(6), book_name defined as char(50), quantity defined as smallint(6), and price defined as float (none of the fields have Null, Key, Default or Extra attributes specified). Write the Python code that will insert a new record into the books table and then print a message confirming that one row was added to the books table. The record to be inserted has book_isbn 978409506, book_name 'Python for you', quantity 1, and price 100. The code should follow the structure of the insertrec.py script, which imports MySQLdb, connects to the bookstore database on host 'localhost' with user 'root' and password 'psw', creates a cursor, executes the insert statement, closes the cursor, commits the transaction, and closes the connection, producing the output 'One row inserted into the books table'.Show the full question
Question 3.2 · Database handling · 10 marks
A table called books was created inside a database named bookstore. The books table has four fields: book_isbn defined as smallint(6), book_name defined as char(50), quantity defined as smallint(6), and price defined as float (none of the fields have Null, Key, Default or Extra attributes specified). Write the Python code that retrieves and displays all the rows from the books table, following the structure of the disprec1.py script which imports sys and MySQLdb, connects to the database on host 'localhost' with user 'root' and password 'psw', creates a cursor, and then closes the cursor and connection. The program must also display an error message if the books table contains no entries. The expected output, when the table contains data, is a listing of columns Book ISBN, Book Name, Quantity and Price, for example showing 978409506, Python for you, 1, and 100 as the values for one row.Show the full question
Question 3.3 · Database handling · 10 marks
A table called books was created inside a database named bookstore. The books table has four fields: book_isbn defined as smallint(6), book_name defined as char(50), quantity defined as smallint(6), and price defined as float (none of the fields have Null, Key, Default or Extra attributes specified). Write the Python code that searches for a record in the books table based on a book_isbn value entered by the user, following the structure of the sqlenquiry.py script which imports MySQLdb, connects to the database on host 'localhost' with user 'root' and password 'psw', creates a cursor, and then closes the cursor and connection. The program must display a message if the entered book_isbn is not found. For example, if the user enters 978409506, the output should read 'Information of the Book with ISBN 978409506 is as follows: ISBN: 978409506, Book Name: Python for you, Quantity: 1, Price: 100'; alternatively, if the user enters 978409500, the output should read 'Sorry no Book found with ISBN 978409500'.Show the full question
Question 4.1 · Database handling · 1 mark
These questions relate to building GUI applications in PyQt that connect to and interact with database tables. Name the class that must be used to integrate a database with PyQt.Show the full question
Question 4.2 · Database handling · 8 marks
These questions relate to building GUI applications in PyQt that connect to and interact with database tables. Describe any four methods belonging to the class used to integrate a database with PyQt.Show the full question
Question 4.3 · Database handling · 2 marks
These questions relate to building GUI applications in PyQt that connect to and interact with database tables. Explain how all the rows of a database table can be displayed in tabular format within a GUI application.Show the full question
Question 4.4 · Database handling · 4 marks
These questions relate to building GUI applications in PyQt that connect to and interact with database tables. Name and describe two methods of the QSqlTableModel class that are used to display rows fetched from a database table.Show the full question