P h i l

advertisement
Philadelphia University
Faculty of Information Technology
Department of Software Engineering
Examination Key
Lecturer: Dr. Samer Hanna
Internal Examiner: Dr. Saed Goul
Coordinator: Dr. Samer Hanna
Special Topics in Software Engineering
(0721439 ) Section 1
Final Exam’s Key
Summer Session of 2014/2015
Date: Wednesday, August 31 , 2015-------- Time: 50 min.
st
Q1) (6 marks)
1. Write the advantages and disadvantages of building Web applications using ASP.NET vs. using PHP (2 marks)
PHP
Advantages
Open source
Can be run on all platforms
Disadvantages
Takes more time to build an application
ASP.NET
Advantages
ASP.NET takes less time to build an application because of the drag and drop controls and other ready code.
Disadvantages
Paid
Can run only on Microsoft based platforms
2. Write two of the differences between the three technologies: JavaScript, PHP and ASP.NET regarding user input
validation. (2 marks)
JavaScript
Client-side input validation
Use
document.getElementById
method to retrieve an input
ASP.NET
PHP
Server-side input validation
Server-side input validation
Use $_Post[“input name”] array to Use Text1.Text property to retrieve
retrieve an input
an input
3. Compare between the datatypes used by HTML vs. the datatypes used by XML Schema Definition (XSD). Also,
what are the datatypes that are supported by HTML not supported by XSD, and the datatypes that are supported by
XSD not supported by HTML? (2 marks)
HTML uses the datatypes: number, text, email, password, date, etc.
XSD use the datatypes: decimal, integer, nonPositiveInteger, etc.
Email, password that are supported by HTML are not supported by XSD
integer, nonPositiveInteger are supported by XSD are not supported by HTML
Q2) (6 marks)
1
Suppose that Philadelphia asked you to build a Web form to insert the information of the books at the University
library. The design of the required web page is in the following figure:
1. Write the needed HTML to build this Web form [note that the form has a right column that contains links to three of
the Jordanian Universities libraries]. (4 marks)
2. Write the needed CSS to build this page (2 marks)
Sol.
1.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Books</title>
</head>
<body>
<form id="form1" runat="server">
<div id="wrap">
<header class="auto-style1">
<strong>Books at Philadelphia Library
</strong>
</header>
<div id="content">
<br />
Book title:
<input type="text" id="booktitle" />
<br />
<br />
First Author Name:
<input type="text" id="firstName" />
<br />
<br />
Number of authors:
<input type="number" id="authors" />
<br />
<br />
Publication date:
<input type="date" id="publish" />
<br />
<br />
<input type="submit" id="submit" value ="Okay" />
</div>
<aside>
<a href="#" >Jordan University Library</a>
<br />
<br />
<a href="#" >JUST University Library </a>
2
<br />
<br />
<a href="#" >Yarmouk University Library </a>
</aside>
</div>
</form></body>
</html>
2.
<style type="text/css">
#wrap
{
width: 615px;
margin: auto;
background-color: lightblue;
}
#content
{
width: 400px;
float: left;
}
aside
{
width: 200px;
float: right;
background-color: aqua;
height: 350px;
}
.auto-style1
{
text-align: center;
}
#submit
{
font-weight: 700;
text-align: center;
}
#content
{
margin-left: 14px;
}
</style>
Q3) (6 marks)
Add the needed JavaScript functions to the Web form in Question 2 in order to:
1. Making sure that the inserted number of authors is between 1 and 10. A proper error message must be printed
otherwise. (2 marks)
2. Making sure that the publication date of the book is before the current date of the system. A proper error message
must be printed otherwise. (2 marks)
3. Changing the background color of the right column that contains universities links. (2 marks)
Sol.
1.
function checkAuthors() {
var a = document.getElementById("authors").value;
if (a < 1 || a > 10)
{
alert("<b>invalid users</b>");
}
}
2.
function checkDate() {
3
var publish = document.getElementById("publish").value;
var publishDate = Date.parse(publish);
var today = new Date();
if (publishDate > today)
{ alert("ivalid date");}
}
3.
function changeColor() {
var elem = document.getElementById("a");
elem.style.backgroundColor = "red";
alert ("color changed");
}
Q4) (6 marks)
Write the needed PHP code to accomplish the following:
1. Declaring a class of type Book depending on the inputs of the forms in Q2 [note. The class must have a
constructor]. (2 marks)
2. Declaring an object of type Book and the filling the form’s inputs in Question 2 with the objects data when the user
clicks the okay button. (2 marks)
3. Making sure that the inserted number of authors is between 1 and 10. A proper error message must be printed
otherwise. (2 marks)
Sol.
1.
class Book
{
public $title;
public $authorName;
public $copies;
public $publishDate;
function __construct($title, $authorName, $copies, $publishDate) {
$this->title = $title;
$this->authorName = $authorName;
$this->copies = $copies;
$this->publishDate = $publishDate;
}
}
2.
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#wrap
{
width: 615px;
margin: auto;
background-color: lightblue;
}
#content
{
width: 400px;
float: left;
4
}
aside
{
width: 200px;
float: right;
background-color: aqua;
height: 300px;
}
.auto-style1
{
text-align: center;
}
#submit
{
font-weight: 700;
text-align: center;
}
#content
{
margin-left: 14px;
}
</style>
</head>
<body>
<?php
if(isset($_POST['submit'])) {
$date = new DateTime();
$date->setDate(2010, 2, 3);
$obj = new Book("Software Engineering", "Summervile", 4, $date);
}
?>
<form method="post" action= "<?=$_SERVER['PHP_SELF'];?>" >
<div id="wrap">
<header class="auto-style1">
<strong>Books at Philadelphia Library
</strong>
</header>
<div id="content">
<br />
Book title:
<input type="text" id="booktitle" value='<?php if (isset($_POST['submit'])){ echo $obj->title;}; ?>'/>
<br />
<br />
First Author Name:
<input type="text" id="firstName" value='<?php if (isset($_POST['submit'])){ echo $obj->authorName;};
?>' />
<br />
<br />
Number of authors:
<input type="number" id="authors" value='<?php if (isset($_POST['submit'])){ echo $obj->authors;}; ?>'/>
<br />
<br />
Publication date:
<input type="date" id="publish" value='<?php if (isset($_POST['submit'])){ echo $obj->publishDate>format('d-m-Y');}; ?>'/>
5
<br />
<br />
<input type="submit" id="submit" name="submit" value ="Okay" />
</div>
<aside>
<a href="#" >Jordan University Library</a>
<br />
<br />
<a href="#" >JUST University Library </a>
<br />
<br />
<a href="#" >Yarmouk University Library </a>
</aside>
</div>
</form>
<?php
class Book
{
public $title;
public $authorName;
public $authors;
public $publishDate;
function __construct($title, $authorName, $authors, $publishDate) {
$this->title = $title;
$this->authorName = $authorName;
$this->authors = $authors;
$this->publishDate = $publishDate;
}
}
?>
</body>
</html>
3.
public function validateAuthors()
{
if ($this->authors<1 || $this->authors>10)
{
echo "invalid number of authors";
}
}
Q5) (4 marks)
1. Write an XML document corresponding to the data of three books inserted using the form in Question 2. (2 marks)
2. Write the XSD file corresponding to the XML document in 1. (2 marks)
Sol.
1.
<?xml version="1.0" encoding="utf-8" ?>
6
<books>
<book>
<title>Software Engineering</title>
<author>Summervile</author>
<numAuthors>5</numAuthors>
<publish>2012-08-01</publish>
</book>
<book>
<title>PHP</title>
<author>Samer</author>
<numAuthors>3</numAuthors>
<publish>2015-08-01</publish>
</book>
</books>
2.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="book">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="author" type="xs:string" />
<xs:element name="numAuthors" type="xs:unsignedByte" />
<xs:element name="publish" type="xs:date" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Q6) (6 marks)
Suppose that we want to build the application in Q2 using ASP.NET MVC;
1. Write the code of the controller that is responsible to create Book object and send it to the view (2 marks)
2. Write the code of the model. (1 mark)
3. Write the code of the view that is responsible to generate the same form such as that in Q2. [The view should be
displayed whenever the user visits the control URL. (3 marks)
Sol.
Controller
namespace MvcLibrary.Controllers
{
public class LibraryController : Controller
{
public ActionResult GetBook()
{
Book book = new Book()
{
Title = "Software Engineering",
Author = "Summervile",
NumAuthors = 5,
PublishDate = new DateTime(2014, 10, 01)
};
return View(book);
}
7
}
}
Model
namespace MvcLibrary.Models
{
public class Book
{
public string Title { get; set; }
public string Author { get; set; }
public int NumAuthors { get; set; }
public DateTime PublishDate { get; set; }
}
}
View
@model MvcLibrary.Models.Book
@{
ViewBag.Title = "Books at Philadelphia Library";
}
<html>
<head>
<title></title>
<style type="text/css">
#wrap
{
width: 615px;
margin: auto;
background-color: lightblue;
}
#content
{
width: 400px;
float: left;
}
aside
{
width: 200px;
float: right;
background-color: aqua;
height: 250px;
}
.auto-style1
{
text-align: center;
}
#submit
{
font-weight: 700;
text-align: center;
}
#content
{
margin-left: 14px;
}
</style>
</head>
<body>
<div id="wrap">
<header class="auto-style1">
<strong>Books at Philadelphia Library
</strong>
</header>
8
<div id="content">
<br />
Book title:
<input type="text" id="booktitle" value="@Model.Title" />
<br />
<br />
First Author Name:
<input type="text" id="firstName" value="@Model.Author" />
<br />
<br />
Number of authors:
<input type="number" id="authors" value="@Model.NumAuthors"/>
<br />
<br />
Publication date:
<input type="date" id="publish" value="@Model.PublishDate.ToShortDateString()" />
<br />
<br />
<input type="submit" id="submit" value ="Okay" onclick="changeColor()" />
</div>
<aside id="a">
<a href="#" >Jordan University Library</a>
<br />
<br />
<a href="#" >JUST University Library </a>
<br />
<br />
<a href="#" >Yarmouk University Library </a>
</aside>
</div>
</body>
</html>
Q7) (4 marks)
For the same form in Q2, write the needed ASP.NET based code to:
1. Make sure that the number of authors is between 1 and 10. Print proper error message to the user otherwise. (2
marks)
2. Make sure that the publish year of the book is equal or after 2010; otherwise a message indicating that the book is
old should be printed. (2 marks)
Sol.
1.
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="RangeValidator"
ControlToValidate="authors" MinimumValue="1" MaximumValue="10" Type="Integer"></asp:RangeValidator>
2.
<input type="button" id="button1" value ="Okay" runat="server" onserverclick="Button1_Click"/>
protected void Button1_Click(object sender, EventArgs e)
{
string n = String.Format("{0}", Request.Form["publish"]);
int year = DateTime.Parse(Request.Form["publish"]).Year;
Label1.Text = year.ToString();
if (year < 2010)
Label1.Text = "Old book published in " + year;
}
9
Download