Case Study - Set B MG 2
Case Study - Set B MG 2
fig. 1
Work Required:
a. State what is meant by a constant and give an example from the algorithm in fig 1 (2 Marks)
b. What is a variable. Give an example of a variable from the algorithm in fig 1. (3 Marks)
c. State the number of goals that will be output by this algorithm for the following inputs.
Explain how you obtained your answer in each case.
i. Wins = 30 Losses = 25 (2.5 Marks)
ii. Wins = 20 Losses = 5 (2.5 Marks)
Ans:
Question Answer
a A constant is a fixed value that does not change during program execution.
Example: Noise = 10. (2 Marks)
Page 1 of 15
b A variable is a named storage location that holds modifiable data.
Example: Wins, Losses, Goals, Net. (3 Marks)
c(i) Output: Goals = 0. (2.5 Marks)
Explanation: Net = 5, which is not greater than Noise = 10, so the loop does not execute.
c(ii) Output: Goals = 1. (2.5 Marks)
Explanation: Net = 15, so the loop executes once, updating Goals to 1.
Work Required:
a. Write a pseudocode that represents this algorithm. (7 marks)
Ans: Solution 1
BEGIN
DECLARE num_questions, total_time AS INTEGER
SET total_time = 0
PRINT "Enter the number of questions:"
INPUT num_questions
Page 2 of 15
PRINT "Estimated time to complete the worksheet: " total_time " seconds"
END
Solution 2
START
// Step 1: Initialize variables
DECLARE totalSeconds = 0
DECLARE numQuestions
Page 3 of 15
c. Implement in a language you best master (10 marks)
Ans:
#include <stdio.h>
#include <string.h>
int main() {
// Step 1: Initialize variables
int totalSeconds = 0;
int numQuestions;
char difficulty[10];
Page 4 of 15
// Step 2: Ask for the number of questions
printf("Enter the number of questions: ");
scanf("%d", &numQuestions);
return 0;
}
Ans :
Term Definition
Data Abstraction Hiding internal details and showing only essential features of an object.
Encapsulation Bundling data and methods into a single unit and restricting access to data.
Polymorphism Ability of an object to take on many forms (e.g., method overloading/overriding).
Inheritance Mechanism where a subclass inherits properties and behaviors from a superclass.
Class Blueprint for creating objects, defining their properties and behaviors.
Page 5 of 15
§ Train number
§ Train Name
§ Source
§ Destination
§ Journey Date
§ Capacity
Member functions
§ Initialize members
§ Input train data
§ Display data
Work Required:
A. Write a code in an object-oriented language you master (C++/Java) to text the train class. (7
marks)
class Train {
private:
int trainNumber;
string trainName;
string source;
string destination;
string journeyDate;
int capacity;
public:
// Constructor to initialize members
Train() : trainNumber(0), trainName(""), source(""), destination(""),
journeyDate(""), capacity(0) {}
Page 6 of 15
getline(cin, destination);
cout << "Enter Journey Date (YYYY-MM-DD): ";
getline(cin, journeyDate);
cout << "Enter Capacity: ";
cin >> capacity;
}
int main() {
Train t;
t.inputTrainData();
t.displayTrainData();
return 0;
}
Animals (ID: integer, Name: string, PrevOwner: string, DateAdmitted: date, Type: string)
Adopter (SIN: integer, Name: string, Address: string, OtherAnimals: integer)
Adoption (AnimalID: integer, SIN: integer, AdoptDate: date, chipNo: integer)
Where:
a. The primary keys are underlined.
b. Animals stores information about the animals currently at the Humane Society. Each is
given an ID, and their names together with the SIN of their previous owners (attribute
PrevOwner), and their date of admission is recorded. Type refers to the type of animal
(dog, cat, etc).
Page 7 of 15
c. Adopter is the relation that holds information about animal adopters. The at- tributes are
self-descriptive, except OtherAnimals which records the number of other animals that the
adopter currently has at home.
d. AnimalID in Adoption refers to the ID of Animals. Similarly, SIN in Adoption refers to
the SIN of Adopter. Attribute chipNo stores the number on the microchip that is implanted
on the animal for tracking. Owner in Animals refers to the SIN of Adopter (in this case
the previous adopter).
Work Required: Formulate the following queries in SQL;
i. Retrieve the total number of dogs that were brought to the Humane Society on 18 April
2000. (2 marks)
SELECT COUNT( ∗ )
FROM Animals
WHERE Type = “dog”
AND DateAdmitted = “2000-04-18”
ii. List the name of the adopter who has adopted every type of animal. (2 marks)
SELECT Name
FROM Adopter
WHERE NOT EXISTS
(SELECT ∗
FROM Animals A1
WHERE NOT EXISTS
(SELECT ∗
FROM Adoption, Animals A2
WHERE AnimalID = A2.ID
AND A2.Type = A1.Type
AND Adoption.SIN = Adopter.SIN ))
Page 8 of 15
Or Using Joins
SELECT A.Name
FROM Adopter A
WHERE NOT EXISTS (
SELECT DISTINCT Type
FROM Animals
EXCEPT
SELECT DISTINCT An.Type
FROM Adoption Ad
JOIN Animals An ON Ad.AnimalID = An.ID
WHERE Ad.SIN = A.SIN
);
iii. For each animal type, list the animal type and total number of adoptions on 14 June 1999.
(2 marks)
SELECT Type, COUNT( ∗ )
FROM Animals , Adoption
WHERE AdoptDate = “14 / 06 / 1999” AND Animals . ID = Adoption . AnimalID
GROUP BY Type ;
iv. List the types of animals who have not had any adoptions. (2 marks)
SELECT DISTINCT Type
FROM Animals
WHERE NOT EXISTS
(SELECT∗
FROM Adoption
WHERE Adoption.AnimalID = Animals.ID)
v. For each adopter who has made at least two adoptions, list their names and addresses. (2 marks)
Page 9 of 15
B. Consider the ER model given in Figure 1. This model represents the operations of a pharmacy chain.
Please answer the following questions regarding this model.
Page 10 of 15
All information about these drugs are deleted from the database as well. This is due to the fact
that Drug is a weak entity of Pharmaceutical Co. entity and instances of Drug cannot exist without
the existence of their strong entity instance.
iii. Similar to part (b), but instead of deleting the pharmaceutical company, what if we delete the
pharmacy that sells the drug. Do we have to delete the drug too? Why or why not? (1 mark)
In this case nothing happens, i.e., we do not have to delete the drug. This is because there is no
weak entity-strong entity relationship between Drug and Pharmacy. Instances of these entity
types can exist on their own..
C. Imagine you are building a restaurant application for XYZ LTD. The application needs to
store data about the company’s employee and it starts by creating the database table below:
EmpID Name Job_Code Job Stae_Code Home_State
Work Required:
i. State whether or not the table is in 1NF. Explain the reason for your choice (2 marks)
Ans:
Yes. All the entries are atomic and there is a composite primary key (EmpID, Job_Code)
so the table is in the first normal form (1NF).
ii. Convert the table into 2NF and 3NF with necessary explanations. (5 marks)
Page 11 of 15
employees Table
EmpID name state_code home_state
E001 Alice 26 Michigan
E002 Bob 56 Wyoming
E003 Alice 56 Wyoming
jobs table
job_code job
J01 Chef
J02 Waiter
J03 Bartender
home_state is now dependent on state_code. So, if you know the state_code, then you can find
the home_state value.
Third Normal Form (3NF)
employee_roles Table
EmpID job_code
E001 J01
E001 J02
E002 J02
E002 J03
E003 J01
employees Table
EmpID name state_code
E001 Alice 26
E002 Bob 56
E003 Alice 56
jobs Table
job_code job
J01 Chef
Page 12 of 15
J02 Waiter
J03 Bartender
states Table
state_code home_state
26 Michigan
56 Wyoming
Now our database is in 3NF.
1) What are the three tags required in ever .html document? (3 marks)
Ans: <html>, <head>, and <body>.
2) Provide the CSS for moving the div "image" away from the div "content" by 20 pixels
THEN, move the text away from the edge of the "content" div by 15 pixels. Place these
rules all within in the "content" tag. (2 marks)
Ans:
#content
{
margin-top: 20px;
}
#content p
{
padding: 15 px;
}
3) Prove the correct way to format a div with the id "text", making it 300px wide and
400px tall with an orange background (2 marks)
Ans:
#text
{
width: 300px;
height: 400px
background-color: orange;
}
4) What does CSS stand for and what are the three different types? (4 marks)
Ans:
§ Cascading Style Sheets
§ Inline (listen to first, ex: <p color="red">HI!</p>
§ Internal (listen to second, ex: <style type="text/css"> p { color: purple; } </style>
§ External (list to third, list the rules in another file, ex: p {color: green;}
5) List the four layers of the box model (from inside to out) (4 marks)
Ans:
§ Content, padding, border, and margin
Page 13 of 15
SECTION D: NETWORKING (15 MARKS)
a. Explain the following:
i. Intranet (2 marks)
ii. Extranet (2 marks)
iii. ARPANET (2 marks)
iv. Network Topology (2 marks)
b. What is IPv6? Explain 2 advantages over IPv4. (6 marks)
c. What is a network protocol? (1 mark)
Ans:
i. Intranet (2 marks)
An intranet is a private network that is used within an organization to share information,
resources, and services among its members. It is accessible only to authorized users, such as
employees, and is typically secured with firewalls and other security measures. Intranets often
use internet technologies like web browsers and servers to facilitate communication and
collaboration.
ii. Extranet (2 marks)
An extranet is an extension of an intranet that allows controlled access to external users, such
as business partners, suppliers, or customers. It enables secure sharing of information and
resources between the organization and its external stakeholders. Like an intranet, it uses
internet technologies but includes additional security measures to protect sensitive data.
iii. ARPANET (2 marks)
ARPANET (Advanced Research Projects Agency Network) was the first wide-area packet-
switching network and the precursor to the modern internet. Developed by the U.S. Department
of Defense, ARPANET was designed to facilitate communication between research institutions
and universities. It laid the foundation for key internet technologies, such as TCP/IP.
iv. Network Topology (2 marks)
Network topology refers to the arrangement or layout of devices (nodes) and connections in a
network. It defines how data flows within the network. Common topologies include:
• Bus Topology: All devices are connected to a single central cable.
• Star Topology: All devices are connected to a central hub or switch.
• Ring Topology: Devices are connected in a circular fashion.
• Mesh Topology: Devices are interconnected, providing multiple paths for data.
The choice of topology affects performance, scalability, and fault tolerance.
Page 14 of 15
b. IPv6 and Its Advantages: (6 marks)
What is IPv6?
IPv6 (Internet Protocol version 6) is the most recent version of the Internet Protocol,
designed to replace IPv4.
It provides a larger address space, improved routing efficiency, and enhanced security
features. IPv6 uses 128-bit addresses, allowing for approximately 3.4 x 10^38 unique
addresses, compared to IPv4's 32-bit addresses.
Advantages of IPv6 over IPv4:
1. Larger Address Space: IPv6 provides a significantly larger address space, eliminating
the problem of IP address exhaustion faced by IPv4. This is crucial for the growing
number of internet-connected devices.
2. Improved Security: IPv6 includes built-in support for IPsec (Internet Protocol
Security), which provides encryption and authentication for secure communication.
While IPsec can be implemented in IPv4, it is mandatory in IPv6.
c. Network Protocol (1 mark)
A network protocol is a set of rules and conventions that govern how data is transmitted
and received over a network. It ensures that devices can communicate effectively by
defining standards for data formatting, error handling, and addressing. Examples include
TCP/IP, HTTP, FTP, and SMTP.
Page 15 of 15