CSC 170 SESSION
7
Welcome Message
Welcome to Session
7
.
Course Web Site(s)
Here is the link to the C
ourse Web site (
CSC
170
)
.
http://www.papademas.net/occ/csc170
Here is the link to the
Online C
ourse Web site
(
CSC
1
71
/
172
/
173
)
.
http://online.oakton.edu
What are the Deliverables for this Week?
SP4
( CSC 17
0 )
,
and Quiz 3
( CSC 171 / 172 / 173 )
.
What are the Deliverables for next
Week?
SP5
( CSC 17
0 )
,
Lab 3
( CSC 17
0
)
, Midterm Exam
( CSC 17
0 )
and Quiz 3
( CSC 171 / 172 / 173 )
.
List of Topics for this Week’s Lecture
SomeLin䍯mm慮ds
Using
M慴hem慴ica
WebP慧e
DesignHints慮dTips
UsingJ慶慓cript
Algorithm
DesignHints慮dTips
Writing䍯mplete
C
ompterProgr慭
s
Reviewof
Bin慲yNmber
s
Reviewof
He慤ecim慬Nmber
s
Wh慴慢otFTP?
FileTr慮sferProtocol
Areviewof
M慣hineProblem
3
⠠
䵐
3
⤠
(
Nmeric慬Q慤r慴re
)
__________________________________________________________________
Some Linux Commands
How do I start an MP (Machine Problem)
?
Consider completion of
MP3
(
Numeric Quadrature or Area Approximation
)
.
Repetitive Execution
Numeric Quadrature
Quick start
Open a Linux Telnet Session
cd mps
travel to your mps directory
mkdir 3
within the mps directory create a folder called 3
cd 3
travel to the new folder named 3
cp /samples/csc/172/mps/3/* .
copy
some files from the sample directory
emacs mp3.f90
open the sample file for MP3
Write your code within mp3.f90
Compile Step
f90 mp3.f90

o mp3
Fortran Compile Command
Fix any errors
Execute step
mp3
Execute the program and test the l
ogic of the
program
Using
Mathematica
For Homework
2
hints, please visit the
CAS
2
Shell
Mathematica file located in the campus
Samples
directory.
Here are some examples from Homework
2
.
(*3abcde, 4abcd Page 59 *)
(* these commands declare
two functions *)
f[x_] = x^3 + x^2 + x + 1
g[x_] = x^5 + x^4 + x^3 + x^2 + x + 1
1+x+x
2
+x
3
1+x+x
2
+x
3
+x
4
+x
5
f[3]
(* this command evaluates a function *)
(* this command plots the function on a 2D grid *)
Plot[f[x], {x,

10, 10}, AspectRatio

> 1,
PlotRange

> {{

10, 10}, {

10, 10}}]
Web Page
Design Hints and Tips
Review of HTML
Here
are some questions and answers concerning making a Web page with
HTML
.
(1)
What does
HTML
element stand for?
(a)
Hyperlinks and Text Markup Language
(b)
Home Tool Markup Language
(c)
Hyper Text Markup Language
(d)
Hyper Text Markup Locator
(e)
Hyper Links and Markup Locator
(2)
Who is making the Web standards?
(a) Netscape
(b) The World Wide Web Consortium
(c) Microsoft
(d)
IBM
(3)
Choose the correct
HTML
tag for the largest heading
(a)
<h1>
(b)
<head>
(c)
<hr>
(d)
<h6>
(e)
<heading>
(4)
What is the correct
HTML
tag for inserting a line break?
(a)
<lb>
(b)
<hr>
(c)
<br>
(d)
<break>
(e)
<line>
(5)
What is the correct
HTML
for adding a background color?
(a)
<background>blue</background>
(b)
<body color = "blue">
(c)
<body myColor = "blue">
(d)
<body background = "blue">
(e)
<body bgColor = "blue">
(6)
Choose the correct
HTML
tag to make a text bold.
(a)
<bold>
(b)
<bb>
(c)
<bld>
(d)
<b>
(e)
<i>
(7)
Choose the correct HTML tag to make a text italic.
(a)
<i>
(b)
<hr>
(c)
<b>
(d)
<ii>
(e)
<italics>
(8)
What is the correct HTML for making a hyperlink?
(a)
<
a>http://www.fye.com</a>
(b)
<a url = "http://www.fye.com">MUSIC AND MOVIES</a>
(c)
<a name = "http://www.fye.com">FYE</a>
(d)
<a src = "http://www.fye.com">FYE</a>
(e)
<a href = "http://www.fye.com">fye</a>
(9)
How can you make an e

mail link?
(a)
<a href = "webcourses@aol.com">
(b)
<mail>webcourses@aol.com</mail>
(c)
<a href = "mailto:webcourses@aol.com">
(d)
<mail href = "webcourses@aol.com">
(e)
<mail src = "webcourses@aol.com">
(10)
How can you open a link in a new browser window?
(a)
<a href = "url" new>
(b)
<a href = "url" target = "new">
(c)
<a href = "url" target = "_blank">
(d)
<link href = "url">
(e)
<mail src = "url">
(11)
Which of these tags are all
<table>
tags?
(a)
<thead><body><tr>
(b)
<table><tr><tt>
(c)
<table><tr><td>
(d)
<table><head><foot>
(e)
<array><tr><td>
(12)
Choose the correct
HTML
to right

align the content inside a table cell.
(a)
<td align = "right">
(b)
<td rightalign>
(c)
<td
valign = "right">
(d)
<tdright>
(13)
How can you make a list that lists the items with numbers?
(a)
<dl>
(b)
<list>
(c)
<ol>
(d)
<ul>
(e)
<style>
(14)
How can you make a list that lists the items with bullets?
(a)
<dl>
(b)
<ol>
(c)
<list
>
(d)
<ul>
(e)
<style>
(15)
What is the correct
HTML
for making a checkbox?
(a)
<check>
(b)
<input type = "check">
(c)
<input type = "checkbox">
(d)
<checkbox>
(16)
What is the correct
HTML
for making a text input field?
(a)
<
textfield>
(b)
<textinput type = "text">
(c)
<input type = "text">
(d)
<input type = "textfield">
(17)
What is the correct
HTML
for making a drop

down list?
(a)
<list>
(b)
<
select>
(c)
<input type = "dropdown">
(d)
<
input type = "list">
(18)
What is the correct
HTML
for making a text area?
(a)
<input type = "textarea">
(b)
<input type = "txt">
(c)
<input type = "textbox">
(d)
<textarea>
(19)
What is the correct
HTML
for inserting an image?
(a)
<
img>image.gif</img>
(b)
<img src = "image.gif">
(c)
<img href = "image.gif>
(d)
<image source = "image.gif">
(e)
<image scr = "image.gif">
(20)
What is the correct
HTML
for inserting a background image?
(a)
<img src = "background.gif" background
>
(b)
<background img = "background.gif">
(c)
<body background = "background.gif">
(d)
<body bgColor = "background.gif">
(e)
<body back = "background.gif">
Using JavaScript
Simple
VB
Script
Compare VBScript to JavaScript.
Here is a VBScript example
which
generates a random number
from 0 to 1
.
<
html
>
<
body
>
<
script
type
=
"text/vbscript">
Randomize()
document.write(Rnd())
</
script
>
</
body
>
</
html
>
Algorithm
Design Hints and Tips
What is an Algorithm? Review Numerical Area Approximation
MP3
(
Quadrature
Methods
)
.
The purpose of
MP3
is to illustrate the process of Numerical Quadrature
–
the purpose of which
is to approximate the area under a curve or function. Various methods t
o approximate are
include the Rectangular Approximation Method, Trapezoidal Approximation Method (
using
trapezoids
) and Simpson’s Rule (
using parabolas
)
.
Techniques of Numerical Integration
What is
numerical integration
? Numerical Integration is a
technique in calculus to find the area under a
portion of a curve. Often, in fields such as statistics and engineering science, the calculated areas
correspond to physical quantities. For example, in statistics, the area under a normal bell

shaped curv
e
is used to compute probabilities of a standard normal variable.
Similar to polynomial equation root finding techniques, there are a number of approximation techniques
that can be used to determine the area under a portion of a curve.
(1)
(
Rectangular
Approximation Method
)
The procedure to compute the area under a curve using the Rectangular Approximation Method is as
follows:
First, take an arbitrary continuous function
f
(
x
)
for which the area under the curve of
the
function is to be co
mputed, within the interval bounded between
x
a
and
x
b
.
Next, divide the area within this interval between
x
a
and
x
b
into
N
rectangles of equal
widths
w
,
where
N
is some arbitrary number. The larger the value of
N
generally
results in a
better approximation. The width of each subinterval is the total width divide by the number of
subintervals or
w
b
a
N
The beginning point of each subinterval is designated by the sequence
x
1
,
x
2
,
x
3
, . . . ,
x
N
The start of the first subinterval is
x
1
and the end of the
N
th subinterval is
x
N
1
The total area under the curve between
a
and
b
is therefore is the sum of the individual areas
under the
N
subintervals. This area basically approximates the actual area under the curve.
Since the area of a rectangle is simply the width multiplied by the height where
w
is the width
then the area
A
i
of the
i
th subinterval is expressed as:
A
i
w
f
(
x
i
)
The total area then would be:
AREA
A
1
A
2
A
3
. . .
A
N
or
N
AREA
w
f
(
x
i
)
i
1
where
w
b
a
N
x
1
a
and
x
i
1
x
i
w
and the index
i
runs from 1 to
N
.
This area then approximates the area under the curve between the limits
x
a
and
x
b
.
For computer programming purposes, the pseudocode for this algorithmic procedure is:
enter the left bound
a
and the right bound
b
and the number
of subintervals
N
calculate the width
w
initialize
x
set total area equal to zero
do for all rectangles
calculate the
y
value corresponding to
x
calculate the area of the rectangle
add the rectangular area to the total area
update the value of
x
end do
display total area
(2)
(
Modified Rectangular Approximation Method
)
This is a modification of the standard Rectangular Approximation Method. This modified
program is sometimes referred to as the
midpoint method
.
The only difference with this method from the standard Rectangular Approximation Method is
that the value of
y
at the midpoint of the subinterval rather than at the start of the subinterval is
used as the height of the rectangle.
The total area under
the curve would therefore be approximated by the equation:
N
AREA
w
f
(
x
i
w
/
2
)
i
1
where
w
b
a
N
x
1
a
and
x
i
1
x
i
w
and the index
i
runs from 1 to
N
.
(3)
(
Trapezoidal
Approximation Method
)
This method to approximate the area under a curve is also divided into subintervals similar to the
rectangular methods. However with this method, the area under the curve is now approximated
by connecting a straight line between the points on the curve corresponding to the start and end
of the subinterval. What we obtain is a trapezoid made up of a rectangle and a triangle.
The
total area under the curve, for this method, would therefore b
e approximated by the equation:
N
AREA
0.50
w
f
(
a
)
f
(
b
)
w
f
(
x
i
)
i
2
where
w
b
a
N
x
1
a
and
x
i
1
x
i
w
and the index
i
runs from 1 to
N
.
Writing Complete
C
omputer Program
s
The typical steps to write a program
are given in the example below that computes
a
binary
logarithm or the number of times it takes to subdivide a number into two parts.
!FORTRAN version
program
main
!binary logarithm
!declare the variables
integer :: counter = 0
integer :: myNumber = 0
!input the even number
write(*,*) "dude, give me an even number"
read (*,*) myNumber
!
perform computations
do
counter = counter + 1
myNumber =
myNumber / 2
!
display computations
write(*,*) counter , " " , myNumber
If (myNumber <= 1) Then
exit
End If
enddo
End program main
Review of Binary Numbers
What is XOR Logic?
Introduction to XOR Encryption
XOR
encryption works as a bitwise operation.
XOR = Exclusive OR
1 = True
0 = False
Truth Table
Given Logic Conditions (Operands) P and Q
P
Q
P XOR Q
1
1
0
1
0
1
0
1
1
0
0
0
For XOR logic, the output is true only if the inputs disagree.
I have an
output of “true” or 1 only when my inputs disagree.
Regular OR Operation
Truth Table
Given Logic Conditions (Operands) P and Q
P
Q
P OR Q
1
1
1
1
0
1
0
1
1
0
0
0
For Standard OR logic, the output is true except if both inputs disagree.
Plaintext Message:
attack
Keyword:
soxwin
Letter
ASCII
Binary Equivalent
a
97
0110 0001
t
116
0111 0100
t
116
0111 0100
a
97
0110 0001
c
99
0110 0011
k
107
0110 1011
Letter
ASCII
Binary Equivalent
s
115
0111 0011
o
111
0110 1111
x
120
0
111 1000
w
119
0
111 0111
i
105
0110 1001
n
110
0110 1110
XOR Comparison
plaintext character a
0110 0001
keyword character s
0111 0011
___________
0001 0010
0001 0010
2
=
18
10
Binary
Decimal
Note: 18 is not in the range
of 97
–
122 (ASCII lower case)
If the number you arrive at is less than
97, then keep multiplying it by a factor of 26 or keep adding 26 until such time as I
arrive at a number in the ASCII range 97
–
122
122 = 18 + 4 * 26
Hence I can encrypt the first "
a" in attack as a z.
XOR Comparison
t
0111 0100
o
0110 1111
___________
0001 1011
0001 1011
2
=
27
10
Note: 27 is not in the range of 97
–
122
If the number you arrive at is less than
97, then keep multiplying it by a factor of 26
or keep adding 26 until such time as I
arrive at a number in the ASCII range 97
–
122
105 = 27 + 3 * 26
Hence I can encrypt the second letter t in attack as an "i".
What about using a negative binary number?
Consider 0001 1011. What is the negative
equivalent of this number? Hint: use the
so
–
called twos complement method.
Original Number
0001 1011
Complement of the Number
1110 0100
Add 1 to the complement
1110 0101
Check if 1110 0101 is the opposite number of 0001 1011 (try the windows
calculator)
100000000
Review of
Hexadecimal Number
s
Hexadecimals are use in HTML Coloring.
Three ways to write colors into an HTML document.

As a Named Color

As a straight hexadecimal color

As an RGB triplett
Using
FTP
We
can create a file in
Notepad and ftp it to our Linux account for compiling purposes.
In this
manner we can create a FORTRAN, Java or C
+
+ file within Notepad and transfer it to our Linux
accounts. Here are some generic steps followed by screen snapshots.
Open Notepad
Type the Program Code
Save the File to your C:
\
Drive
Open the
Windows
Command Prompt
Open an ftp Connection
ft
p the File to your Linux Account
Open the Windows Command Prompt
Telnet into your Linux Server
Verify that the file was Transferred
Compile the File
Execute the File
A
Pre
view of MP
3
(
Numerical Quadrature
)
Here is a sample run of the MP
3
problem.
A Preview of SP4 (
The Mysterious Number
e
)
Euler’s Number
A good example of looping techniques and working with an
accumulated sum.
The standard series expansion for
e
x
(
due to mathematician
Colin Maclaurin )
is shown below
e
x
1
x
/ 1
!
x
2
/ 2
!
x
3
/
3
!
x
4
/
4
!
x
5
/
5
!
. . .
where
e is the base number of the natural number system such that
e
2.71828 and
where
1
!
represents 1 factorial,
2
!
represents 2 factorial, and so on.
If
x
1
, the above formula becomes
e
1
1
1
/ 1
!
1
2
/ 2
!
1
3
/
3
!
1
4
/
4
!
1
5
/
5
!
. . .
or
e
1
1
1
/
1
1
/ 2
1
/
6
1
/
24
1
/
120
. . .
As decimal equivalents
e
1
1.00
1
0.50
0.16667
0.041667
0.008333
0.0013889
0.000198412698
. . .
e
1
2.71827
For programming purposes our code sets up an accumulating sum to calculate e ^ x
As follows
sum = 1
(
before we enter the loop
)
sum = 1 + x / Factorial(1)
(
first iteration
)
sum = 1 + x / Factorial(1)
+ x / Factorial(2)
(
second
iteration
)
each iteration improves the value of e ^ x until such time as we are satisfied with the result.
For the modification:
In VBScript a For Loop Structure is as follows:
For counter = 1 To N, Step 1
'statements to execute
Next counter
Dim i
ndex
For
Index = 1
To
20
sum = sum + x / factorial(index)
x = temp * x
Next
Within the body of the loop we would write
document.write( "counter value: " & Index
& "<br />"
)
document.write( "
current sum
: " &
sum & "<br />"
)
Quiz 3 Hints Revisited
#include
<iostream>
using
namespace
std;
void
main()
{
bool
condition1 =
true
;
bool
condition2 =
false
;
if
(condition1)
{
if
(condition2)
cout <<
"two"
;
}
else
cout <<
"one"
;
}
An output is not produced
#include
<iostream>
using
namespace
std;
void
main()
{
bool
condition1 =
false
;
bool
condition2 =
true
;
if
(condition1)
{
if
(condition2)
cout <<
"two"
;
}
else
cout <<
"one"
;
}
FORTRAN Select Case structure
'Declare variables
INTEGER :: Number, Sign
'Initialize the
variables
Number = 1
Sign =

1
'Enter the Case Structure
SELECT CASE (Number)
CASE ( :

1)
Sign =

1
CASE (0)
Sign = 0
CASE (1 : )
Sign = 1
END SELECT
WRITE(*,*) "Sign = ", Sign
Select Case structures are used when we have in
dividual values to test
and
not
a range of values.
Enter the password to open this PDF file:
File name:

File size:

Title:

Author:

Subject:

Keywords:

Creation Date:

Modification Date:

Creator:

PDF Producer:

PDF Version:

Page Count:

Preparing document for printing…
0%
Comments 0
Log in to post a comment