# CSC 170 SESSION 12

Software and s/w Development

Nov 3, 2013 (4 years and 6 months ago)

120 views

1

CSC 170 SESSION
12

Welcome Message

Welcome to Session 1
2

.

Course Web Site(s)

Here is the link to the Course Web site (

CSC

170

)

.

Here is the link to the Online Course Web site (
CSC

171

/

172

/

173

)

.

http://online.oakton.edu

List of Topics for this Week’s Lecture

Web⁐慧a Des楧n⁈楮瑳⁡湤

T楰s

/

䅬Ao物瑨洠Des楧渠䡩湴s⁡湤⁔楰s

W物t楮朠g潭p汥te⁃o浰畴e爠r牯杲g浳

W桡琠hb潵琠tTP㼠⁆楬e⁔牡湳ne爠rr潴ocol

䄠牥癩e眠w映䵡ch楮e⁐牯扬e洠4 ⠠
MP4

(

N畭e物c慬⁉湴敧牡ri潮

)

__________________________________________________________________

Here is a review of various compile commands:

C++

g++ myFile.cpp
-
o myFile

FORTRAN

f90 myFile.f90
-
o myFile

2

Java

javac myFile.java

Using Mathematica

For Homework 3 hints, please visit the
CAS3Shell

Mathematica file located in the campus
Samples

directory.

Web Page Design Hints and Tips

Review of HTML

Using JavaScript

/

VBScript

Here is a simple VBScript example.

<
html
>

<
><
title
>
a simple Web page
</
title
>

<
script

type

=

"text/vbscript">

<!
--

Sub Button1_OnClick

MsgBox "Chicago Bears"

End Sub

--
>

</
script
>

</
>

<
body
>

<
h3
>

a simple Web page

</
h3
>

<
hr
>

<
form
>

<
input

name
= "button1"

type
=
"button"

value
= "click

here">

</
form
>

</
body
>

</
html
>

Algorithm Design Hints and Tips

What is an Algorithm? Review the "

Taxi

-

Cab Distance

" in Mathematics
SP8

(

Special Project 8

)

.

The "

Taxi

-

Cab Distance

" between two points (

x

1

,
y

1

) and (

x

2

,
y

2

) is defined as the

" greater " distance between the two points or

: |
x

2

x

1

| + |
y

2

y

1

|

Compare this to the " shortest " distance between the two points, defined by Pythagoras as

:

(

(
x

2

x

1

)

2

+ (
y

2

y

1

)

2

)

2

3

Writing Complete Computer Programs

Here are the steps for simple file processing:

Writing to a File

declare a file name

declare a file processing object

store some text or numbers in a local variable

write the contents of the variable in the te
xt file

close the file processing object

declare a file name

declare a file processing object

read some text or numbers in a local variable

display the contents of the variable on the screen

close the file processing
object

Here are some file processing examples:

FORTRAN

program

average

!declarations for file processing

integer

:: fin = 3, fout = 4

real

:: x = 0

integer

:: count = 0, ierror

real

:: averageVal = 0

4

! 1) file variable initializations

open(unit = fin, file =
"file_in.dat"
, action =
)

open(unit = fout, file =
"file_out.dat"
, action =
"write"
)

! 2) loop over the input file

do

! 3) attempt to input an ordered pair

(fin, *, iostat = ierror) x

! 4) test for end of file

if

(ierror /= 0)
then

! 5) leave if true

exit

endif

! 6) accumulate the sum

averageVal = averageVal + x

count = count + 1

enddo

! 7) compute average

averageVal = averageV
al / count

! 8) write the average value

write
(fout, *)
"average = "
, averageVal

! 9) disconnect from files

close
(fin)

close
(fout)

end

program

average

5

C++

//(1) write the preprocessing directives

#include

<iostream>

//cin, cout

#include
<
cstring>

//string variables

#include

<fstream>

//file processing

#include

<conio.h>

//clear screen

using

namespace

std;

//(2) open the scope of the main() method

void

main()
{

//(3) declare and initialize the variables

static

char

chrName[100];

//employee name

double

myExpenses;

//individual expense

char

myLabels[100];

//expense label

int

index = 0;

//loop control variable

int

number = 0;

//number of expense items

ofstream fout;

//file stream output

//(4) file variable
initialization

fout.open(
"data.txt"
);

//(5) clear the screen

system(
"CLS"
);

//(6) request the employee name

cout <<
"enter the employee name: "

<< endl;

cin.getline(chrName,100);

//(7) request the number of expense items

cout <<
"enter the number of expense items: "

<< endl;

cin >> number;

cin.ignore();
//skip [Enter] entry from keyboard;

//(8) open the looping structure

while

(index <= number)

{

6

index++;

//(9) request the user for an expense item

cout
<<
"enter the type of expense: "

<< endl;

cin.getline(
myLabels
,100);

cout <<
"enter the amount of expense: "

<< endl;

cin >> myExpenses;

//(10) write the data to a text file

fout << chrName <<
":"

<<
myLabels

<<
":"

<<

myExpenses << endl;

cin.ignore();
//skip [Enter] entry from keyboard;

//(11) close the scope of the while() loop

}

//(12) close the file

fout.close();

//(13) close the scope of the main() method

}

Java

//Sammy Student:
programmer

import java.awt.Graphics;

import javax.swing.JOptionPane;

import java.io.*;

import java.io.FileWriter;

public

class

CreateData {

public

static

void main(
String
[] args)

{

JOptionPane.showMessageDialog(null,

"this program
writes payroll data"
,

"Welcome"
, JOptionPane.PLAIN_MESSAGE);

Write();

}

static

void Write()

{

try

{

String

firstLine, secondLine, thirdLine, number;

File check =
new

File(
"payroll.txt"
);

FileWriter file;

if
(check.exist
s())

file =
new

FileWriter(
"payroll.txt"
,
true
);

else

7

file =
new

FileWriter(
"payroll.txt"
);

BufferedWriter buffer =
new

BufferedWriter(file);

int size, count = 1;

number = JOptionPane.showInputDialog(
"how many records?"
);

size =
Integer
.parseInt(number);

do

{

firstLine = JOptionPane.showInputDialog(
"Enter name"
);

secondLine = JOptionPane.showInputDialog(
"Enter hours"
);

thirdLine = JOptionPane.showInputDialog(
"Enter wage"
);

buffer
.write(firstLine);

buffer.newLine();

buffer.write(secondLine);

buffer.newLine();

buffer.write(thirdLine);

buffer.newLine();

count++;

}
while
(count <= size);

Review of Binary Numbers

Bitwise manipulation examines the individual digits comprising a binary number

and performs some operation with this number and perhaps another number.

Here are some examples of bitwise manipulation:

NOT 1001 (

decimal
9 )

= 0110 (

decimal 6

)

( here
we examine the complement of the digits

i.e. we flip or toggle your digital
state )

0101 (

decimal
5 )

OR

0110 (

decimal 6

) = 0111 (

decimal 7

)

( OR performs an operation on digits in corresponding positions )

0101 (

decimal
5 )

XOR

0110 (

dec
imal 6

) = 0011 (

decimal 3

)

( XOR performs an operation on digits in corresponding positions and returns a 1
only if the digits differ )

0101 (

decimal
5 )

AND

0110 (

decimal 6

) = 0100 (

decimal 4

)

( AND performs an operation on digits in corresp
onding positions and returns a 1
only if the digits ARE BOTH 1 )

00110101 LEFT

-

SHIFT = 01101010

00110101 RIGHT

-

SHIFT = 00011010

Shifts in C, C++ and Java

8

Bit

wise manipulation

/* The obvious method */

if (x < y)

r = x;

else

r = y;

/* A method using bit manipulation */

r = y + ((x
-

y) &
-
(x < y));

Source code that performs bit manipulation makes use of the bitwise operations: AND, OR,
XOR, NOT, and bit shifts.

Binary to Hex
Conversion

Here are some examples to convert from an integer binary number to hexadecimal.

Split the binary number into 4

-

bit sections from the least significant bit to the most significant
bit.

Convert the 4

-

bit binary number to its hexadecimal
equivalent.

For example, the binary value
1010111110110100

will be written:

1001

1111

1011

0100

9

F

B

4

Hex to Binary Conversion

Here are some examples to convert from an integer hexadecimal number to binary.

number to its 4

-

bit binary equivalent.

Combine the 4

-

bit sections by removing the spaces.

9FB4

will be written:

9 F B 4

1001 1111 1011 0100

This yields the binary number 1001111110110100

.

9

Using
FTP

What is FT
P? File Transfer Protocol

To connect to your personal campus network drive:

ftp://ftp.oakton.edu

To connect to the F:
\

Samples drive:

ftp://samples.oakton.edu

A Preview
of MP 5 (

Linear Regression

)

Machine Problem 5 deals with reading linear data from an input file, finding the line of best fit
using linear regression (

least squares

) techniques and displaying the result in a text file.

Here is a sample run of the MP5

problem. Review the Mathematical Background for this
machine problem.

Notice that when you run the mp5 executable, the program lacks the usual console input and
output.

Here is the input data as read from the
mp5.inp

file. To read the file in Linux type the
following command:

cat mp5.inp

Here is the output data as read from the
mp5.out

file. To read the file in Linux type the
following command:

cat mp5.out

10