0% found this document useful (0 votes)
5 views15 pages

Case Study - Set B MG 2

The document outlines a case study for a Software Engineering course, detailing various programming tasks including algorithm design, pseudocode writing, object-oriented programming concepts, and database development. It includes specific questions and answers related to algorithms, pseudocode, SQL queries, and normalization of database tables. Additionally, it covers web design fundamentals, including essential HTML tags and CSS styling instructions.

Uploaded by

crllandry20005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views15 pages

Case Study - Set B MG 2

The document outlines a case study for a Software Engineering course, detailing various programming tasks including algorithm design, pseudocode writing, object-oriented programming concepts, and database development. It includes specific questions and answers related to algorithms, pseudocode, SQL queries, and normalization of database tables. Additionally, it covers web design fundamentals, including essential HTML tags and CSS styling instructions.

Uploaded by

crllandry20005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Speciality/Option: Software Engineering (SWE)

Paper: Case Study Credit: 14


Duration: 6 Hours
Answer All Questions
SECTION A: ALGORITHM AND PROGRAMMING (50 MARKS)
Question 1: Algorithms (10 Marks)
You are asked to write a program that guesses the number of goals a team will score in a football
match.
The Algorithm for the program is shown below

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.

Question 2: Pseudocode (25 Marks)


A Maths teacher wants to estimate how long it should take her students to complete a worksheet.
You are required to develop an algorithm to calculate this estimate. The algorithm must do the
following:
o Ask the teacher how many questions the worksheet contains and store this in an
appropriately named variable
o For every question in the worksheet, the algorithm should:
§ Ask the teacher if the question looks ‘easy’ or ‘difficult’
§ If the question is ‘difficult’ then the total number of seconds should increase by 2
§ If the question is ‘easy’ then the total number of seconds should increase by 1
o After the teacher has entered a difficulty level for all the questions, the algorithm should
output the estimated number of seconds that it should take to complete the worksheet.

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

FOR i FROM 1 TO num_questions DO


PRINT "Is question " i " easy or difficult? (easy/difficult)"
INPUT difficulty

IF difficulty == "difficult" THEN


SET total_time = total_time + 2
ELSE
SET total_time = total_time + 1
ENDIF
ENDFOR

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

// Step 2: Ask for the number of questions


PRINT "Enter the number of questions:"
INPUT numQuestions

// Step 3: Loop through each question


FOR i = 1 TO numQuestions
PRINT "Is question " + i + " easy or difficult? (Enter 'easy' or 'difficult'):"
INPUT difficulty

// Step 4: Update total time based on difficulty


IF difficulty == "difficult" THEN
totalSeconds = totalSeconds + 2
ELSE IF difficulty == "easy" THEN
totalSeconds = totalSeconds + 1
END IF
END FOR

// Step 5: Output the total estimated time


PRINT "Estimated time to complete the worksheet: " + totalSeconds + " seconds"
END

b. Draw a flowchart represents for the algorithm (8 marks)

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);

// Step 3: Loop through each question


for (int i = 1; i <= numQuestions; i++) {
// Step 4: Ask for the difficulty of the question
printf("Is question %d easy or difficult? (Enter 'easy' or 'difficult'): ",
i);
scanf("%s", difficulty);

// Step 5: Update total time based on difficulty


if (strcmp(difficulty, "difficult") == 0) {
totalSeconds += 2;
} else if (strcmp(difficulty, "easy") == 0) {
totalSeconds += 1;
} else {
printf("Invalid input. Please enter 'easy' or 'difficult'.\n");
i--; // Repeat the current question
}
}

// Step 6: Output the total estimated time


printf("Estimated time to complete the worksheet: %d seconds\n", totalSeconds);

return 0;
}

Question 3: Object Oriented Programming (15 Marks)


a. Define the following terms as used in OOP
i. Data Abstraction (1 marks)
ii. Encapsulation (2 marks)
iii. Polymorphism (2 marks)
iv. Inheritance (2 marks)
v. Class (1 marks)

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.

b. Define a class named ‘Train’ representing the following members:


Data Members

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)

Ans: C++ Code


#include <iostream>
#include <string>
using namespace std;

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) {}

// Function to input train data


void inputTrainData() {
cout << "Enter Train Number: ";
cin >> trainNumber;
cin.ignore(); // Ignore newline character after number input
cout << "Enter Train Name: ";
getline(cin, trainName);
cout << "Enter Source: ";
getline(cin, source);
cout << "Enter Destination: ";

Page 6 of 15
getline(cin, destination);
cout << "Enter Journey Date (YYYY-MM-DD): ";
getline(cin, journeyDate);
cout << "Enter Capacity: ";
cin >> capacity;
}

// Function to display train data


void displayTrainData() const {
cout << "\nTrain Details:\n";
cout << "Train Number: " << trainNumber << endl;
cout << "Train Name: " << trainName << endl;
cout << "Source: " << source << endl;
cout << "Destination: " << destination << endl;
cout << "Journey Date: " << journeyDate << endl;
cout << "Capacity: " << capacity << endl;
}
};

int main() {
Train t;
t.inputTrainData();
t.displayTrainData();
return 0;
}

SECTION B: DATABASE DEVELOPMENT AND ADMINISTRATION (20 MARKS)


You are designing a database for KW Humane Society. The result is the following
set of relations where the type of each relations attribute is given following the
attribute (e.g., ID: integer):

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)

SELECT Name, Address


FROM Adopter , Adoption
WHERE Adopter . SIN = Adoption . SIN
GROUP BY Adoption . SIN
HAVING COUNT( SIN ) > =2 ;

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.

Fig 1.Figure for question B


i. Can a pharmaceutical company have multiple phone numbers? If not, what do you need to do
to allow this? (1 marks)
Ans:
Yes, the pharmaceutical company can have multiple phone numbers. This is because the Phone
attribute is defined as a multivalued one.
ii. If we delete from the database the pharmaceutical company that manufactures a drug, what
happens to the drugs that the company manufactures? Justify (in one or two sentences only)
your argument. (1 marks)

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

E001 Alice J01 Chef 26 Buea

E001 Alice J02 Waiter 26 Buea

E002 Bob J02 Waiter 56 Limbe

E002 Bob J03 Bartender 56 Limbe

E003 Alice J01 Chef 56 Limbe

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)

Second Normal Form (2NF): A table in 2NF


• it’s already in 1NF
• has no partial dependency. That is, all non-key attributes are fully dependent on a
primary key.
employee_roles Table
EmpID job_code
E001 J01
E001 J02
E002 J02
E002 J03
E003 J01

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.

SECTION C: WEB DESIGN (15 MARKS)

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy