CS105: Introduction to Computer Programming: C++

Assignment #1: How Big is Big?


Tuesday, February 3rd at 11:59pm


This is a pretty simple getting-to-know-C++ assignment. You'll have to figure out how to use Linux machines, find an editor that you like, write several functions that test the maximum values that ints can hold, and compile and run your code.


These instructions assume that you're doing development on the CS department linux machines. I recommend using the CS department linux machines, but if you feel more comfortable using another development platform, that's fine. Eventually, you'll have to use the CS department machines to submit the assignment, but you can develop on any machine you're comfortable with. Just make sure to test your code on the department machines before turning it in!
  1. If you don't have a CS department account, you should request a new account.
  2. Log on to a CS department linux machine using your CS department login. Make sure you log into a Linux machine, not a Sun machine!
  3. Start up XWindows by typing
    If you're new to linux, you might want to get a friend to help you or come by office hours. Getting used to a new operating system can take some time.
  4. Open up a terminal window and make a new directory for this assignment called assignment1:
    mkdir assignment1
    And change to that directory:
    cd assignment1
    Now use your favorite text editor to make a new file called maxint.cc.
  5. Write some code inside maxint.cc that displays two numbers to the screen:
    1. The first number should be the biggest possible long int that can be stored on the current machine.
    2. The second number should be the biggest possible unsigned long int that can be stored on the current machine.

    The only thing that should be displayed are these two numbers, separated by whitespace. For example, running your code should produce something like this:

      computer% g++ -Wall -Werror maxint.cc -o maxint
      computer% ./maxint

    Of course, those probably aren't the right numbers to display.

    There are at least three different ways that you can compute these two numbers, any of which are fine. The only restriction is that your code should be more sophisticated than this:

      cout << 1024 << '\n' << 2048 << '\n';     // don't do this!

    Displaying a magic number might work on one machine, but it won't necessarily work on all machines. Good programmers strive for portable code.

    While you shouldn't return your own hard-coded constant, you should try to make this function as efficient as possible. Some methods for completing this assignment are significantly faster than others. How fast can you make your code?

  6. Compile and run your code:
    1. Make sure you're in the same directory as your maxint.cc file. If you type
      ls maxint.cc
      you should see the name of the file listed on the screen, along with anything else that happens to be in that directory.
    2. Compile your file with this command:
      g++ -Wall -Werror maxint.cc -o maxint
      If all goes well, you shouldn't see any error messages.
    3. Run your program by typing this command:
      Whatever you've included in your main function should run, and any output that is generated should appear on your screen.
  7. When you're happy with your code, use the turnin program to submit your maxint.cc file. Use assignment1 as the assignment name.

Submission Checklist

Too easy for you? Want more?

Extra Credit (+20%)

There are several different ways to do this assignment. You've already figured out one way to display the biggest number possible. For extra credit, try to figure out other ways to get the job done, and implement each of them as a separate function. Can you create functions that: