Download presentation
Presentation is loading. Please wait.
Published byVictor Perkins Modified over 9 years ago
1
Joe Hummel, PhD Dept of Mathematics and Computer Science Lake Forest College hummel@lakeforest.edu hummel@lakeforest.edu Lecture 2: Working with Visual Studio 2005
2
2-2 2. Working with VS 2005 2.1 Intro to Visual Studio What is Visual Studio 2005?
3
2-3 2. Working with VS 2005 Visual Studio Microsoft’s IDE A single IDE for all.NET development –For every.NET language –For every application type –Powerful, professional tool –http://msdn.microsoft.com/vstudio/http://msdn.microsoft.com/vstudio/
4
2-4 2. Working with VS 2005 Editions of Visual Studio Express : free IDE, one for each language / platform Standard : base line IDE (one for all languages and platforms) Professional : adds SQL Server Express for database access –this is the edition you get with MSDN Academic Alliance Team Editions Software engineering editions: Architect, Developer, Tester Include class designer, integrated testing & coverage tools, etc. Team Suite All 3 software engineering editions in one package Trial version available from MSDNAA Team Foundation Server The server-side component for the team editions / suite Source code control, process management, task/bug lists, reporting, etc. Built-in support for two processes: Agile and Waterfall
5
2-5 2. Working with VS 2005 2.2 Working with Visual Studio Let's work though an example…
6
2-6 2. Working with VS 2005 Example Let’s work through an example… Console-based application to process US Census data –Students build an application to mine real Census data –A Nifty assignment from SIGCSE 2005
7
2-7 2. Working with VS 2005 (1) Create a New Project…
8
2-8 2. Working with VS 2005 (2) Select Project Type… Here you pick language & type of application to build…
9
2-9 2. Working with VS 2005 (3) Code… Write code in the Code window (duh :-) –Use Solution Explorer for navigating between program files –A window isn’t visible? Make visible via View menu… Code window Solution Explorer
10
2-10 2. Working with VS 2005 (4) Run… I’m a huge fan of incremental development Press F5 at any time to build and run –Beware of “console flash”, manually keep console window open… namespace CensusDataApplication { class Program { static void Main(string[] args) { // keep console window open System.Console.Read(); } namespace CensusDataApplication { class Program { static void Main(string[] args) { // keep console window open System.Console.Read(); }
11
2-11 2. Working with VS 2005 (5) Visual Studio Modes VS operates in one of three modes: –Design, Running, or Debugging –If students can’t edit their code, they are probably still running!
12
2-12 2. Working with VS 2005 (6) The Census Data Application Here’s the program design: 1 * census.txt SMITH 1.006 1.006 1 JOHNSON 0.810 1.816 2.
13
2-13 2. Working with VS 2005 ReadCensusData Reads input file & returns collection of FamilyName objects: static ArrayList ReadCensusData(string filename) { string line, name; double freq; int rank; string[] tokens; char[] separators = { ' ' }; ArrayList names = new ArrayList(); // collection StreamReader reader = new StreamReader(filename); // open input file: line = reader.ReadLine(); while (line != null) // for each line, parse & create FamilyName: { // break line into 4 tokens: name, freq, cumulativeFreq, rank: tokens = line.Split(separators, StringSplitOptions.RemoveEmptyEntries); name = tokens[0]; freq = System.Convert.ToDouble(tokens[1]); rank = System.Convert.ToInt32(tokens[3]); names.Add( new FamilyName(name, freq, rank) ); line = reader.ReadLine(); } reader.Close(); // close file return names; // return collection! } static ArrayList ReadCensusData(string filename) { string line, name; double freq; int rank; string[] tokens; char[] separators = { ' ' }; ArrayList names = new ArrayList(); // collection StreamReader reader = new StreamReader(filename); // open input file: line = reader.ReadLine(); while (line != null) // for each line, parse & create FamilyName: { // break line into 4 tokens: name, freq, cumulativeFreq, rank: tokens = line.Split(separators, StringSplitOptions.RemoveEmptyEntries); name = tokens[0]; freq = System.Convert.ToDouble(tokens[1]); rank = System.Convert.ToInt32(tokens[3]); names.Add( new FamilyName(name, freq, rank) ); line = reader.ReadLine(); } reader.Close(); // close file return names; // return collection! }
14
2-14 2. Working with VS 2005 Main Program starts by reading input & outputting top 5 names: –input file should be placed in project's bin\Debug sub-folder static void Main(string[] args) { string username, s, filename; ArrayList namesCollection; FamilyName nameObj; System.Console.WriteLine("** Welcome to US Census Bureau Data Mining Program **"); // assume input file is in same directory as.EXE: filename = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "census.txt"); namesCollection = ReadCensusData(filename); System.Console.WriteLine(">>1990 Census data contains a total of " + namesCollection.Count + " family names<<"); // // output top 5 family names in the census data: // System.Console.WriteLine(">>Top 5 Family Names in the 1990 US Census<<"); for (int i = 0; i < 5; i++) { nameObj = (FamilyName) namesCollection[i]; s = string.Format("{0}. {1}", i+1, nameObj.Name); System.Console.WriteLine(s); } static void Main(string[] args) { string username, s, filename; ArrayList namesCollection; FamilyName nameObj; System.Console.WriteLine("** Welcome to US Census Bureau Data Mining Program **"); // assume input file is in same directory as.EXE: filename = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "census.txt"); namesCollection = ReadCensusData(filename); System.Console.WriteLine(">>1990 Census data contains a total of " + namesCollection.Count + " family names<<"); // // output top 5 family names in the census data: // System.Console.WriteLine(">>Top 5 Family Names in the 1990 US Census<<"); for (int i = 0; i < 5; i++) { nameObj = (FamilyName) namesCollection[i]; s = string.Format("{0}. {1}", i+1, nameObj.Name); System.Console.WriteLine(s); }
15
2-15 2. Working with VS 2005 Main (cont'd) Then we allow the user to search for a name: // // now let user search for names they are interested in... // System.Console.Write("Please enter a name you are interested in: "); username = System.Console.ReadLine(); while (!username.Equals("")) { username = username.ToUpper(); // Census data is in UPPER case // search through collection... int index; for (index = 0; index < namesCollection.Count; index++) { nameObj = (FamilyName) namesCollection[index]; if (nameObj.Name.Equals(username)) break; } // did we find matching family name? if (index == namesCollection.Count) // not found System.Console.WriteLine("Sorry, that name does not appear in the census data."); else System.Console.WriteLine(namesCollection[index].ToString()); System.Console.Write("Please enter a name you are interested in: "); username = System.Console.ReadLine(); } // // now let user search for names they are interested in... // System.Console.Write("Please enter a name you are interested in: "); username = System.Console.ReadLine(); while (!username.Equals("")) { username = username.ToUpper(); // Census data is in UPPER case // search through collection... int index; for (index = 0; index < namesCollection.Count; index++) { nameObj = (FamilyName) namesCollection[index]; if (nameObj.Name.Equals(username)) break; } // did we find matching family name? if (index == namesCollection.Count) // not found System.Console.WriteLine("Sorry, that name does not appear in the census data."); else System.Console.WriteLine(namesCollection[index].ToString()); System.Console.Write("Please enter a name you are interested in: "); username = System.Console.ReadLine(); }
16
2-16 2. Working with VS 2005 FamilyName Class Here's a very simple design for the FamilyName class: –we'll come back and improve this design in the next lecture… public class FamilyName { public string Name; public double RawPercentFreq; public int Rank; public FamilyName(string name, double percentFrequency, int rank) { this.Name = name; this.RawPercentageFreq = percentFrequency; this.Rank = rank; } public override string ToString() { string s; s = string.Format("{0}. {1}: {2} ({3}%)", this.Rank, this.Name, this.GetFormattedPercentageFrequency(), this.RawPercentageFreq); return s; } public string GetFormattedPercentageFrequency() {... } }//class public class FamilyName { public string Name; public double RawPercentFreq; public int Rank; public FamilyName(string name, double percentFrequency, int rank) { this.Name = name; this.RawPercentageFreq = percentFrequency; this.Rank = rank; } public override string ToString() { string s; s = string.Format("{0}. {1}: {2} ({3}%)", this.Rank, this.Name, this.GetFormattedPercentageFrequency(), this.RawPercentageFreq); return s; } public string GetFormattedPercentageFrequency() {... } }//class
17
2-17 2. Working with VS 2005 2.3 Features of Visual Studio IntelliSense Other helpful features File system layout
18
2-18 2. Working with VS 2005 IntelliSense IntelliSense is a fantastic advance –context-sensitive programming aid –reduces programming errors –encourages experimentation and exploration // Keep console window open until user is done… System.
19
2-19 2. Working with VS 2005 Other HelpFul Features Compilation errors are underlined like spelling mistakes Debugger –set breakpoints in margin, run, single-step — use as a teaching tool! Toolbar buttons: –indent / outdent –comment in / out View menu: –Class view
20
2-20 2. Working with VS 2005 Visual Studio File System Layout As a professional tool, VS produces lots of files: –solution (.sln) represents your program solution double-click on.SLN file to open an existing program in VS –project (.csproj) tracks source files, settings you have one project file for each compiled unit (.EXE,.DLL) –bin\Debug sub-directory contains.EXE & data files for example, this is where you put “census.txt”
21
2-21 2. Working with VS 2005 2.4 What's Next? Lab exercise #2…
22
2-22 2. Working with VS 2005
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.