0% found this document useful (0 votes)
11 views5 pages

2024 Fall A1

Assignement 1 comp sci 270

Uploaded by

xnyygrskkb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

2024 Fall A1

Assignement 1 comp sci 270

Uploaded by

xnyygrskkb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

CMPT 214: Programming Principles and Practice

Assignment 1

September 23, 2024

Due Date: September 23, 2024, 6:00 pm – late submissions will not be accepted
Total points: 100

Instructions
All source files (Makefile, .c, .sh, ...) should be bundled in a single tarball (named
‘a1.tar’)
Verify that your tar file is not corrupted (can happen sometimes when updating the contents
of an existing tarball in an incorrect manner) by extracting it (using ‘tar -xvf a1.tar’) in a
different directory and checking its contents before submitting. Do not submit binaries;
i.e. no ‘.o’ or executable object files of any kind. You should always run ‘make clean’
before running ‘tar’ to clean all binaries.
Your code must include comments describing what it does, and how. Code with syntax
errors will receive no credit.
You should always develop your solutions incrementally on Git and show your
progress as you are developing your solutions; i.e. you should commit every single
complete change you make as you work on your solution. You must submit a git.log which
is the output of git log showing your incremental progress.
To submit your work, you should upload your tar file to Canvas.

Git repository setup


We will start by creating a new a1 branch, branching out of the main branch, using the
following commands:
$ git switch main
$ git switch -c a1

1
Question 1 [60 points]
In this question, you are to write a C program that computes an approximation of π using
the Leibniz formula:

1 1 1 1 1
π = 4( − + − + − ...)
1 3 5 7 9

The above formula is what is known as an “infinite sum” formula. The idea is that we can
obtain the exact value, if add up an infinite number of terms. A realistic implementation
would only use a finite number of terms. The accuracy of the computed value depends on
the number of terms being added.
Your program should (eventually) start by reading an integer n from stdin using scanf().
You can then use the appropriate looping structure to compute the sum of the first n terms
of the above formula. To maximize accuracy, we will use a variable of type double to store
the sum. Once the sum is computed you must then display the approximate value of π using
printf() and the appropriate format characters.
To do this we will break this down into multiple stages so we can practice good design, and
git commit habits. It is important to submit each stage, even if you can develop the entire
solution already, as the assignment will assess your incremental work.

Create a skeleton
Create a file called pi.c this should contain a main function which reads the number of terms
to compute (it does not need to do anything with this yet). It should also compute the first
two terms (it does not need to use a looping structure, but should use variables to do the
computation). Lastly, have the program use printf() to output its (poor) approximation
of π.
As per “standard programming practice” discussed in class, you must also write a Makefile
to build your pi.c program into an executable object file named pi.
Once your pi.c can be built without errors by your Makefile: Create a copy of your pi.c
called pi-skeleton.c then git add all files created so far. Lastly, git commit your work.1
A git push wouldn’t be a bad idea either.
1
at this stage you my not know how to approach the next section, but you should be able to start on
some parts of Question 2, which is a good idea

2
Improve your skeleton
Continue to develop your pi towards the specification above by adding an appropriate loop.
You should also ensure your types are appropriate, and that your printf() output is correct.
As you complete improvements you should make incremental git commits which document
what you changed and why.
You have finished this stage when your pi program works as specified.

Question 2 [40 points]


To verify the correctness of the program in Question 1, we are going to use a BASH script
(pi-test.sh) to automate the test process. Note, this script does not need a fully working
version of Question 1, the skeleton version should be sufficient for you to develop your BASH
script.
In the script, you will run your program using different values for n and record the results
in a text file specified as a command-line argument. The values for n will be specified as
3 arguments, start value, end value, and increment. The start and end value should be
included in the range.
For example, for the command ./pi-test.sh pi.txt 10 10000 10, the correct implemen-
tation of the script should produce a pi.txt file having contents similar to the following:
10 3.041840
20 3.091624
30 3.108269
40 3.116597
...
9960 3.141492
9970 3.141492
9980 3.141492
9990 3.141493
10000 3.141493
As in question 1, in incremental approach is recommended, start with a version of the script
which ‘hardcodes’2 the arguments, then incrementally improve that by adding the flexibility
of accepting the output file, then the range parameters. Even though we are not asking for
these steps to be submitted, we should see evidence that they existed in your git.log.

2
‘hardcoding’ is where something that should be a parameter is fixed in the program code

3
Files to hand in
All source files must be on git. The following files are to be packaged into a tarball a1.tar
and submitted to canvas:
- Makefile
- git.log
- pi-skeleton.c
- pi.c
- pi-test.sh

You can generate the git.log file with the following command:

git log main..a1 > git.log

Your tarball should be flat (contain no subdirectories), and should not contain any files not
listed above. Remember the command to generate a tarball will be like the following:

tar -cvf a1.tar my file1 my file2 ...

Minimum Credible Submission


The following commands must work, without error,3 for your submission to be graded (i.e.
Write these into a terminal to test).

$- make
$ test -s git.log && echo “PASS” || echo “FAIL”
$ test -s pi.c && echo “PASS” || echo “FAIL”
$ test -s pi-test.sh && echo “PASS” || echo “FAIL”

All files, except those explicitally exempt, or used as command input, must include Name,
NSID, Student Number, and Course & section number at the top (i.e. before any other
content). These must have the following formats (Remove angle brackets and replace with
3
Where a command does not explicitly print a PASS/FAIL, the return value should be zero and there
should be no errors printed to the terminal.

4
your information). Note: due to how this document is formatted, you should not copy and
paste these blocks as the resulting text may lose formatting.
$• Bash
# !/ bin / bash
# Name : <Last , First >
# NSID : < abc123 >
# Student Number : <##### >
# Course : CMPT214 - <## > 2024

• C
/*
Name : <Last , First >
NSID : <abc123 >
Student Number : <##### >
Course : CMPT214 - <## > 2024
*/

• Makefile
# Name : <Last , First >
# NSID : < abc123 >
# Student Number : <##### >
# Course : CMPT214 - <## > 2024

You might also like