CSE 333 21wi Exercise 0

Out: Monday, January 4, 2021
Due: Friday, January 8, 2021 by 10:00 am.

A typo on my part has resulted in repositories having names csea333-21wi-xyzzy, rather than what's indicated below. Note the 'a' before '333'. Sorry.

git Setup

A repository named cse333-21wi-xyzzy has been set up for your use in CSE 333, where xyzzy is your CSE login. (For example, my repository is cse333-21wi-zahorjan.) We use your repository to distribute code to you, as in this exercise, and may use it as a way for you to submit your code. If you haven't already set up git access to CSE Gitlab, you should go through setup now. You can use the CSE GitLab web interface to browse your files and find out information about your repository, but you must clone a copy of your repository to do your work. (Hint: In the Gitlab web interface for your repository there is a little "clone" button in the top right corner. Click on it and find the string labeled "ssl". Make a copy of the long git@gitlab... string and use that in a git clone [string you copied] command to save some typing.)

A directory named cse333-21wi-xyzzy will have been created. cd into it. You'll find an ex00 directory containing an ex00.c file. You should complete the implementation of the problem described next by modifying ex00.c. (There are comments steering you the parts that need to be filled in.) There is also a bin directory containing two style checking ptyhon scripts, clint.py and cpplint.py. Your should run the former against all your C programs for this course before turning them in, and the latter against all your C++ programs. If they complain about anything, it would be worth the time to edit your code so that they stop complaining.

Finally, to make it easier to invoke the python scripts, you should add the .../cse333-21wi-xyzzy/bin/ directory to your PATH environment variable. The script .../bin/setpath.sh will do it for you, assuming you use bash as your shell and invoke the script from the directory in which it lives (i.e., as "$ ./setpath.sh"). To either avoid or enhance confusion, depending on how you look at it, setpath.sh invokes a new bash process, so you'll definitely be in bash after you run it. (If you don't use bash, we're guessing you know how to set PATH in your shell.)

One Time Setup for gcc 9 on Allen School Centos Linux machines

We're assuming that you will be using the Allen School Centos Linux machines, either via remote login or via the CSE Home Virtual Machine, for your work. In fact, we assume that the most common setup will be running VSCode on whatever machine you have and using it to edit/build your code on attu.cs. You can do your work with other tools, but our instructions will probably assume the VSCode/attu setup and, worse, our definition of "correct code" is "correct when running on attu" since we will be grading there.

The lab Centos systems have both gcc/g++ versions 8 and 9 installed. To see which version you get by default, you can run the command

$ gcc -v
(The dollar sign indicates whatever your shell prompt is, so isn't something you type.) If the output indicates version 9, you're done. Otherwise, enter the command
$ touch ~/.gcc9
(The character before the slash is a tilde, not a minus sign.) That creates an empty, hidden file in your home directory, and that causes gcc/g++ to invoke version 9. After creating that indicator file, you must log out and log back in before it takes effect. Run the command gcc -v to verify the version being invoked.

If this process doesn't work for you, well it isn't a crisis as gcc 8 is fine for this exercise (but isn't later in the course). You'll want to move to gcc/g++ 9 soon, so please post on the discussion board or send mail to the staff list if the procedure above fails for you.

ex00 Problem Description

One way to approximate π is to partially evaluate the following infinite series, which was discovered by Nilakantha in the 15th century:

      π = 3 + (4 / (2 x 3 x 4)) - (4 / (4 x 5 x 6)) + (4 / (6 x 7 x 8)) - ...

Breaking the series down:

Write a C program that:

Your program should be contained in a single source file named ex00.c. It should build as shown below, and produce the output shown below when invoked as shown:
    bash$ gcc -Wall -g -std=c17 -o ex00 ex00.c
    bash$ ./ex00 100
    Our estimate of Pi is 3.14159241097198238535
    bash$

You should use C's double type for the floating-point arithmetic. Different floating-point types or adding up the terms in the series in an order different from left-to-right might yield different results. The point of this exercise, however, is to create and run a simple C program, not to explore the nuances of floating-point arithmetic, so please use the double datatype, which will be adequate for our purposes and will produce the expected results, and your program output should match the example.

Your code must:

Turn-in

When done, we expect you'll submit your code using gradescope, but that might change (so check the announcements section on the home page just before submitting!). To submit file(s) using Gradescope, simply select the course, select the assignment, and drag the file(s) to the indicated place.)

You should have received an email message from Gradescope with your login information. Your userid is your @uw.edu email address. If your gradescope account is not set up properly, please send email to the cse333-staff[at]cs address so we can fix the problem.

A note on C Documentation

As part of this exercise you will need to explore some of the basic C libraries and conventions in order to access the command line argument (the string of digit characters), convert that digit string to a binary int value, and print the result. The course Resources page contains a link to www.cplusplus.com/reference, which is a good source for information about the C and C++ libraries (ignore the C++ information for now). In particular, you will find it useful to look at the stdio.h library for basic input and output, string.h for handling C strings (null-terminated arrays of characters), and stdlib.h for some useful functions, include parsing (converting) strings of digit characters to int values (there are multiple ways to do this later task, including sscanf, atoi, and others -- think about the tradeoffs and differences between them).