Test 2 Flashcards

1
Q

Creating a table in SQL with restricted choice

A

CREATE TABLE user (
username VARCHAR(20) NOT NULL PRIMARY KEY,
password VARCHAR(20) NOT NULL,
gender VARCHAR NOT NULL CHECK(gender = “male” or gender = “female”),
nickname VARCHAR(20) NOT NULL,
FOREIGN KEY nickname REFERENCES score(nickname)
);

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

SQL query in php with a established connection

A
leftarrow ?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
die(“Connection failed: “ . $conn->connect_error);
}

$sql = "SELECT id, firstname, lastname FROM MyGuests";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "br>";
  }
} else {
  echo "0 results";
}
$conn->close();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Insert Query

A

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES (‘Cardinal’, ‘Tom B. Erichsen’, ‘Skagen 21’, ‘Stavanger’, ‘4006’, ‘Norway’);

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

Update Query

A

UPDATE Customers
SET ContactName = ‘Alfred Schmidt’, City= ‘Frankfurt’
WHERE CustomerID = 1;

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

Delete Query

A

DELETE FROM Customers WHERE CustomerName=’Alfreds Futterkiste’;

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

What does a binary search look like?

A
def BinarySearch1(searchlist1,goal):
 found = False
 startpos = 0
 endpos = len(searchlist) -1

#print (“Endpos at beginning = “,endpos)

while (startpos <= endpos) and found == False:
middle = (startpos+endpos)//2 #Integer Division
if searchlist[middle] == goal:
found = True
elif searchlist[middle] smaller than goal:
startpos = middle + 1
else:
endpos = middle -1

if found == True:
print(“Match has been found at position”,middle)
else:
print(“Goal not found”)

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

What does a bubble sort look like?

A

def bubbleSort(beforeName, beforeScore):

for outer in range (len(beforeScore) -1,0,-1):
    for inner in range(outer):
        if beforeScore[inner]>beforeScore[inner+1]:
            temp = beforeScore[inner]
            tempName = beforeName[inner]
            beforeScore[inner] = beforeScore[inner+1]
            beforeName[inner] = beforeName[inner+1]
            beforeScore[inner+1] = temp
            beforeName[inner+1] = tempName

print(beforeScore, beforeName)

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

What does an insertion sort look like?

A

def insertionSort(beforeName, beforeScore):

for index in range(1,len(beforeScore)):
    currentval = beforeScore[index]
    currentName = beforeName[index]
    position = index
    while position > 0 and (beforeScore [position-1] > currentval):
        beforeScore[position] = beforeScore[position-1]
        beforeName[position] = beforeName[position-1]
        position = position - 1
    beforeScore[position] = currentval
    beforeName[position] = currentName

print(beforeScore, beforeName)

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

How to create a 2D array

A

map = [[’.’ for col in range(0,30)] for row in range(0,10)]

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

What does instantiation mean

A

An object that has been created which contains the methods and attributes of a particular class e.g. Aiden is an instantiation of a human class

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

What is a class

A

A template for a particular object e.g. a car class has information about wheels, colour, engine, seats, speed and methods that can manipulate these values.

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

What does encapsulation mean

A

Attributes of an instantiation of a class are private and can only be changed using the setter and getter methods. E.g. a car’s speed can only be changed using car.accelerate() and car.decelerate() methods

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

What does polymorphism mean

A

When a subclass has a method of the same name as its superclass but the functionality is different. For example car superclass has an accelerate method which increases speed by 10 but a toycar subclass has an accelerate method which plays a sound effect of a car. This means that program code doesn’t have to know which class of car is being passed into it.

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

What does inheritance mean

A

Where a class can be set up as a subclass of another class (superclass) and this automatically inherits the attributes and methods of it’s parent. For example toycar has all the attributes of car - colour, speed, engine, seats, wheels

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

What does a constructor do

A

Creates an instantiation of a class with default attribute values

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

Constraints within a project

A

Time, technology, labour, cost and if one of them is changed, they all change

17
Q

Code to create a form with php action

A

html>
body>

h1> Tennis Form /h1>

form action=”/TennisSetSession.php” method=”get”>
label for=”Name”> Full Name: /label>br>
input type=”text” id=”Name” name=”Name”>br>br>

label for="ExperienceLevel"> Level Of Experience: /label>br>
input type="radio" id="Colour" name="colour" value="Green">
label for="Colour"> Green /label>br>
input type="radio" id="Colour" name="colour" value="Yellow">
label for="Colour"> Yellow /label>br>
input type="radio" id="Colour" name="colour" value="Red">
label for="Colour"> Red /label>br>br>

label for="Day">Choose A Day For Your Lesson: /label>br>
select id="Day" name="Day">
	option value="Tuesday">Tuesday /option>
	option value="Thursday">Thursday /option>
	option value="Saturday">Saturday /option>
/select>br>br>

label for="Time">Choose A Time For Your Lesson:/label>br>
select id="Time" name="Time">
	option value="9:00am">9:00am /option>
	option value="11:00am">11:00am /option>
	option value="1:00pm">1:00pm /option>
/select>br>br>

input type="submit" value="Submit"> /form>

/body>
/html>

18
Q

Form Types

A

submit
radio
checkbox
button

19
Q

Examples of session variables

A

?php

session_start();
?>
!DOCTYPE html>
html>
body>

?php

$_SESSION["Name"] = $_GET["Name"];
$_SESSION["Colour"] = $_GET["colour"];
$_SESSION["Day"] = $_GET["Day"];
$_SESSION["Time"] = $_GET["Time"];
echo "Thank You For Booking A Lesson With Mr Bringleberry.";

?>

/body>
/html>

20
Q

Setting up a server and destroying it

A
?php
session_start();
?>
!DOCTYPE html>
html>
body>

?php
// remove all session variables
session_unset();

// destroy the session
session_destroy();
?>

/body>
/html>