Coding Examples

Table of Contents:

HTML

<!DOCTYPE html>

<html>

<head>

</head>

<body>

  <h3>Prove n<sup>3</sup>+4n<sup>2</sup>logn+16n= &theta; (n<sup>3</sup>)</h3>

  <p>

  n<sup>3</sup>+4n<sup>2</sup>logn+16n &geq; n<sup>3</sup> &forall; n &geq; 1<br>

  n<sup>3</sup>+4n<sup>2</sup>logn+16n = &Omega; (n<sup>3</sup>)<br>

  <br>

  n<sup>3</sup>+4n<sup>2</sup>logn+16n &leq; C<sub>0</sub>5n<sup>3</sup><br>

  C<sub>0</sub> = 5, n<sub>0</sub> = 3<br>

  n<sup>3</sup>+4n<sup>2</sup>logn+16n &leq; 5n<sup>3</sup> &forall; n &geq; 3<br>

  n<sup>2</sup>logn+16n &leq; n<sup>3</sup> &forall; n &geq; 3<br>

  n<sup>3</sup>+4n<sup>2</sup>logn+16n = O(n<sup>3</sup><br>

  <br>

  n<sup>3</sup>+4n<sup>2</sup>logn+16n = &theta; (n<sup>3</sup>)<br>

  </p>

</body>

</html>

<!DOCTYPE html>

<html>

<head>

</head>

<body>

  <h3>Prove if f(n) = O(g(n)) and g(n) = O(h(n)) then f(n) = O)h)n))</h3>

  <p>

  By definition:<br>

  f(n) = O(g(n)) &exist; c<sub>1</sub> & n<sub>1</sub> &ni;

  f(n) &leq; c<sub>1</sub> * g(n) &forall; n &geq; n<sub>1</sub><br>

  and<br>

  g(n) = O(h(n)) &exist; c<sub>2</sub> & n<sub>2</sub> &ni;

  g(n) &leq; c<sub>2</sub> * h(n) &forall; n &geq; n<sub>2</sub><br>

  <br>

  f(n) &leq; c<sub>1</sub> * g(n)<br>

  &emsp; &nbsp; &leq; c<sub>1</sub> * c<sub>2</sub> * h(n)<br>

  &forall; n &geq; max{n<sub>1</sub>,n<sub>2</sub>}<br>

  &therefore; f(n) = O(h(n))<br>

  </p>

</body>

</html>

After coding all of this I learned you could replace "<sup>1</sup>" with "&sup1;", which would have made my code shorter and easier to read.

LaTeX

\documentclass[11]{article}

\usepackage{gensymb}

\usepackage{amsmath}

\usepackage{multicol}

\usepackage{graphicx}

\addtolength{\oddsidemargin}{-.875in}

\addtolength{\evensidemargin}{-.875in}

\addtolength{\textwidth}{1.75in}

\addtolength{\topmargin}{-.875in}

\addtolength{\textheight}{1.75in}


\begin{document}

\begin{center}

PHYSICS 324: METHODS OF THEORETICAL PHYSICS \\

\textit{A. Sindorf} \\

Homework 6\\

\end{center}

Determine the Fourier series of the following functions.\\

\textbf{Problem 1}\\

$f(x) = \vert sinx \vert $\\

\begin{center}

$f(x)= \vert sinx \vert$ is even and pi periodic, thus has a Fourier series in the form

$$f(x) = \frac{a_0}{2}+\sum_{n=1}^\infty a_n cos(2nx)$$

$$a_n = \frac{2}{pi}\int_0^\pi f(x) cos(2nx)dx$$

plugging in $sinx$ for our function

$$a_n = \frac{2}{\pi}\int_0^\pi sinx cos(2kx)dx$$

$$a_n = \frac{1}{\pi}\int_0^\pi(sin((1+2n)x)+sin((1-2n))dx$$

$$a_n = \frac{1}{\pi}\left( \frac{cos((2n-1)x)}{2n-1}-\frac{cos((2n+1)x)}{2n+1}\right)\Big|_0^\pi$$

$$a_n = \frac{2}{\pi}\left( \frac{1}{2n+1}- \frac{1}{2n-1}\right)$$

$$a_n = -\frac{4}{\pi (4n^2-1)}$$

$$a_0 = $$

\end{center}



\end{document}


\documentclass[11]{article}

\usepackage{gensymb}

\usepackage{amsmath}

\usepackage{multicol}

\usepackage{graphicx}

\addtolength{\oddsidemargin}{-.875in}

\addtolength{\evensidemargin}{-.875in}

\addtolength{\textwidth}{1.75in}

\addtolength{\topmargin}{-.875in}

\addtolength{\textheight}{1.75in}


\begin{document}

\begin{center}

PHYSICS 324: METHODS OF THEORETICAL PHYSICS \\

\textit{A. Sindorf} \\

Homework 2\\

\end{center}

\textbf{Problem 1}\\

What region is described by the inequality?

$$1<\vert z+1-i\vert<2?$$

Solving, substituting $x+iy$ for $z$

$$1<\vert x+1+y-1\vert<2$$

$$1<\vert (x+1)+(y-i)\vert<2$$

$$1<\sqrt{(x+1)^2+(y-1)^2}<2$$

$$1<(x+1)^2+(y-1)^2<4$$

This results in 2 circles centered at (-1,1) with radii 1,2. The area between them is the region described by the inequality.

\begin{center}

\includegraphics[scale=.2]{graphcircle.png}

\end{center}

\textbf{Problem 3}\\

Prove that if $\vert z \vert < 1$ and $\omega = i(1-z)/(1+z), z \neq -1$, then $Im(\omega)>0$

$$\omega=i\frac{1-x-iy}{1+x+iy}$$

$$\omega=i\frac{((1-x)-iy)((1+x)-iy)}{((1+x)+iy)((1+x)-iy)}$$

$$\omega=i\frac{(1-x)(1+x)-iy+xiy-iy-xiy-(iy)^2}{(1+x)(1+x)-iy-xiy+iy+xiy+(-iy)^2}$$

$$\omega=i\frac{1-x^2-2iy-y^2}{x^2+2x+1+y^2}$$

$$\omega=\frac{i-ix^2+2y-iy^2}{x^2+2x+1+y^2}$$

$$\omega=\frac{i-ix^2-iy^2}{x^2+2x+1+y^2}+\frac{2y}{x^2+2x+1+y^2}$$

$$Im(\omega)=\frac{1-x^2-y^2}{x^2+2x+1+y^2}$$

$$Im(\omega)=\frac{-(x^2+y^2-1)}{x^2+2x+1+y^2}$$

$$Im(\omega)=\frac{-(z\bar{z}-1)}{x^2+2x+1+y^2}$$

Since $z\bar{z}$ will always create a nonnegative number and $\vert z \vert<1$, $-(z\bar{z}-1)$ will always result in a negative number multiplied by $-1$. Thus $Im(\omega)$ will always be positive.\\

\textbf{Problem 5}\\

(a) Evaluate $\vert e^{-3iz+5i}\vert$, where $z=x+iy$.\\

(b) Solve the Equation

$$e^z=2+2i, \forall z.$$

Solving (a)

$$\vert e^{-3i(x+iy)+5i}\vert$$

$$\vert e^{-3ix+3y+5i}$$

$$\vert e^{3y}\vert\vert e^{-3ix+5i}\vert$$

$$\vert e^{3y}\vert$$

$$e^{3y}$$

Solving (b)

$$e^z=2+2i$$

$$e^{x+iy}=2(1+i)$$

$$e^xe^{iy}=2\sqrt{2}\left(\frac{1}{\sqrt{2}}+\frac{i}{\sqrt{2}}\right)$$

$$e^xe^{iy}=2\sqrt{2}(sin\frac{\pi}{4}+icos\frac{\pi}{4})$$

$$e^xe^{iy}=\sqrt{8}e^{i\pi/4}$$

\begin{multicols}{2}

$$e^x=\sqrt{8}$$

$$lne^x=ln\sqrt{8}$$

$$x=.5ln8$$

\columnbreak\\

$$e^y=e^{\pi/4}$$

$$lne^y=lne^{\pi/4}$$

$$y=\pi/4$$

\end{multicols}

\end{document}



PHP/HTML

This project was to write create an HTML file that submits data to a single php file.  The php file would generate a table of classes based on the input from the HTML file.

I have embedded the HTML code here, but pressing submit will cause an error as I cannot host php scripts on this site.  Nonetheless you can still play around with the drop down menus and reset buttons.  Please see the video on the right for a demonstration of the working script, as hosted locally on an apache2 server.  The associated php file text has been posted below the embedded HTML, with the data to the right of it.

The project required the use of a Switch Case statement in the PHP file.  My implementation passed a single integer variable to the statement, which would then call the display function and pass the info.  The display function took the two passed variables, generated the appropriate data, and displayed it for the user.

<?php

$input = $_POST['input'];

echo "<br>";

echo '<a href="final.html">Back</a>';

echo "<br>";


function printAll($input,$subject) {


echo "<head>

<style type='text/css'>

    

    table { 

        border: 1px solid black; 

        border-collapse: collapse; 

        background: #fff; 

    }

    

    th, td { 

        border: 1px solid black; 

        padding: .2em .7em;   

        color: #000;

        font-size: 16px; 

        font-weight: 400; 

    } 

    

    thead th { 

        background-color: #1A466A; 

        color: #fff; 

        font-weight: bold;  

    }

    .link {

            padding: 10px 20px;

    }

</style>

</head>";


?>

<!doctype html>

<html>

<head>

<style type="text/css">

    

    table { 

        border: 1px solid black; 

        border-collapse: collapse; 

        background: #fff; 

    }

    

    th, td { 

        border: 1px solid black; 

        padding: .2em .7em;   

        color: #000;

        font-size: 16px; 

        font-weight: 400; 

    } 

    

    thead th { 

        background-color: #1A466A; 

        color: #fff; 

        font-weight: bold;  

    }

    .link {

            padding: 10px 20px;

    }

</style>

</head>

<body>

    <table>

    <thead>

        <tr>

        <?php

$columnLabels = ["ID", "Course", "Instructor", "Section", "Days", "Time", "Location"]; 

            foreach($columnLabels as $label) {

                echo "<th>{$label}</th>";

            }

        ?>

        <tr>

    </thead>

    <tbody>

<?php


    $fp = fopen("uww_schedule.csv", "r");


    if (!$fp) {

        return false;

    }

    $list = [];

    

    if ($input == '0') {

$list = getAll($fp);

}

elseif (($input > '0') && ($input < '4')) {

$list = getBySubject($fp, $subject);

}

elseif (($input > '3') && ($input < '6')) {

$list = getByDay($fp, $subject);

}

elseif (($input > '5') && ($input < '8')) {

$list = getByLoc($fp, $subject);

}

   foreach($list as $class) {

        echo "<tr>";

echo "<td>{$class[0]}";

        echo "<td>{$class[1]} {$class[2]}</td>";

        echo "<td>{$class[3]}</td>";

echo "<td>{$class[4]}</td>";

        echo "<td>{$class[5]}</td>";

        echo "<td>{$class[6]}</td>";

        echo "<td>{$class[7]}</td>";

        echo "</tr>";

   }

echo "</tbody></table>";

echo "</body></html>";

fclose($fp);

}

function getBySubject($fp, $subject) {

echo "<h3>$subject</h3>";


    $list = [];

    

    while ($class = fgetcsv($fp, 255, ',')) {

        if (trim($class[1]) == $subject) {

            $list[] = $class;

        }

    }

return $list;

}

function getByDay($fp, $Day) {

echo "<h3>$Day Sections</h3>";


    $list = [];

    

    while ($class = fgetcsv($fp, 255, ',')) {

        if (trim($class[5]) == $Day) {

            $list[] = $class;

        }

    }

return $list;

}

function getByLoc($fp, $Loc) {

echo "<h3>$Loc Sections</h3>";


    $list = [];

    

    while ($class = fgetcsv($fp, 255, ',')) {

        if (trim($class[7]) == $Loc) {

            $list[] = $class;

        }

    }

return $list;

}

function getAll($fp) {

    while ($class = fgetcsv($fp, 255, ',')) {

        $list[] = $class;

}

return $list;

}

if ($input < "0"){

    echo "Please select an option";

}

else {

    switch ($input) {

    case 0:

echo "<h3>All Subjects</h3>";

        printAll($input,"NULL");

        break;

    case 1:

        printAll($input,"COMPSCI");

        break;

    case 2:

        printAll($input,"MATH");

        break;

    case 3:

        printAll($input,"MAGD");

        break;

    case 4:

        printAll($input,"MW");

        break;

case 5:

        printAll($input,"TuTh");

break;

case 6:

        printAll($input,"McGraw 0115");

break;

case 7:

        printAll($input,"McGraw 0117");

break;

}

echo "<br>";

echo "<br>";

echo '<a href="final.html">Back</a>';


    

}

?>

460, COMPSCI, 162, 1, W 12:30 PM - 1:45 PM, Jiehui Ma, MG0115

461, COMPSCI, 162, 2, W 2:00 PM - 3:15 PM, Jiehui Ma, HY0210

462, COMPSCI, 162, 3, Web Based, Tina Cao, ONLINE 

463, COMPSCI, 170, 1, M 9:30 AM - 10:45 AM, Jiehui Ma, MG0125

464, COMPSCI, 170, 2, Tu 3:30 PM - 4:45 PM, Jiehui Ma, MG0115

465, COMPSCI, 172, 1, MW 11:00 AM - 12:15 PM, To Be Arranged, MG0125

466, COMPSCI, 172, 2, TuTh 9:30 AM - 10:45 AM, To Be Arranged, MG0115

468, COMPSCI, 174, 2, TuTh 12:30 PM - 1:45 PM, Tina Cao, MG0115

467, COMPSCI, 174, 1, MW 3:30 PM - 4:45 PM, Tina Cao, MG0115

469, COMPSCI, 180, 1, M 11:00 AM - 12:15 PM, Jiehui Ma, MG0115

470, COMPSCI, 215, 1, Tu 3:30 PM - 4:45 PM, Lopamudra Mukherjee, HY0210

471, COMPSCI, 220, 1, TuTh 11:00 AM - 12:15 PM, To Be Arranged, HY0210

472, COMPSCI, 222, 1, TuTh 2:00 PM - 3:15 PM, To Be Arranged, HY0210

474, COMPSCI, 223, 2, W 11:00 AM - 12:15 PM, Arnab Ganguly, MG0115

473, COMPSCI, 223, 1, Tu 2:00 PM - 3:15 PM, Arnab Ganguly, MG0115

475, COMPSCI, 271, 1, M 2:00 PM - 3:30 PM, Athula Gunawardena, HY0210

476, COMPSCI, 271, 2, Tu 11:00 AM - 12:15 PM, Athula Gunawardena, MG0115

477, COMPSCI, 296, 1, TuTh 5:00 PM - 6:15 PM, Zachary Oster, MG0125

478, COMPSCI, 310, 1, Web Based, Robert Kuzoff, ONLINE 

479, COMPSCI, 320, 1, MW 9:30 AM - 10:45 AM, Zachary Oster, MG0115

480, COMPSCI, 332, 1, Tu 12:30 PM - 1:45 PM, Lopamudra Mukherjee, HY0210

481, COMPSCI, 353, 1, TuTh 11:00 AM - 12:15 PM, To Be Arranged, MG0125

482, COMPSCI, 381, 1, TuTh 9:30 AM - 10:45 AM, Tina Cao, HY0210

483, COMPSCI, 382, 1, MW 3:30 PM - 4:45 PM, To Be Arranged, MG0125

484, COMPSCI, 382, 2, TuTh 12:30 PM - 1:45 PM, To Be Arranged, MG0125

485, COMPSCI, 412, 1, MW 11:00 AM - 12:15 PM, Haijian Sun, HY0210

486, COMPSCI, 433, 1, MW 2:00 PM - 3:15 PM, Arnab Ganguly, MG0115

487, COMPSCI, 455, 1, TuTh 5:00 PM - 6:15 PM, To Be Arranged, HY0210

488, COMPSCI, 460, 1, MW 5:00 PM - 6:15 PM, To Be Arranged, HY0210

489, COMPSCI, 476, 1, MW 3:30 PM - 4:45 PM, Zachary Oster, HY0210

490, COMPSCI, 481, 1, TuTh 3:30 PM - 4:45 PM, Sobitha Samaranayake, MG0125

491, COMPSCI, 493, 1, Web Based, Zachary Oster, INDSTY

492, COMPSCI, 498, 1, Web Based, Zachary Oster, INDSTY

493, COMPSCI, 498R, 1, Web Based, To Be Arranged, INDSTY

1207, MATH, 124, 4, Tu 1:00 PM - 1:50 PM, To Be Arranged, HE0117

1206, MATH, 124, 3, W 12:00 PM - 12:50 PM, Teri Alder, WH1014

1205, MATH, 124, 2, W 11:00 AM - 11:50 AM, Teri Alder, WH1014

1204, MATH, 124, 1, Tu 11:00 AM - 11:50 AM, Teri Alder, SC3009

1234, MATH, 139, 23, TuTh 2:00 PM - 3:15 PM, Peter Lampe, MG0117

1233, MATH, 139, 22, TuTh 2:00 PM - 3:15 PM, John Reilly, HE0112

1232, MATH, 139, 21, MW 2:00 PM - 3:15 PM, Heather Conte, HE0112

1231, MATH, 139, 20, MW 2:00 PM - 3:15 PM, To Be Arranged, HE0102

1230, MATH, 139, 19, TuTh 12:30 PM - 1:45 PM, John Reilly, HE0112

1229, MATH, 139, 19, TuTh 12:30 PM - 1:45 PM, John Reilly, HE0112

1228, MATH, 139, 18, TuTh 12:30 PM - 1:45 PM, Josh Ruk, HE0102

1235, MATH, 139, 24, MW 3:30 PM - 4:45 PM, Josh Ruk, HE0102

1236, MATH, 139, 25, MW 3:30 PM - 4:45 PM, To Be Arranged, HE0112

1237, MATH, 139, 26, MW 3:30 PM - 4:45 PM, Teri Alder, HH1310

1238, MATH, 139, 26, MW 3:30 PM - 4:45 PM, Teri Alder, HH1310

1239, MATH, 139, 27, TuTh 3:30 PM - 4:45 PM, Peter Lampe, MG0117

1240, MATH, 139, 28, Web Based, Corey Bruns, ONLINE S

1241, MATH, 139, 29, Web Based, Corey Bruns, ONLINE S

1242, MATH, 139, 30, Web Based, Heather Conte, ONLINE S

1243, MATH, 139, 31, Web Based, Heather Conte, ONLINE S

1244, MATH, 139, 32, TuTh 2:00 PM - 3:15 PM, To Be Arranged, HE0102

1227, MATH, 139, 18, TuTh 12:30 PM - 1:45 PM, Josh Ruk, HE0102

1226, MATH, 139, 17, MW 12:30 PM - 1:45 PM, Pawel Felcyn, HE0112

1225, MATH, 139, 17, MW 12:30 PM - 1:45 PM, Pawel Felcyn, HE0112

1208, MATH, 139, 1, MW 8:00 AM - 9:15 AM, Morgan Gauvin, HE0102

1209, MATH, 139, 2, TuTh 8:00 AM - 9:15 AM, Huckleberry Rahr, HE0102

1210, MATH, 139, 3, MW 9:30 AM - 10:45 AM, Morgan Gauvin, HE0102

1211, MATH, 139, 4, MW 9:30 AM - 10:45 AM, To Be Arranged, HE0112

1212, MATH, 139, 5, MW 9:30 AM - 10:45 AM, Josh Ruk, MG0117

1213, MATH, 139, 6, TuTh 9:30 AM - 10:45 AM, To Be Arranged, HE0102

1214, MATH, 139, 7, TuTh 9:30 AM - 10:45 AM, John Reilly, HE0112

1215, MATH, 139, 8, MW 11:00 AM - 12:15 PM, To Be Arranged, HE0102

1216, MATH, 139, 9, MW 11:00 AM - 12:15 PM, Pawel Felcyn, HE0112

1217, MATH, 139, 10, MW 11:00 AM - 12:15 PM, Balamurugan Pandiyan, MG0117

1224, MATH, 139, 16, MW 12:30 PM - 1:45 PM, Morgan Gauvin, HE0102

1223, MATH, 139, 16, MW 12:30 PM - 1:45 PM, Morgan Gauvin, HE0102

1222, MATH, 139, 15, TuTh 11:00 AM - 12:15 PM, To Be Arranged, HE0113

1221, MATH, 139, 14, TuTh 11:00 AM - 12:15 PM, Balamurugan Pandiyan, MG0117

1220, MATH, 139, 13, TuTh 11:00 AM - 12:15 PM, Pawel Felcyn, HY0216

1219, MATH, 139, 12, TuTh 11:00 AM - 12:15 PM, To Be Arranged, HE0112

1218, MATH, 139, 11, TuTh 11:00 AM - 12:15 PM, Rachel Chaphalkar, HE0102

1250, MATH, 142, 6, MTuWTh 1:00 PM - 1:50 PM, To Be Arranged, HE0219

1249, MATH, 142, 5, MTuWTh 12:00 PM - 12:50 PM, To Be Arranged, HE0219

1248, MATH, 142, 4, MTuWTh 11:00 AM - 11:50 AM, Xueqing Chen, HE0219

1247, MATH, 142, 3, MTuWTh 10:00 AM - 10:50 AM, Geethamali Samaranayake, UH0144

1246, MATH, 142, 2, MTuWTh 9:00 AM - 9:50 AM, Pawel Felcyn, WH2013

1245, MATH, 142, 1, MTuWTh 9:00 AM - 9:50 AM, To Be Arranged, HE0219

1262, MATH, 143, 12, Web Based, To Be Arranged, ONLINE S

1261, MATH, 143, 11, Web Based, Huckleberry Rahr, ONLINE S

1260, MATH, 143, 10, Web Based, Huckleberry Rahr, ONLINE S

1259, MATH, 143, 9, MW 3:30 PM - 4:45 PM, Leon Arriola, HH1317

1258, MATH, 143, 8, MW 9:30 AM - 10:45 AM, Tina Cao, HH2306

1257, MATH, 143, 7, MW 2:00 PM - 3:15 PM, Ki-Bong Nam, UH0144

1256, MATH, 143, 6, TuTh 12:30 PM - 1:45 PM, Tamas Szabo, HH1317

1251, MATH, 143, 1, MW 9:30 AM - 10:45 AM, Ki-Bong Nam, HH1317

1252, MATH, 143, 2, TuTh 9:30 AM - 10:45 AM, Wesley Hough, HH1317

1253, MATH, 143, 3, MW 11:00 AM - 12:15 PM, Ki-Bong Nam, HH1317

1254, MATH, 143, 4, TuTh 11:00 AM - 12:15 PM, Leon Arriola, HH1317

1255, MATH, 143, 5, MW 12:30 PM - 1:45 PM, Leon Arriola, HH1317

1263, MATH, 147, 1, MTuWTh 2:00 PM - 2:50 PM, Teri Alder, HY0216

1264, MATH, 148, 1, TuTh 9:30 AM - 10:45 AM, Josh Ruk, HY0216

1265, MATH, 148, 2, MW 12:30 PM - 1:45 PM, Josh Ruk, HY0216

1267, MATH, 149, 2, TuTh 12:30 PM - 1:45 PM, To Be Arranged, HY0216

1266, MATH, 149, 1, MW 9:30 AM - 10:45 AM, To Be Arranged, HY0216

1268, MATH, 151, 1, TuTh 9:30 AM - 10:45 AM, Balamurugan Pandiyan, MG0117

1269, MATH, 151, 2, MW 11:00 AM - 12:15 PM, Corey Bruns, HH1310

1270, MATH, 151, 3, TuTh 3:30 PM - 4:45 PM, Pawel Felcyn, UH0144

1271, MATH, 152, 1, MTuWThF 9:00 AM - 9:50 AM, Peter Lampe, HH1310

1272, MATH, 152, 2, MW 2:00 PM - 2:50 PM, Balamurugan Pandiyan, HE0219

1273, MATH, 250, 1, MW 2:00 PM - 2:50 PM, Corey Bruns, HE0117

1276, MATH, 253, 3, MW 2:00 PM - 2:50 PM, Xueqing Chen, HH1310

1275, MATH, 253, 2, MTuWThF 1:00 PM - 1:50 PM, Geethamali Samaranayake, HH1310

1274, MATH, 253, 1, MTuWThF 10:00 AM - 10:50 AM, Peter Lampe, HH1310

1277, MATH, 254, 1, MTuWTh 10:00 AM - 10:50 AM, To Be Arranged, HE0219

1278, MATH, 255, 1, MW 11:00 AM - 12:15 PM, Sobitha Samaranayake, HY0216

1279, MATH, 280, 1, MW 2:00 PM - 3:15 PM, Geethamali Samaranayake, HH1317

1280, MATH, 281, 1, M 5:00 PM - 5:50 PM, Tamas Szabo, HY0216

1281, MATH, 301, 1, MW 2:00 PM - 3:15 PM, Wesley Hough, MG0117

1282, MATH, 343, 1, TuTh 11:00 AM - 12:15 PM, Wesley Hough, HH1310

1283, MATH, 355, 1, MW 3:30 PM - 4:45 PM, Ki-Bong Nam, UH0144

1284, MATH, 361, 1, TuTh 9:30 AM - 10:45 AM, Sobitha Samaranayake, HE0117

1285, MATH, 370, 1, MW 12:30 PM - 1:45 PM, Tamas Szabo, MG0117

1286, MATH, 416, 1, MW 3:30 PM - 4:45 PM, Tamas Szabo, HY0216

1287, MATH, 422, 1, TuTh 2:00 PM - 3:15 PM, Tamas Szabo, HH1317

1288, MATH, 450, 1, MW 12:30 PM - 1:45 PM, Wesley Hough, HE0117

1289, MATH, 452, 1, MW 9:30 AM - 10:45 AM, Xueqing Chen, HE0117

1290, MATH, 471, 1, TuTh 2:00 PM - 3:15 PM, Leon Arriola, MG0125


This project takes in two user defined variables, grossIncome and dependents, and calculates the Net income for the user.


<?php

$grossIncome = $_POST['grossIncome'];

$dependents = $_POST['dependents'];


if ($dependents < "0"){

    echo "Please select number of dependents";

}

else {

    switch ($dependents) {

    case 0:

        $tax = 0.33;

        break;

    case 1:

        $tax = 0.25;

        break;

    case 2:

        $tax = 0.18;

        break;

    case 3:

        $tax = 0.15;

        break;

    case 4:

        $tax = 0.10;

        break;

}

    $taxes = ($grossIncome*($tax));

    $taxes = intval($taxes * ($p = pow(10, 2))) / $p;

    echo "Gross Income: $"."$grossIncome<br>";    

    echo "Taxes: $"."$taxes"."<br>";

    echo "Net Income: $".($grossIncome-$taxes)."<br>";

    

}

echo "<br>";

echo "<br>";

echo '<a href="index.php">Back</a>';

?>

This project is an exercise in file handling.  The user selects a category of product to view.  The program then opens a defined txt file, parses each line for items of the desired category, and displays them for the user.


<?php

$category = $_POST['category'];

if ($category > 0){

@ $fp = fopen("products.txt", "r");


if (!$fp){

echo "<p><strong> File cannot be opened!. Please try again later.</strong></p>";

exit;

}

echo "<h3>Category: $category"."s</h3><br>";

while (!feof($fp)){

    // Read each line

    $product = fgetcsv($fp, 256, ",");

    if ($category == "{$product[1]}"){

        echo "{$product[2]}, $"."{$product[3]} <br>";

    }

}


// close the file

fclose($fp);

}

else {

    echo "Please select an option";

}

echo "<br>";

echo "<br>";

echo '<a href="index.php">Back</a>';


?>

SH/SQL

This script takes data from the file dbusers.dat, appends the corresponding info to SQL commands creating a new user and granting them permissions, then runs the files as a batch in SQL.

dbusers.dat

cs481user1 Cs481password1# cs1FinalDB

cs481user2 Cs481password2# cs2FinalDB

cs481user3 Cs481password3# cs3FinalDB

cs481user4 Cs481password4# cs4FinalDB

cs481user5 Cs481password5# cs5FinalDB

cs481user6 Cs481password6# cs6FinalDB

cs481user7 Cs481password7# cs7FinalDB

cs481user8 Cs481password8# cs8FinalDB

cs481user9 Cs481password9# cs9FinalDB

cs481user10 Cs481password10# cs10FinalDB


The script in action:

You can see after the script executed, the user was then prompted for their mysql password.

If we check out the generated file and the listed users we see they are all there.

The following script takes in a file as a command argument, and backs it up in the directory backupdata

The script in action: