CptS 122 – Data Structures                                                                        

 

Lab 1: Review of Problem Solving with C and Introduction to Microsoft Visual Studio 2008

 

Assigned: Week of August 27, 2012

Due: At the end of the lab session

 

I. Learner Objectives:

 

At the conclusion of this programming assignment, participants should be able to:

 

II. Prerequisites:

 

Before starting this programming assignment, participants should be able to:

 

III. Overview & Requirements:

 

Welcome to CptS 122 – Data Structures’ first lab! Labs are constructed to be hands-on. So be ready to get your hands dirty!

 

This lab, along with your TA, will help you navigate through Microsoft Visual Studio 2008 Integrated Development Environment (IDE). You will learn how to setup a console application. You will take advantage of the text editor, compiler, linker, and loader that is built into Visual Studio to construct, execute, and test small C programs that solve basic mathematical problems.

 

Labs are held in a “closed” environment such that you may ask your TA questions. Please use your TAs knowledge to your advantage. You are required to move at the pace set forth by your TA. Please help other students in need when you are finished with a task. You may work in pairs if you wish. However, I encourage you to compose your own solution to each problem. Have a great time! Labs are a vital part to your education in CptS 122 so work diligently.

Task 1: Develop a small hello world program utilizing the Visual Studio development environment. All of the applications that we will build in this class will be Console applications. Console applications run in a command window, and have purely textual input and output.

Perform the following steps to build a Console application:

  1. Create a folder in your Z: drive, for this class, named cpts122.  This is where all programs that you create for this class will be saved.
  2. From the start menu select programs, Microsoft Visual Studio 2008 --> Microsoft Visual Studio 2008 (or equivalently click on the Microsoft Visual Studio 2008 icon on the desktop if one exists).  This will start the visual studio integrated development environment (IDE). The IDE start page is shown below. 

       

From the File menu select New and then Project. This will bring up the New Project window shown below.

       

In this window, select Visual C++ Projects on the left and then select Win32 Console Application on the right. (See the gray shaded entries above). Next, give the project a name. A naming scheme will make it easier to find different solutions and projects later. At this time, name this project “Lab1Task1”. You also need to enter the Location; it should be “Z:\cpts122”. You can use the Browse button or type it in directly. When these are correctly completed, click the OK button.

You should now see the Win32 Application Wizard Window shown below, in that window click on the Application Settings Tab.

       

You will see the Wizard window change to provide several choices. Select the Console application (should be the default Application type already) and Empty project as shown in the screen image below. Then click the Finish button.

       

The IDE Window will change a little bit now. There is now information on the left hand side of the window in the Solution Explorer. 

       

You can close the Start Page window if you want by clicking on the x in the start window.

You now need to create a new file for your program. Do this by right clicking on the Source Files folder in the Solution Explorer, in the Visual Studio IDE, and selecting Add --> New Item. Give your file a name in the filename text field. Name the file MyHello.c. Make sure that you give your file the .c extension indicating that you would like the C compiler to be invoked once you compile your program. If you do not use the .c extension, the source file will default to a .cpp extension. This will cause the C++ compiler to be invoked. Next click Add.

       

When you select Add, you will see a file edit window come up inside the IDE with the name MyHello.c. You can enter your Hello World program here. 

Make sure that for every program that you write, you have the following comment header block at the beginning of your source code file:

/*******************************************************************************************

* Programmer: Your Name                                                                         *

* Class: Cpt S 122, Fall 2012; Lab Section X                                              *

* Programming Assignment: Lab1Task1                                                        *

* Date: August 27, 2012                                                                            *

* Description: This program prints out a simple "hello world" message.          *

*******************************************************************************************/

For this first program you will only need one executable C statement to output a message. Your program should output "Hello World, I am in CptS 122!" with a printf ( ) statement. 

Once you have entered the code for your simple hello world program you will build it from the Solution Explorer. Place the mouse pointer over Lab1Task1 in the solution explorer. Right click and choose Build. If you correctly entered the program source code you should see a "Build succeeded" message in the Build Window. If you had an error you will have a failed message in the Build window and a fatal error in the Task List Window. Correct your mistakes and try again.

To run your program when it has successfully built, hit Ctrl-F5 or run it from the Debug tab in the IDE.

Life does not get much better than the joy experienced once you see the window below! 

       

When you have successfully ran your hello world program, show your TA. Once you have completed this you may close this workspace under the file menu. Close this solution and create a new one for the next task. You should be able to move on to the rest of tasks when your TA instructs you to do so! 

Task 2: Design, implement, compile, and test C solutions to the following problems. Once you have completed a problem, demonstrate your solution to your TA.

a) Write a function that recursively reverses a string. Recall, a recursive function is a function that calls itself. These functions have at least one base or simple case and at least one recursive step. The base case(s) have known solutions. As the function is called, the problem is broken down into simpler parts that are closer to the base case.

b) Write a function that integrates or merges two unsorted strings into sorted order. You will need to provide multiple solutions.

    i) Solution 1: Merge items into a third, fixed-sized array.

    ii) Solution 2: Merge items into a third, dynamically allocated array, which grows as each item is inserted.

    iii) Solution 3: Merge items without the use of a third array.

c) Write a program which reads characters from a file and determines the number of each character, and the line of which each one is found, in the file. Assume the file consists of alphabetic characters only. You may NOT use if statements to “count” each character.


IV. Submitting Labs:

 

V. Grading Guidelines: