Language and IDE - CS351 Main Page

advertisement
All 300/400 Level CS Major Courses
• Tutoring
http://cs.ua.edu/undergraduate/tutoring/
• Location: SEC 3433
• Sign up or walk-in
Introduction
2-1
Language and IDE
• C++/CLI language and .NET framework
• Examples in Microsoft Visual Studio 2012
Compiled Languages
hello.cpp
(high level)
Compiler
(Including
Linker)
hello.exe
(machine)
hello.exe
Executor
Result
Interpreted Languages
hello.bas
Interpreter
Result
Hybrid Compiler-Interpreter
Source code
Compiler
Intermediate language code
Interpreter
Result
C++/CLI
C++/CLI
Source Code
C++/CLI
compiler
CIL Bytecode
CIL = C++ Intermediate Language
CLR
Result
CLR = Common Language Runtime
This applies to C# and VB .NET too.
About C++\CLI
• C++ (.h, .cpp, complied)
• C++/CLI (compiled to MSIL (Microsoft
Intermediate Language), not machine code)(not
interpreted at runtime)
• C++ vs. C++/CLI
– Unmanaged code vs. managed code
• Managed code: memory management, code access
security, multi-language integration
– Garbage collection
.NET
– Application development technologies
– .NET base class library
– Common Language Runtime (above OS)
.NET Advantages
• Language natural … MSIL
– Many non-MS languages can use base class library
– Common Type System (CTS)
– Common Language Specification (CLS)
• Minimum subset of CTS for all the .NET compatible
languages
• Platform independent … CLR
– Port .NET Framework to non-Windows platform w/o
recompiling
– JIT: Just-In-Time Compilation
– A JIT compiler translates bytecode into the native machine
language.
IDE (Integrated development
environment)
• Microsoft Visual Studio for C++
Obtain Microsoft Visual Studio 2012
(either Professional, or Ultimate)
Visual Studio 2012 only:
• any student at UA at no cost.
• http://oit.ua.edu/oit/services/softwarelicensing/dreamspark-standard/ and scroll to
the very end (click on the “WebStore” link
in “Obtaining Software”
Obtain Windows,
Microsoft Visual Studio 2012
(either Professional, or Ultimate)
OIT resources for licensed copies
• access software through DreamSpark
– STEM departments: DreamSpark Premium
• http://oit.ua.edu/oit/services/software-licensing/dreamspark-standard/
• https://www.dreamspark.com/Institution/Subscription.aspx
• No cost to eligible students
• Get help:
– OIT service desk
– CS : Jeremy LaGrone, jlagrone at cs ua edu
Examples
• How to use Microsoft Visual Studio 2012
• Assignment: within next two weeks
– Download and install Microsoft Visual Studio
2012.
– If needed, Windows as well.
– Use Visual Studio to create a project of CLR
Console Application after this class
• Can use your current or later assignments
• Create a CLR Console Application
– Start Microsoft Visual Studio 2012
– Create a new project by selecting from the menu bar
"FILE"-> "New"->"Project". In the "New Project"
dialog box, select "Visual C++" under "Installed
Templates" and select "CLR Console Application" as
the project template. Enter C:\CS351\Projects (or any
directory designated for keeping your CS351 projects)
in the "Location" field, and First (or any project name)
in the "Name" filed. It is better to uncheck "Create
directory for solution".
– Add code to the project.
– Build.
– Execute.
backups
Examples
• Quadratic Equation: ax2+bx+c=0
• Discriminant: ∆=b2-4ac
 b  b  4ac
• Two roots: x1=
2a
2
x2=
 b  b 2  4ac
2a
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
// Quadratic.cpp : main project file.
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
double a, b, c;
Console::Write(L"Enter the quadratic coefficiet(a): ");
a = Double::Parse(Console::ReadLine());
Console::Write(L"Enter the linear coefficnet(b): ");
b = Double::Parse(Console::ReadLine());
Console::Write(L"Enter the constant term(c): ");
c = Double::Parse(Console::ReadLine());
double discriminant;
discriminant = b*b-4*a*c;
double x1 = (-b+Math::Sqrt(discriminant))/(2*a);
double x2 = (-b-Math::Sqrt(discriminant))/(2*a);
Console::WriteLine(L"Two roots are " + x1 + " and " + x2);
return 0;
}
Play with code
• 1. Console application
– Output more
– Read so to pause
• Console::Write(L"Enter the constant term(terminate): ");
• Int c = Double::Parse(Console::ReadLine());
•
Console::Write(L"Verify");
•
Boolean y = Double::Parse(Console::ReadLine());
• 2. Windows Form Application
– Use different form name
Download