Visual Studio .NET Academic Student Tools Guide Chapter 6
Visual Studio .NET Academic Student Tools Guide

CHAPTER 6
Samples

A group of nine samples are shipped with Microsoft Visual Studio .NET Academic. These samples range in difficulty from simple to complex. Samples are organized using the following classification system:

The following table shows the list of samples included with Visual Studio .NET Academic and their classification.

Sample Classification
Hello World Sample Simple
Tic-Tac-Toe Sample Simple
Diff Tool Sample Simple
Elementary Data Structures Sample Simple
Expression Parser Sample Intermediate
Sorting Sample Intermediate
Tile Puzzle Sample Advanced
Towers of Hanoi Sample Console version, Intermediate
Windows version, Advanced
Network Chat Sample Advanced

To access a specific sample

Hello World Sample

Demonstrates how to generate basic screen output and simply prints the phrase "Hello World". This sample is written in Visual C++, Visual C#, and Visual Basic. For an in-depth explanation of each line of code in the Visual C++ implementation of this sample, see Walkthrough: Creating a Console Application in Getting Started.

Building and Running the Sample

To build and run this sample

  1. Under Sample Files, click the Load Sample Solution link.

    The Browse For Folder dialog box appears.

  2. Browse to select a location for the sample files, and click OK.

    Select a location to which you have write access. The sample files are opened automatically in a new instance of Visual Studio .NET.

    The HelloWorld.sln file is opened in Solution Explorer.

  3. From the Build menu, choose Build Solution.

    The HelloWorld.sln file contains three separate projects-one project for each language implementation of the Hello World sample.

  4. To run the executable (.exe) file associated with each of the three projects, right-click the project name in Solution Explorer, choose Debug, and then choose Start New Instance.

    -or-

    Right-click the project name in Solution Explorer, choose Set as Startup Project, and then, from the Debug menu, choose Start Without Debugging.

Tic-Tac-Toe Sample

Demonstrates using two-dimensional arrays and prompting for user input in a game of Tic-Tac-Toe played between a user and the computer on a 3x3 game board. The sample is written in Visual C++. This sample uses standard C++ iostream classes to perform input and output in a console-mode application.

Program Logic

This program uses a simple algorithm for determining how the computer selects a move. First, the program determines whether there are any rows or columns that it can block. If it locates one of these spaces, then it places an "X" in the appropriate row or column. Failing this, the program places an "X" in the first open space.

The winner of the game is the first player to place three "X" or "O" symbols in a row. A tie is declared when the board is full and if no player is able to place three symbols in a row.

Building and Running the Sample

To build and run this sample

  1. Under Sample Files, click the Load Sample Solution link.

    The Browse For Folder dialog box appears.

  2. Browse to select a location for the sample files, and click OK.

    Select a location to which you have write access. The sample files are opened automatically in a new instance of Visual Studio .NET.

    The TicTacToe.sln file is opened in Solution Explorer.

  3. From the Build menu, choose Build.
  4. From the Debug menu, choose Start Without Debugging.
  5. Follow the program instructions to play the game.

Possible Improvements

There are several ways you can modify this sample to improve program logic or playability. The following are a few possible improvements for modifying the program:

Diff Tool Sample

Demonstrates how to handle file input and output. Specifically, this sample:

  1. Reads input from two text files.
  2. Compares each line of text in these files.
  3. Generates an output file that indicates which lines differ between input files.
  4. Provides a summary of the differences observed.

This sample demonstrates simple file differentiation and is intended as a sample reference on file input and output, not a reference on file differencing.

The text files input to and output from this sample are shown in the following table.

File Description Sample file
Filename1 Input
Base text file against which to compare.
Base.txt
Filename2 Input
Modified version of base text file.
Compareto.txt
Filename3 Output
Text file that indicates the differences between the first and second text files. This argument is optional. If not provided, then the output is printed to standard output.
User-specified name

This sample demonstrates the following:

The Diff Tool sample is written in Visual C++ using ANSI and using the iostream class libraries to perform console and file stream manipulations. This sample is designed to operate only on English-language ANSI text files. There is no support for UNICODE and MBCS (Multi-Byte Character Set) text files or binary files.

Program Logic

The Diff Tool sample works as follows:

  1. The program compares the first line in the Filename1 file to all of the lines in the Filename2 file.
  2. The program then compares the next line in the Filename1 to the lines following the last found line in Filename2. This check is repeated until all lines in Filename1 have been evaluated.
  3. After all lines in Filename1 have been compared to the lines in Filename2, all text beyond the last found line in Filename2 file is marked as added.

Implementation Notes and Limitations

Building and Running the Sample

To build and run this sample

  1. Under Sample Files, click the Load Sample Solution link.

    The Browse For Folder dialog box appears.

  2. Browse to select a location for the sample files, and click OK.

    Select a location to which you have write access. The sample files are opened automatically in a new instance of Visual Studio .NET.

    The StudentDiff.sln file is opened in Solution Explorer. This solution contains the source code for the application (StudentDiff.cpp), Base.txt, and Compareto.txt.

  3. From the Build menu, choose Build.
  4. In Solution Explorer, right-click the project name, and choose Properties.

    The Properties dialog box appears.

  5. Choose Debugging.
  6. In the Command Arguments text box type the following: base.txt compareto.txt
    Note  Specifying two command arguments prints output to the screen; specifying three command arguments prints output to a file. For example, in the Command Arguments text box, enter base.txt compareto.txt outputfile.txt.
  7. Click Apply, and click OK.
  8. From the Debug menu, choose Start Without Debugging.

Possible Improvements

There are several ways you can modify this sample to improve program logic. The following are a few possible improvements for modifying the program:

This sample includes a Readme.txt file in their respective directories. This file provides more information about the sample and suggested improvements.

Elementary Data Structures Sample

Demonstrates an implementation of queue and stack data structures. A queue is a first-in first-out (FIFO) buffer. In a queue, the first item added to the queue is also the first item removed. A stack is a last-in first-out (LIFO) buffer, where the last item added is the first item removed from the stack. In this sample, the "push" command adds that item to the stack, while the "pop" command removes an item from the stack. Similarly, the "enqueue" command adds an item to the queue, and "dequeue" removes an item from the queue. This sample is written in Visual C++ and using the iostream classes for console input and output.

Building and Running the Sample

To build and run this sample

  1. Under Sample Files, click the Load Sample Solution link.

    The Browse For Folder dialog box appears.

  2. Browse to select a location for the sample files, and click OK.

    Select a location to which you have write access. The sample files are opened automatically in a new instance of Visual Studio .NET.

    The ElementaryStructures.sln file is opened in Solution Explorer.

  3. From the Build menu, choose Build Solution.
  4. From the Debug menu, choose Start Without Debugging.
  5. Follow the program instructions.

Possible Improvements

There are several ways you can modify this sample to improve program logic. The following is one possible improvement for modifying the program:

This sample includes a Readme.txt file in their respective directories. This file provides more information about the sample and suggested improvements.

Expression Parser Sample

Demonstrates the following:

This sample is written in Visual C++ using Microsoft Foundation Classes (MFC). This sample is designed to operate only on English-language ANSI input strings. There is no support for UNICODE or MBCS (Multi-Byte Character Set) text input.

Building and Running the Sample

To build and run this sample

  1. Under Sample Files, click the Load Sample Solution link.

    The Browse For Folder dialog box appears.

  2. Browse to select a location for the sample files, and click OK.

    Select a location to which you have write access. The sample files are opened automatically in a new instance of Visual Studio .NET.

    The ExpressionParser.sln file is opened in Solution Explorer.

  3. From the Build menu, choose Build Solution.
  4. From the Debug menu, choose Start Without Debugging.
  5. In the Expression box, type ((a+b)*2), and click Parse.

    The expression tree is displayed on the screen.


    Note  Enclose the entire expression in parentheses.

Practice using this application with other expressions. The following expression operators are supported:

Possible Improvements

There are several ways you can modify this sample to improve program logic. The following are a few possible improvements for modifying the program:

This sample includes a Readme.txt file in their respective directories. This file provides more information about the sample and suggested improvements.

Sorting Sample

Graphically demonstrates the following sorting algorithms:

This sample is written in Visual C++ using the C interfaces to the Windows application programming model.

Building and Running the Sample

To build and run this sample

  1. Under Sample Files, click the Load Sample Solution link.

    The Browse For Folder dialog box appears.

  2. Browse to select a location for the sample files, and click OK.

    Select a location to which you have write access. The sample files are opened automatically in a new instance of Visual Studio .NET.

    The SortingDemonstration.sln file is opened in Solution Explorer.

  3. From the Build menu, choose Build Solution.
  4. From the Debug menu, choose Start Without Debugging.

    The Sorting Demonstration window appears.

  5. From the Sort menu, choose the type of sort you want to perform, Insertion Sort or Quick Sort.
  6. Click Step to step through the selected sort incrementally.

    -or-

    Click Auto Sort to run the entire sort through to completion.

Possible Improvements

There are several ways you can modify this sample to improve program logic. The following are a few possible improvements for modifying the program:

This sample includes a Readme.txt file in their respective directories. This file provides more information about the sample and suggested improvements.

Tile Puzzle Sample

This sample is shipped with the Managed Extension for Visual C++ sample set. For more information, see TilePuzzle Sample: Demonstrates Interoperability Between C# and Managed Extensions for C++ in the Microsoft MSDN Library.

Towers of Hanoi Sample

The Towers of Hanoi sample demonstrates a recursive algorithm for solving the Towers of Hanoi puzzle using a console application or a graphical application created using the .NET Framework Forms class libraries from Visual C#. This sample is divided into the following projects:

This sample is written in Microsoft Visual C# .NET.

Building and Running the Sample

To build and run this sample

  1. Under Sample Files, click the Load Sample Solution link.

    The Browse For Folder dialog box appears.

  2. Browse to select a location for the sample files, and click OK.

    Select a location to which you have write access. The sample files are opened automatically in a new instance of Microsoft Visual Studio .NET.

    The Hanoi.sln file is opened in Solution Explorer.

    The Hanoi solution contains a Microsoft Visual C++ .NET and a Visual C# .NET project for the two language implementations of this sample that are provided.

  3. From the Build menu, choose Build Solution.
  4. From the Debug menu, choose Start Without Debugging.
  5. To run the executable (.exe) file associated with the HanoiConsole and HanoiWindows projects, right-click the project name in Solution Explorer, and choose Set as Startup Project.
  6. From the Debug menu, choose Start Without Debugging.

HanoiConsole displays the output of a three-peg Towers of Hanoi solution in a console window. HanoiWindows makes it possible for you to solve the Towers of Hanoi puzzle through a graphical user interface.

Use the following instructions to play HanoiWindows:

Possible Improvements

There are several ways you can modify this sample to improve program logic or playability. The following a few possible improvements for modifying the program:

This sample includes a Readme.txt file in their respective directories. This file provides more information about the sample and suggested improvements.

Network Chat Sample

This sample is shipped with the .NET Framework SDK. For more information, see Wintalk Application Sample in the .NET Framework SDK.

Debugging Sample

Used in conjunction with the Walkthrough: Debugging a Sample Application topic in Working With Visual Studio .NET to guide you through using the debugger to find and resolve a bug in a simple application.

To build this sample

  1. Under Sample Files, click the Load Sample Solution link.

    The Browse For Folder dialog box appears.

  2. Browse to select a location for the sample files, and click OK.

    Select a location to which you have write access. The sample files are opened automatically in a new instance of Visual Studio .NET.

    The FahrenheitToCelsius.sln file is opened in Solution Explorer.

  3. From the Build menu, choose Build Solution.
  4. To run the sample, follow the instructions in Walkthrough: Debugging a Sample Application in Working With Visual Studio .NET.
 Return to Contents 

© 2001 Microsoft Corporation. All rights reserved. Terms of Use.