A03 - C++ and Make
Assignment: GitHub Classroom
Late Policy
- You have until the assigned due date, after that you will receive 0 points.
Assignment A02: C++ and Make (25 points)
Overview
In this assignment, students will extend their previous Monte Carlo implementation for calculating π (pi.cc
) to create a new program autopi.cc
. This new program will automatically calculate π to 1, 2, 3, 4, 5, 6, 7, and 8 significant digits. Students will measure the computational effort (iterations and time) required for each level of precision and output this data to a file. Additionally, students will write a Python script to parse the output file and generate a plot following best practices for data visualization.
Students will also build a Makefile
for the new program that compiles the code into an executable named autopi
and includes a make clean
target.
Objective and Expected Learning Outcomes
The primary objectives of this assignment are:
- Automate the Monte Carlo method for calculating π to different levels of precision.
- Measure and analyze the computational effort required for increasing precision.
- Visualize the relationship between precision and computational effort using a Python-generated plot.
Outcomes:
-
Enhanced Programming Skills in C++:
- Modify and extend existing C++ code to add automated calculations and data output.
-
Makefile Proficiency:
- Write a
Makefile
from scratch to manage the build process for the updated program.
- Write a
-
Performance Measurement:
- Implement time tracking in C++ to measure computation time for different levels of precision.
- Save iteration counts and timing data to a file for analysis.
-
Data Visualization with Python:
- Write a Python script to read the output file and generate a plot illustrating the relationship between significant digits and computational effort.
-
Best Practices for Coding and Visualization:
- Follow clean coding standards in both C++ and Python.
- Adhere to principles of effective data visualization, including labeling, scaling, and formatting.
Instructions
Part 1: Extending the C++ Program
-
Edit file named
autopi.cc
by copying your previouspi.cc
implementation. - Modify
autopi.cc
to:- Automatically calculate π to 1 through 8 significant digits.
- For each level of precision:
- Record the number of iterations required to achieve the precision.
- Measure the time taken for the computation using
std::chrono
.
- Output the results in the following format to a file named
autopi.csv
:Precision, Iterations, Time, Pi 1, <iterations>, <time>, <value of pi calculated> 2, <iterations>, <time>, <value of pi calculated> ... 8, <iterations>, <time>, <value of pi calculated>
- Include proper error handling and comments in your code.
Part 2: Makefile
- Create a
Makefile
to:- Compile
autopi.cc
into an executable namedautopi
. - Include a
make clean
target to remove build artifacts and executables.
- Compile
- Test the
Makefile
on the UIC CS resources (systems{1-4}.cs.uic.edu
) to ensure it works correctly.
Part 3: Python Visualization
- Write a Python script
autopiPlot.py
to:- Read
autopi.csv
. - Generate a plot with:
- x-axis: Significant Digits (1 to 8)
- y-axis: Computational Effort (iterations and time on separate plots or a dual-axis plot).
- Proper labels, legends, titles, and gridlines.
- Save the plot as
autopi.png
(dual-axis plot) orautopi00.png
andautopi01.png
(separate plots).
- Read
- Follow best practices for graphing:
- Use clear, descriptive labels.
- Ensure the plot is readable and well-formatted.
Submission Guidelines and Evaluation Criteria
- Add and/or edit the following files to your GitHub repository:
autopi.cc
Makefile
-
autopi.csv
(sample run with results for all 8 significant digits) autopiPlot.py
-
autopi.png
(generated by your script)
- Include a short reflective statement in
autopi.txt
, summarize the challenges faced and lessons learned in this assignment. - When your program is ready for grading, commit and push your local repository to the remote git classroom repository and follow the Assignment Submission Instructions.
- You will be evaluated on your ability to follow instructions, correctly name files, quality and completeness of code, and reflection on the assignment.