User Tools

Site Tools


lecture_materials:week_00

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lecture_materials:week_00 [2025-08-18 18:27] Jeffrey Bergaminilecture_materials:week_00 [2025-08-19 14:31] (current) Jeffrey Bergamini
Line 5: Line 5:
 </WRAP> </WRAP>
  
-<WRAP round tip> +===== Monday =====
-===== Slides =====+
  
 +{{ :lecture_materials:cabrillo_-_c_boot_camp_-_monday_session.pdf |Pascal Broca: Introduction and Overview}}
  
-</WRAP>+{{ :lecture_materials:monday_camp_development_cycle.pdf |Daria Malysheva: Software Development Cycle}} 
  
-===== Monday =====+===== Tuesday =====
  
-Forthcoming+==== Scope and Lifetime ====
  
-===== Tuesday =====+{{ :lecture_materials:blocks-scope-lifetime.pdf |Jeffrey Bergamini: Blocks, Scope and Lifetime}}
  
-==== scopes.cpp (illustrating locally and globally scoped variables) ====+=== scopes.cpp (illustrating locally and globally scoped variables) ===
  
 <file cpp scopes.cpp [enable_line_numbers=true]> <file cpp scopes.cpp [enable_line_numbers=true]>
Line 61: Line 61:
  
 <WRAP round info> <WRAP round info>
-=== Notes ===+== Notes ==
  
-Your job: Be the compiler and the OS and determine the output without using any tools but your mind!+Your job: Be the compiler and the shell and determine the output of this program without using any tools other than your mind!
  
 Then compile and run this code to see if you were right. Then compile and run this code to see if you were right.
 </WRAP> </WRAP>
  
-==== scopes_annotated.cpp (illustrating locally and globally scoped variables) ====+=== scopes_annotated.cpp (illustrating locally and globally scoped variables) ===
  
 <file cpp scopes_annotated.cpp [enable_line_numbers=true]> <file cpp scopes_annotated.cpp [enable_line_numbers=true]>
Line 112: Line 112:
  
 <WRAP round info> <WRAP round info>
-=== Notes ===+== Notes ==
  
 This is the same program, but prints the **memory address** of each variable in question. Note which ''x'' variables are at the same address, i.e. are literally the same integer object. This is the same program, but prints the **memory address** of each variable in question. Note which ''x'' variables are at the same address, i.e. are literally the same integer object.
 </WRAP> </WRAP>
  
-==== raii.cpp (illustrating the concept of RAII) ====+=== raii.cpp (illustrating the concept of RAII) ===
  
-<file cpp scopes_annotated.cpp [enable_line_numbers=true]>+<file cpp raii.cpp [enable_line_numbers=true]>
 /** /**
  * @file raii.cpp  * @file raii.cpp
Line 163: Line 163:
   std::ifstream othello{"/srv/datasets/shakespeare-othello.txt"};   std::ifstream othello{"/srv/datasets/shakespeare-othello.txt"};
   std::cout << "Othello: " << count_vowels(othello) << '\n';   std::cout << "Othello: " << count_vowels(othello) << '\n';
-  // std::cout is just a plain input stream:+  // std::cin is just a plain input stream:
   std::cout << "std::cin: " << count_vowels(std::cin) << '\n';   std::cout << "std::cin: " << count_vowels(std::cin) << '\n';
   // Lifetimes of `hamlet` and `othello` end here.   // Lifetimes of `hamlet` and `othello` end here.
Line 171: Line 171:
  
 <WRAP round info> <WRAP round info>
-=== Notes ===+== Notes ==
  
 [[https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization|RAII]] is a horrible acronym, but understanding its consequences in C++ is important. [[https://en.wikipedia.org/wiki/Resource_acquisition_is_initialization|RAII]] is a horrible acronym, but understanding its consequences in C++ is important.
 +</WRAP>
 +
 +=== scope_lifetime_practice.cpp (an opportunity to think and practice) ===
 +
 +<file cpp scope_lifetime_practice.cpp [enable_line_numbers=true]>
 +/**
 + * @file scope_lifetime_practice.cpp
 + * @author Jeffrey Bergamini for CS 19 Boot Camp, jeffrey.bergamini@cabrillo.edu
 + *
 + * Some lunchtime practice!
 + */
 +
 +#include <cctype>    // for `std::isprint()`
 +#include <fstream>   // for `std::ifstream`
 +#include <iostream>  // for `std::cout`
 +
 +/**
 + * `main()` can have parameters to access *command-line arguments* and *environment variables*.
 + *
 + * @param argc argument count: the number of command-line arguments (including the executable name)
 + * @param argv argument values: an array of C strings containing the command-line arguments
 + */
 +int main(int argc, char **argv) {
 +  // Exit with an error message if command-line arguments weren't provided:
 +  if (argc < 3) {
 +    std::cerr << "Usage: " << argv[0] << " FILE1 FILE2\n";
 +    return 1;  // nonzero exit status reports unsuccessful termination to the shell
 +  }
 +  // Attempt to open the two files specified as command-line arguments:
 +  std::ifstream f1(argv[1]);
 +  std::ifstream f2(argv[2]);
 +  if (!f1 || !f2) {
 +    std::cerr << "Cannot read from input file(s)\n";
 +    return 2;
 +  }
 +  // TODO: Find all the unique printable characters present in one file and not the other.
 +  // Print each unique character and its ASCII encoding, one character per line, in ascending order.
 +}
 +</file>
 +
 +<WRAP round info>
 +== Notes ==
 +
 +Having some data to test with is useful. I have many textual datasets available. If you have your program in a form that is executable in a terminal, the following commands should work for testing:
 +
 +Command:
 +<code bash>
 +./a.out <(echo suitably) <(echo implausible)
 +</code>
 +
 +Expected Output:
 +<code>
 +e 101
 +m 109
 +p 112
 +t 116
 +y 121
 +</code>
 +
 +Command:
 +<code bash>
 +./a.out <(curl -s https://jeff.cis.cabrillo.edu/datasets/genius.txt) <(curl -s https://jeff.cis.cabrillo.edu/datasets/injust.txt)
 +</code>
 +
 +Expected output:
 +<code>
 +      39
 +,       44
 +-       45
 +.       46
 +J       74
 +M       77
 +j       106
 +k       107
 +v       118
 +</code>
 +
 +Command:
 +<code bash>
 +./a.out <(curl -s https://jeff.cis.cabrillo.edu/datasets/shakespeare-hamlet.txt) <(curl -s https://jeff.cis.cabrillo.edu/datasets/shakespeare-macbeth.txt)
 +</code>
 +
 +Expected Output:
 +<code>
 +      34
 +#       35
 +$       36
 +%       37
 +*       42
 ++       43
 +/       47
 +0       48
 +4       52
 +5       53
 +6       54
 +7       55
 +8       56
 +9       57
 +<       60
 +=       61
 +>       62
 +@       64
 +J       74
 +U       85
 +X       88
 +Z       90
 +_       95
 +j       106
 +~       126
 +</code>
 </WRAP> </WRAP>
  
lecture_materials/week_00.1755566857.txt.gz · Last modified: by Jeffrey Bergamini