Programming Questions Flashcards
What is required for a queue?
Start pointer, rear pointer, current size, maximum size and an array
Create a new database called ‘rent’
$sql = "CREATE DATABASE 'rent'" $result = $connection ->query($sql)
Write SQL code to check if there has been a connection error
if(mysqli_connect_errno()){
echo “error message”
exit();
}
Close a database connection
mysqli_close($connection)
Write SQL code to connect to a database called school with the password ‘12345’ and the username teacher
$connection = new mysqli(“localhost”,”teacher”,”12345”,”school”);
Write a SQL statement that inserts ‘Charles Boyle’ ‘Detective’ into the table cops to the attributes name and job respectively
INSERT INTO cops(name,job)
VALUES(‘Charles Boyle’,’Detective’);
Write an Update SQL statement to update the table pupil and change the pupil second name to ‘Davis’ where pupil ID is 34
UPDATE pupil
SET pupil.secondname = ‘Davis’
WHERE pupil.id = 34;
Write SQL code to delete all from the table school
DELETE * FROM school;
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
SELECT * FROM pupil WHERE pupil.year > 4 ORDER BY pupil.age DESC;
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
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
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
class AlbumnTrack(Track): def \_\_init\_\_(self,title,artist,length,albumnname): Track.\_\_init\_\_(self,title,artist,length) self.albumnname = albumnname
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
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)
Write PHP code to sanitize username which has come in by the get method
$username = filter_var($_GET[‘username’], FILTER_SANITIZE_STRING);
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
$result = $_POST[‘Best Musical’]
echo $result
Write the start of the stack class without the push or pop
class Stack: def \_\_init\_\_(self,size): self.stack = [] * size self.stackPointer = 0 self.size = 0