CS 14 - Lab 1

In this lab you will learn the basics that are necessary to complete and electronically submit assignments in this class. Many of you already know most of this material, but it will be a good review. You will practice basic MS-Windows commands, then write and submit a short C++ program.

You should perform and understand the following tasks before leaving this lab. Be sure to ask the TA if you have any questions. There is also a very good web page made by another instructor called "The Basics" which can answer many questions you might have. Click here to view it.

  1. Make sure the computer is booted to MS-Windows and log in. (Your TA will give you your class account).
  2. Perform basic operations in Windows:
    1. Create folders (directories).
    2. Rename files or folders.
    3. Move/Copy files or folders within your account.
    4. Delete files or folders. This is important because before submitting an assignment electronically, you are required to delete all unnecessary files from the submitted folder. Failure to do so will result in points being marked off. You should only submit the files you actually wrote (.cpp files).
  3. Send e-mail. This is important if you need to contact the instructor or TA outside of class.
  4. Use Visual C++ to write, compile, and run a program.
  5. Electronically submit your program.

In order to get the points for this lab, you must demonstrate to the TA that you have performed the tasks listed above. Specifically, you must:

  1. Send your TA e-mail (during your lab time) containing the following information: Name, SSN, login, and lab section number.
  2. Create a folder called lab1. The C++ program you will write and submit (in the next two steps) should be stored in this folder.
  3. Write a simple C++ program that prompts the user to enter up to 50 positive floating point values, then sorts the values (using a bubble sort) and prints them out in ascending order with each value rounded to 2 decimal places. See below for more specific information about this program. Run the program in front of the TA.
  4. Electronically submit your program in the lab1 folder. Click here to go to the electronic submission web page and click on the WWWTurnin link. Make sure the folder you submit contains only your .cpp file. Once you have performed the submit and you see the "Successful Turn In" message, make sure your .cpp file is listed. Simply seeing "Successful Turn In" is not enough. It can be a lie! Make sure your .cpp file is listed underneath. If it is not, your .cpp file is not within the folder you submitted. Show the TA the "Successful Turn In" message.

The Bubble Sort Program

Use an array of size 50 to hold the numbers the user enters. However, do not force the user to enter in 50 values. Allow him/her to stop at any time by entering 0 or a negative value. You should also make sure the user can not enter more than 50 numbers. As the numbers are entered, store them into the array.

Once the numbers have been entered, sort the array using the bubblesort algorithm:

   Variables Used:
      A: the array of values
      size: the number of values in the array
      i: an index into the array
      sorted: flag to indicate if the array is sorted or not

   Step 1: Set sorted to true
   Step 2: Loop from i = 0 to size - 1
   Step 3:    If A[ i ] > A[ i + 1 ] Then
   Step 4:       Swap the values in A[ i ] and A[ i + 1 ]
   Step 5:       Set sorted to false
   Step 6:    End If
   Step 7: End loop
   Step 8: If sorted is false then goto Step 1
Note that even though the above algorithm contains a goto, you must not use the C++ goto statement in your program. (Use a loop instead, such as a do/while.) Also, the size variables is the number of values the user entered, which will most likely be different than the size of the array (50).

Following is a sample run of the program:

This program will allow you to enter up to 50 numbers, then sort and print
the numbers in ascending order.

Please enter a positive number (or 0 to quit): 75.5
Please enter a positive number (or 0 to quit): 24.5
Please enter a positive number (or 0 to quit): 50
Please enter a positive number (or 0 to quit): 10
Please enter a positive number (or 0 to quit): -2

The numbers in ascending order are:
10.00
24.50
50.00
75.50