CSCI 159 Lab 2 exercises

Lab2 will consist of two parts:

You have two weeks to complete the lab, but there are no scheduled lab sessions during the second week (as VIU is closed on National Day for Truth and Reconciliation).

Hopefully most people complete all of the basic exercise and get started on the main exercise in this week's session, thus giving you two weeks to complete the main exercise on your own time (either using lab 102 during its open sessions or by connecting from home).

Here is the collection of new C++ syntax elements we'll be using for lab2.

Today we'll also experiment with a different editor, pluma
(if you're logging in from home with ssh, remember to use pico not pluma,
since pluma can't open an edit window on your laptop/desktop/notebook)


Refresher: logging in and setting up

  1. logging in

  2. opening the browser and today's lab page

  3. opening a terminal window

  4. using make159 to get lab2

  5. getting into lab2 and the edit/compile/test/submit cycle


New: getting feedback/marks from the previous lab(s)

  1. getting the feedback directory the first time

  2. updating the feedback directory (for later labs)

  3. seeing the feedback files


Part 1: the basics of this lab's C++ features (basic.cpp)

For the first part of today's lab exercise we're adding code to a program to experiment with some of of the more unusual behaviour and limitations of simple data types, while also learning to 'code to standards' as we go. Of course we'll get more practice with the edit/compile/test/submit cycle as we go.

We'll also try to create and call a function of our own: passing data to it, having it perform computation and return a result which our main routine can then use.

Go through the various steps, adding each to your basic.cpp main routine as you go.


Part 2: design and implementation exercise (lab2.cpp)

Now that we've practiced using each of our new C++ features, our objective is to design, write, test, and debug a more interesting program in our lab2.cpp file.

The program we'll be creating is going to get the user to provide a name and size for a container of some kind, and the program will compute estimates for how many marbles, ping pong balls, and tennis balls would probably fit in the container.

A typical run of the program might look something like
Welcome to HowManyFit! 
 
We estimate how many (small) marbles, ping pong balls, and tennis balls 
fit in a container whose size you specify. 
 
Please enter a name for the container (as a single word): carton 
Please enter the size of a(n) carton in litres (e.g. 4.6): 1.5 
 
A carton of size 1.5 litres holds 
 105.3 to  128.7 small marbles 
  27.7 to   33.8 ping pong balls 
   5.0 to    6.1 tennis balls 
 
Thanks for using HowManyFit! 

We'll base the computation on the following constant values:

The width of the numeric display columns is 6 characters (including the decimal point) and exactly one digit is to be displayed after the decimal point (as shown in the example above).

No error checking is required at this point, you can trust that the user will provide valid data. (When testing your submission for this lab I'll only use valid data.)

Your output doesn't have to look exactly like the output shown below, and the numbers certainly won't, but should provide a similar level of detail and functionality, and demonstrate both left- and right-justified columns.

Designing your solution

Take some time to come up with a design - figuring out what functions you want/need to write/call, what you want each of them to do, and how you want to structure your logic in the main routine.

Taking the time to come up with a good design will, in the long run, result in much cleaner and better organized code: code that is easier to write, understand, debug, and maintain.

Good design takes practice though. Don't worry if you have to significantly revise your original design a couple of times as you work through the coding practice: it's normal to recognize the need for some changes as you start getting deeper into the actual code.

If you're having trouble getting started, go to the lecture resources and check out the sections on design and modularity. There are also many good resources online to help new programmers learning to design.

I strongly recommend attempting your own design ideas for a few days first, but in case anyone is really stuck here is a link to a design example/process for a past lab2, and outline for this year's problem.

Standards and submission

Remember to put all your code for this part of the exercise in your lab2.cpp file in your lab2 directory, and submit it prior to the deadline using the "make submit" command.

As with the other lab exercises, you can 'make submit' as often as you like, it basically just copies your latest version to a place where I can access it.

Do remember that your code needs to follow the course code standards, and that it is most effective to code-to-standards as you go.