Date post: | 20-Dec-2015 |
Category: |
Documents |
View: | 216 times |
Download: | 3 times |
Visual X++Visual X++A Tutorial About Several Popular A Tutorial About Several Popular
Programming LanguagesProgramming Languages
Dr. Bernie DomanskiDr. Bernie DomanskiThe City University of New YorkThe City University of New York
The College of Staten IslandThe College of Staten Island
[email protected]@superlink.net
http://domanski.cs.csi.cuny.edu/http://domanski.cs.csi.cuny.edu/
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 2
OutlineOutlineOutlineOutlineLanguages We’ll Look at:Languages We’ll Look at:• Visual BasicVisual Basic• C++ and Visual C++C++ and Visual C++• Java and Visual J++Java and Visual J++• JavaScript and a little HTMLJavaScript and a little HTML
Disclaimer:Disclaimer:• This talk is This talk is NOT ABOUT PERFORMANCE OR CAPACITYNOT ABOUT PERFORMANCE OR CAPACITY• We are looking only at Microsoft implementations of VB, We are looking only at Microsoft implementations of VB,
VC++ and VJ++VC++ and VJ++• There are other versions that may, in fact, be betterThere are other versions that may, in fact, be better• I am not an expert!I am not an expert!
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 3
Common ProgramCommon ProgramCommon ProgramCommon Program
• We’ll try to implement a simple We’ll try to implement a simple loanloan program in each language –program in each language –
• Inputs –Inputs –– Principle (amount being borrowed)– Interest Rate (annual – expressed as
8.5 )– No. of Years (term of the loan)
• OutputOutput– Monthly Payment
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 4
Some ExplanationSome ExplanationSome ExplanationSome Explanation
• The formula:The formula:Payment = Principle * (InterestRate/1200.) / (1- { [ 1 / (1+InterestRate/1200.) ] ^ [NoOfYears*12]
} );
• What’s Going On?What’s Going On?– Dividing the InterestRate by 1200 yields the
interest rate per month as a fraction – eg. .085– Multiplyling the NoOfYears by 12 yields the number
of months of the loan’s term– ^ is the symbol for “to the power”
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 5
The Development The Development EnvironmentEnvironment
The Development The Development EnvironmentEnvironment
• Very similar in all the MS productsVery similar in all the MS products• How to develop an applicationHow to develop an application – –
– Draw the user interface … like a paint program would
– Command buttons, text boxes, and other objects will automatically recognize events
– You write code that responds to each event
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 6
Events and ObjectsEvents and ObjectsEvents and ObjectsEvents and Objects
• EventsEvents– Mouse click or double click– Key pressed
• ObjectsObjects– Command button, Radio button, Check
box– Text box, Scroll Bar, etc
• Event-driven programmingEvent-driven programming– Tiny interrupt handlers!
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 7
Objects and MethodsObjects and MethodsObjects and MethodsObjects and Methods
• PropertiesProperties– Features that you can change –– eg. Color, font, alignment– Use the Properties Window to set feature
values at design time
• MethodsMethods– Functions that come packaged with the
object that manipulate the object– eg. Add items to a combo box
Combo Box Example
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 8
Visual BasicVisual BasicVisual BasicVisual Basic
• Lets build the loan program –Lets build the loan program –– Draw the GUI– Write some code– Try it out …
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 9
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 10
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 11
Try IT !!Try IT !!Try IT !!Try IT !!
VB Loan Program
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 12
Common Objects & SamplesCommon Objects & SamplesCommon Objects & SamplesCommon Objects & Samples
• Command buttonsCommand buttons• Edit box, labelsEdit box, labels• Scroll barsScroll bars• TimersTimers• Combo boxesCombo boxes• Common Dialog ControlCommon Dialog Control• GraphicsGraphics
13(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved.
Where to Get StuffWhere to Get StuffWhere to Get StuffWhere to Get Stuff
• All of the samples shown in this All of the samples shown in this presentation can be accessed and presentation can be accessed and downloaded from downloaded from http://domanski.cs.csi.ciny.edu/http://domanski.cs.csi.ciny.edu/
• Look for the Look for the Languages Languages TutorialTutorial .zip file within the area .zip file within the area called ‘called ‘Stuff to Download’Stuff to Download’
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 14
Visual C++Visual C++Visual C++Visual C++
• Remember the movie Remember the movie The The ExorcistExorcist? Remember the twisting ? Remember the twisting of the little girl’s head? That what of the little girl’s head? That what happens to YOUR head when happens to YOUR head when diving into C++ !!diving into C++ !!
• Lets build the Lets build the loanloan program … program …
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 15
Run the Loan ProgramRun the Loan ProgramThen We’ll Build It !!Then We’ll Build It !!
Run the Loan ProgramRun the Loan ProgramThen We’ll Build It !!Then We’ll Build It !!
Loan / Mortgage
Program via C++
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 16
There’s LOTS to C++There’s LOTS to C++There’s LOTS to C++There’s LOTS to C++
• Classes yield objectsClasses yield objects• TemplatesTemplates• Function OverloadingFunction Overloading• Operator OverloadingOperator Overloading• Constructors / DestructorsConstructors / Destructors• InheritanceInheritance• More (Virtual Functions, Containers, More (Virtual Functions, Containers,
…)…)
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 17
C++ Code SamplesC++ Code SamplesC++ Code SamplesC++ Code Samples
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 18
Visual J++Visual J++Microsoft’s Java ImplementationMicrosoft’s Java Implementation
Visual J++Visual J++Microsoft’s Java ImplementationMicrosoft’s Java Implementation
• Java is considered by many to be a Java is considered by many to be a subsetsubset of C++ of C++
• Designed and first developed by SUNDesigned and first developed by SUN• Java programs can run as non-Web Java programs can run as non-Web
entities … but …entities … but …• Java Java appletsapplets (programs that execute (programs that execute
on Web servers) are very popularon Web servers) are very popular
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 19
Java AppletsJava AppletsJava AppletsJava Applets
• There’s got to be a web page There’s got to be a web page defined (.HTML code) where the defined (.HTML code) where the Java code resides.Java code resides.
• So we have to define a web page, So we have to define a web page, andand
• … … the Java applet the Java applet
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 20
The Web PageThe Web PageThe Web PageThe Web Page
• And the java source …And the java source …• And the java applet …And the java applet …
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 21
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 22
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 23
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 24
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 25
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 26
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 27
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 28
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 29
C:\JavaScript\Java\examples\mortgage-applet\mortgage.htm
30(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved.
JavaScriptJavaScriptJavaScriptJavaScript
• Fast and fun …Fast and fun …• Simplistic programming language Simplistic programming language
… similar to a macro language… similar to a macro language• Great JavaScript Tutorial website: Great JavaScript Tutorial website:
http://www.netkontoret.dk/javascript.htm
• The Dr Bernie Java & JavaScript The Dr Bernie Java & JavaScript site:site:http://domanski.cs.csi.cuny.edu/420stuff/420frame.htm
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 31
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 32
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 33
The Loan Program in The Loan Program in JavaScriptJavaScript
The Loan Program in The Loan Program in JavaScriptJavaScript
• HTML defines the web pageHTML defines the web page• JavaScript code is embedded in the JavaScript code is embedded in the
HTML sourceHTML source• We’ll also use some graphics and We’ll also use some graphics and
……• … … a scrolling messagea scrolling message
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 34
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 35
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 36
Source CodeSource CodeSource CodeSource Code<HTML>
<HEAD>
<TITLE>Home Finders Nationwide Realty</TITLE>
<!---------------------------------------------->
<SCRIPT language="javascript">
<!--Hide from old browsers
//
// Scrolling message has 4 components -
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 37
// 1- display object- defines where the scrolling object displays
// 2- the message - text string assigned to a variable
// 3- the position - the starting location in whichthe message first displays in the display object
// 4- the delay - the length of time between when a message ends and when it starts to appear again
//
var scrollMsg = "Mortgage rates are at their LOWEST !!"
var msgSpace = "--- ---"
var beginPos = 0
JS Code – page 2
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 38
function scrollingMsg(){
document.msgForm.textBox.value =
scrollMsg.substring(beginPos,scrollMsg.length)+ msgSpace+scrollMsg.substring(0,beginPos)
beginPos = beginPos + 1
if (beginPos > scrollMsg.length) {
beginPos = 0
}
//
// recursive function call using setTimeout ...
window.setTimeout("scrollingMsg()",200)
}
JS Code – page 3
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 39
function doMort() {
//
// first, statements to clear the text boxes ...
//
document.MortCalc.Amount.value=" "
document.MortCalc.Rate.value=" "
document.MortCalc.Years.value=" "
document.MortCalc.Payment.value=" "
document.MortCalc.Amount.focus()
}
JS Code – page 4
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 40
function Calc(myform) {
//
// converts & strores the text box values as integer or floating point var's
// this function passes the value of the text box to a variable,
// uses the partseInt() function to convert the variable to a number, and
// then uses the isNaN() function to verify the value is a number.
//
// To pass the text box values to the function, you must
// pass the form (in this case, myform) to the Calc function
//
JS Code – page 5
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 41
var mortAmount = document.MortCalc.Amount.value
var mortAmount = parseInt(mortAmount,10)
if (isNaN(mortAmount)) {
alert("The loan amount is not a number")
document.MortCalc.Amount.value=" "
document.MortCalc.Amount.focus()
}
JS Code – page 6
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 42
else {
//
// check the other fields ...
//
var mortRate = document.MortCalc.Rate.value
var mortRate = parseFloat(mortRate)
if (isNaN(mortRate)) {
alert("The interest rate is not a number")
document.MortCalc.Rate.value=" "
document.MortCalc.Rate.focus()
}
JS Code – page 7
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 43
//
else {
var mortYears = document.MortCalc.Years.value
var mortYears = parseInt(mortYears,10)
if (isNaN(mortYears)) {
alert("Number of years is not a number")
document.MortCalc.Years.value = " "
document.MortCalc.Years.focus()
}
}
}
JS Code – page 8
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 44
//
// so if everything is valid, call on the monthly() function
// to compute the monthly payment
//
document.MortCalc.Payment.value = monthly(mortAmount, mortRate, mortYears)
}
JS Code – page 9
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 45
//
// the monthly() function - following the formula
function monthly(mortAmount, mortRate, mortYears) {
var Irate = mortRate / 1200
var Pmts = mortYears * 12
var Loan = mortAmount
return Loan * (Irate / (1 - (1 / Math.pow(1+Irate,Pmts))))
}
//-->
</script>
<!---------------------------------------------->
</HEAD>
JS Code – page 10
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 46
<BODY onload="scrollingMsg()">
<P ALIGN="CENTER"><IMG SRC="HOMELOGO.JPG">
</P>
<DIV ALIGN="CENTER"><CENTER>
<TABLE BORDER="0" WIDTH="75%">
<TR>
<TD></TD>
<TD><P ALIGN="CENTER"><IMG SRC="calculator.jpg" WIDTH="100" HEIGHT="106"
ALT="Check out Rates"></TD>
<TD></TD>
</TR>
JS Code – page 11
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 47
<TR>
<TD><P ALIGN="CENTER">
<IMG SRC="house1.gif" WIDTH="180" HEIGHT="144">
</TD>
<TD>
<P ALIGN="CENTER">
<A HREF="#LoanCalc" onclick="doMort()">Estimate Mortgage Payment</a>
</p>
<!---------------------------------------------->
<FORM Name="msgForm">
<INPUT Type="text" Name="textBox" Size="33">
</FORM>
<!---------------------------------------------->
</TD>
<TD><P ALIGN="CENTER">
<IMG SRC="house2.gif" WIDTH="180" HEIGHT="144"></TD>
</TR>
JS Code – page 12
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 48
<TR>
<TD></TD>
<TD><IMG SRC="house3.gif" WIDTH="180" HEIGHT="144"></TD>
<TD></TD>
</TR>
</TABLE>
</CENTER></DIV>
<P ALIGN="CENTER">
<BR>
JS Code – page 13
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 49
<A NAME="LoanCalc"></P>
<H3 ALIGN="CENTER">Estimate Mortgage Payments</H3>
</A>
<CENTER>
<FORM Name="MortCalc">
<TABLE>
<TR>
<TD>Amount of Mortgage:</TD>
<TD><INPUT Type="text" Name="Amount" value=" " Size="9"></TD>
</TR>
<TR>
<TD>Interest Rate as % (e.g. 7.9):</TD>
<TD><INPUT Type="text" Name="Rate" value=" " Size="9"></TD>
</TR>
<TR>
<TD>Number of Years:</TD>
<TD><INPUT Type="text" Name="Years" value=" " Size="9"></TD>
</TR>
JS Code – page 14
(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved. 50
<TR>
<TD>Monthly Payment:</TD>
<TD><INPUT Type="text" Name="Payment" value=" " Size="12"></TD>
</TR>
<TR>
<TD><INPUT Type="Button" value="Calculate" onclick="Calc(MortCalc)">
<INPUT Type="Reset"></TD>
</TR>
</TABLE>
</FORM>
</CENTER>
<HR>
<BR>
<BR>
</BODY>
</HTML>
JS Code – page 15
51(c) Dr. Bernie Domanski, 1999-2000. All Rights Reserved.
SummarySummarySummarySummary
• Tried to just scratch the surface Tried to just scratch the surface on these languages.on these languages.
• A lot to absorb!A lot to absorb!• Hope your interest has been Hope your interest has been
stimulated!stimulated!• Any questions??Any questions??• Enjoy CMG99 !!Enjoy CMG99 !!• [email protected]@superlink.net• http://http://domanskidomanski..cscs..csicsi..cunycuny..eduedu//