Overview
Welcome to 2nd Quarter! With the CPE now behind us, it's time for the promised flip in how we conduct class. Tests and quizzes are out, programs and presentations are in! We are moving from learning to read C++ programs to learning to write them.
Of the 31 students in our two sections of this class, 18 have now earned CPE certification, while 13 have not. Experience has taught me that it is very difficult, to write in a language you can't effectively read, and I will explain in class this week how I hope to mitigate this challenge to provide extra support for students still struggling to learn to effectively read C++.
Thursday, November 7th
Classwork
After briefly discussing the results of our CPE testing and how I plan to use the results to plan your learning journey during 2nd quarter, we will dive right in to writing C++ programs.
Writing C++ programs effectively will require you to have the skills that enable you to:
- manage and edit files from the unix command line.
- use git and Markdown to submit and share your work.
Today in class I will present a program I worked on over the break to choose random pairs of students for programming assignments. I'll use this opportunity to talk about iterative and incremental development and unit testing.
For my first iteration I knew the program would have to support choosing
between the two sections we have of this course: periods 1B and 4B. I decided
I wanted to store class lists for each section in a text file, and to be able
to read in two groups of students from each section depending on their CPE
status. I decided I wanted to choose the section on the command line, and that
the main
function should test for correct input and that the
needed file exists befor calling other functions to do the processing of
student pairs. Here is my first iteration of main
, which tests
for correct cli input:
#include <iostream> #include <fstream> #include <cstring> using namespace std; int main(int argc, char* argv[]) { if (argc != 2) { cerr << "Too few arguments: enter 1B or 4B for 2nd argument." << endl; return 1; } if (strcmp(argv[1], "1B") && strcmp(argv[1], "4B")) { cerr << "Second argument must be either 1B or 4B,"; cerr << " not " << argv[1] << '.' << endl; return 2; } cout << "You made it!" << endl; return 0; }
Now that the command line input is processed, for my next iteration I'll open the proper classlist file. Remove the last two lines of the code above and insert:
char filename[16]; strcpy(filename, "classlist"); strcat(filename, argv[1]); strcat(filename, ".dat"); ifstream infile(filename); if (!infile.is_open()) { cerr << "Error openning file " << filename << endl; return 3; } return 0;
Now it's time to process the input file data into a list of students from which random pairs can be chosen. I want to use a TDD approach for this, so I'll start with three files that compile successfully with a failing test:
That's as far as we'll get today. You'll have the rest of class and homework time to finish setting up a working unit testing development environment and learning how to use it.
Homework / Evaluation
First make sure you have a working unit testing development environment as we discussed in class. Spend your remaining homework time reviewing the skills you will need this quarter: using the unix cli to manage files and directories, editing text files with vim, and using git for revision control. a