Programming Questions Flashcards

1
Q

What is required for a queue?

A

Start pointer, rear pointer, current size, maximum size and an array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Create a new database called ‘rent’

A
$sql = "CREATE DATABASE 'rent'"
$result = $connection ->query($sql)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Write SQL code to check if there has been a connection error

A

if(mysqli_connect_errno()){
echo “error message”
exit();
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Close a database connection

A

mysqli_close($connection)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Write SQL code to connect to a database called school with the password ‘12345’ and the username teacher

A

$connection = new mysqli(“localhost”,”teacher”,”12345”,”school”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write a SQL statement that inserts ‘Charles Boyle’ ‘Detective’ into the table cops to the attributes name and job respectively

A

INSERT INTO cops(name,job)

VALUES(‘Charles Boyle’,’Detective’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write an Update SQL statement to update the table pupil and change the pupil second name to ‘Davis’ where pupil ID is 34

A

UPDATE pupil
SET pupil.secondname = ‘Davis’
WHERE pupil.id = 34;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write SQL code to delete all from the table school

A

DELETE * FROM school;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write SQL code to select all the records where the year of the pupil is greater than 4th year and order by DESC in pupil age from pupil table

A

SELECT * FROM pupil WHERE pupil.year > 4 ORDER BY pupil.age DESC;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Write a delete track function on a Playlist where index in passed in and the instance variables in the class are self.maxLength, self.tracks, self.nextTrack

A
def deleteTrack(self,index):
if index > self.maxLength or index < 0:
print("Invalid index")
else:
for item in range(index, self.nextTrack-1):
self.tracks[item] = self.tracks[item+1]
end for
self.nextTrack = self.nextTrack - 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
Write a class AlbumnTrack and init subroutine that inherits all it's instance variables from the Track class and then has another instance variable called albumnname 
Title, artist and length are passed into track initiation
A
class AlbumnTrack(Track):
def \_\_init\_\_(self,title,artist,length,albumnname):
Track.\_\_init\_\_(self,title,artist,length)
self.albumnname = albumnname
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
Write code to define a class Athlete which has instance values age, name, event and has a method to display all the information 
Event should be default competitor if no event is given during instantiation
A
class Athlete:
def \_\_init\_\_(self,age,name,event="Competitor"):
self.age = age
self.name = name
self.event = event 
def display(self):
print("Age:" , self.age)
print("Name:", self.name)
print("Event:", self.event)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Write PHP code to sanitize username which has come in by the get method

A

$username = filter_var($_GET[‘username’], FILTER_SANITIZE_STRING);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Write PHP to receive the value from the radio box of the 2018 tony best musical nominations which were sent under the name ‘Best Musical’ and using post

A

$result = $_POST[‘Best Musical’]

echo $result

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Write the start of the stack class without the push or pop

A
class Stack:
def \_\_init\_\_(self,size):
self.stack = [] * size
self.stackPointer = 0
self.size = 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Write a push action for a stack class

A
def push(self,value):
if self.stackPointer == self.size

else:

self. stack[self.StackPointer] = value
self. stackPointer = self.stackPointer + 1

17
Q

Write a pop action for a stack class

A
def Pop(self):
if self.stackPointer == 0:

else:
self.stackPointer = self.stackPointer - 1
return self.stack[self.stackPointer]

18
Q

Write the start of the Queue class without the join and the leave functions

A
class Queue
def \_\_Init\_\_(self,size):
self.start = 0
self.rear = 0 
self.currentSize = 0
self.maxSize = size
self.queue = [] * self.maxSize
19
Q

Write the join procedure for queue

A
def Join(self,data):
if self.currentSize = self.maxSize:

else:

self. queue[self.rear] = data
self. rear = self.rear + 1
self. currentSize = self.currentSize + 1

if self.rear > self.maxSize:
self.rear = 1

20
Q

Write the leave function for a queue

A
def Leave(self):
if self.currentSize = 0:
return 0 
else:
return self.queue[self.start]
self.queue[self.start] = 0
self.currentSize = self.currentSize - 1
self.start = self.start + 1
if self.start > self.maxSize:
self.start = 1
21
Q

Write a procedure to set up a linked list

A

PROCEDURE setuplist()
DECLARE data INTEGER INITIALLY 0
DECLARE head POINTER INITIALLY NULL
END PROCEDURE

22
Q

Write a procedure to add a new node to a linked list

A
PROCEDURE newNode(data, next):
IF head = NULL THEN

next = NULL
ELSE

next = NULL
END IF
END PROCEDURE