CS310 Assignment 2 Solution and Discussion

Assignment No. 02
Semester: Fall 2019
CS310: Open Source Web Application Development Total Marks: 15
Due Date: December 02, 2019
Topics Covered: Topics of Weeks 1 to 5

Instructions:

Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:

 The assignment is submitted after due date.
 The submitted assignment does not open or file is corrupt.
 Assignment is copied (partial or full) from any source (websites, forums, students, etc)

Note: You have to upload .php file which will have code of PHP. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks.

Objective:

The objectives of this assignment are:

• Understanding the use of if-else statements

Note:

• This assignment is a Graded Assignment.
• The assignment submitted through email will not be accepted.
• This assignment is covering all topics of weeks 1 to 5.

Guidelines:

 Code should be properly indented.
 You can use the following tools/software:
o Adobe Dreamweaver, Notepad
o XAMP, WAMP, Vertrigo Server

For any query about the assignment, contact at [email protected].

Assignment Statement:

Suppose, you joined NGCP (Natural Gas Company Pakistan) as a developer. The first task is given to you is create a web-based application in PHP to generate the bill of customer.

User of your application will give customer id as customer_id and number of units as units through URL. Your application will read customer id and units from URL and generate the bill according to table given below.

Number of Units Rate per Unit
First 50 units 0.50/unit
Next 100 units 0.75/unit
Next 100 units 1.00/unit
units above 250 1.50/unit
Additional taxes on Cost of Gas is 18%.
Late payment surcharge 5% payable bill.

The code to reach customer_id and units from URL is already given PHP file attached with assignment. You need work on provided file and complete and missing requirements.

Sample Web Page:

79e578d4-c79f-4e20-90ee-1237013913e6-image.png

Submission Instructions:

You have to submit single PHP file which will have all the code provided by us and PHP code you will write.

BEST OF LUCK!

Idea Solution

<?php

if(!isset($_GET['customer_id']) || !isset($_GET['units'])){
$customer_id = 0;
$units = 0;
}
else{
	$customer_id = $_GET['customer_id'];
$units = $_GET['units'];
}
$amount = 0;

if($units > 0 && $units <= 50)
    {
        $amount = $units * 0.50;
    }
    else if($units <= 150)
    {
        $amount = 50 * 0.5 + (($units - 50) * 0.75);
    }
    else if($units <= 250)
    {
        $amount = 50 * 0.5 + 100 * 0.75 + (($units - 150) * 1.00);
    }
    else
    {
        $amount = 50 * 0.5 + 100 * 0.75 + 100 * 1.0 + (($units - 250) * 1.50);
    }


$tax = $amount * 0.18;
$payable = $amount + $tax;
$lp_surcharge = $payable * 0.05;

$late_payable = $payable + $lp_surcharge;
?>

<html>
<head>
<title>Assignment No. 2 (Solution) - Fall 2019</title>
</head>

<body bgcolor="#CCCCCC">
<table width="1800" border="0" align="center" cellpadding="20" cellspacing="0">
  <tr>
    <td height="200" colspan="2" align="center" valign="middle" bgcolor="#CC6633"><h1>Natural Gas Company Pakistan</h1></td>
  </tr>
  <tr>
  <td width="300"  align="center" valign="top" bgcolor="#FF9966"><table width="100%" border="0" cellspacing="0" cellpadding="20">
  <tr>
    <td align="right"><strong>Customer ID</strong></td>
  </tr>
  <tr>
    <td align="right"><strong>Units Consumed</strong></td>
  </tr>
  <tr>
    <td align="right"><strong>Cost of Gas</strong></td>
  </tr>
  <tr>
    <td align="right"><p><strong>Taxes (18%)</strong></p></td>
  </tr>
  <tr>
    <td align="right"><strong>Payable within Due Date</strong></td>
  </tr>
  <tr>
    <td align="right"><strong>Late Payment Surcharge (5%)</strong></td>
  </tr>
  <tr>
    <td align="right"><strong>Payable after Due Date</strong></td>
  </tr>
  </table>
</td>
  <td height="500" align="left" valign="top" bgcolor="#FFDECE"><table width="100%" border="0" cellspacing="0" cellpadding="20">
    <tr>
      <td><strong><?php echo $customer_id; ?></strong>
      </td>
    </tr>
    <tr>
      <td><?php echo $units; ?></td>
    </tr>
    <tr>
      <td><?php echo $amount; ?></td>
    </tr>
    <tr>
      <td><?php echo intval($tax*100) / 100; ?></td>
    </tr>
    <tr>
      <td><?php echo intval($payable * 100) / 100; ?></td>
    </tr>
    <tr>
      <td><strong><?php echo intval($lp_surcharge * 100) / 100; ?></strong></td>
    </tr>
    <tr>
      <td><strong><?php echo intval($late_payable * 100) / 100; ?></strong></td>
    </tr>
  </table></td>
  </tr>
  
  <tr>
    <td height="140" colspan="2" align="center" valign="middle" bgcolor="#CC6633"><h4>Copy Rights: NGCP</h4></td>
  </tr>
</table>
</body>
</html>

Ideas 2

<?php

if (isset($_POST[‘submit’])) {

$salary = $_POST[‘salary’];

if ($salary>50000) {

$insurance = (20/100)*$salary;

echo “Your salary is “.$salary . ” And Calculated insurance is “. $insurance;

}elseif($salary>40000){

$insurance = (15/100)*$salary;

echo “Your salary is “.$salary . ” And Calculated insurance is “. $insurance;

}elseif($salary>30000){

$insurance = (10/100)*$salary;

echo “Your salary is “.$salary . ” And Calculated insurance is “. $insurance;