CISC-2000-E01 Homework

This semester’s homework
(CISC-2000-E01 in Spring 2026)

  1. Thursday, January 15, 2026. Nothing to hand in this week, but you have plenty to do. Read the syllabus, including the links to attendance and plagiarism. Admire the good-looking students in the class and click on each student’s Fordham ID to look in their public_html directory. Log into your account on our Fedora Linux server storm.cis.fordham.edu. (All but three students were able to do this on January 15, 2026; see this link). Try out all the basic Linux commands. Practice editing (i.e., hacking up) a file (e.g., xanadu.txt) with the editor vi.

    Please email me at mmeretzky@fordham.edu if you can tell us how to log in to storm.cis.fordham.edu from a Google Chromeboook.

    Two examples showing that composing a bitmask of 1’s and 0’s can actually be fun:

    1. the photographic negative example is an easier way to make the bitmask 0xDF.
    2. the use of “bitwise or” in the expression sun | mon | tue in restaurants.C is an easier way to make the bitmask 0x07.

    Homework that will be due on Wednesday, January 28, 2026: change restaurants.C so that it outputs the number of weekdays that each restaurant is open. The output will be

    Katz's Delicatessen   3
    Tavern on the Green   2
    Wo Hop                7
    Luchow's              3
    Delmonico's           3
    
    Hint: decimaltobinary.C showed how to examine each bit of an int. In this homework, you will have to examine each bit of a char. Simply count how many of these bits are 1’s. Feel free to add additional restaurants to the array of structures. For example, just for testing purposes, how about adding a restaurant that is never open?

  2. Thursday, January 22, 2026. Two homeworks due on Wednesday, January 28, 2026:
    1. Run restaurants.C (go to your home directory, download it with wget, compile it with your compile shellscript, and make sure it works. Then edit it with vi and change it so that it outputs the number of days per week that each restaurant is open. (Hint: in addparity.C and checkparity.C, we saw how to count how many 1 bits there are in a byte.) The output should be
      Katz's Delicatessen   3
      Tavern on the Green   2
      Wo Hop                7
      Luchow's              3
      Delmonico's           3
      
      Feel free to add additional restaurants to the array of structures. For example, just for testing purposes, how about adding a restaurant that is never open? The program will no longer have to find out what day of the week it currently is. Move your restaurants.C file to the public_html subdirectory of your home directory, and make sure it’s visible here. Leave the executable restaurants file in the bin subdirectory of your home directory; don’t move it anywhere.
    2. Write an interesting C++ program named vector.C with some flavor of vector (such as vector<int>, vector<double>, vector<string>, or even a “vector of vectors” such as vector<vector<int>>). Imitate vectorint1.C or vectordouble1.C. Remember to #include the header file <vector>. Your vector object can be born empty, like the ones in vectorint2.C or vectordouble2.C. Or the vector can be born with some values already in it, like the ones in vectorint1.C or vectordouble1.C. Remember to move your vector.C file to your public_html subdirectory.

  3. Thursday, January 29, 2026. Study and run the series of evolving examples in classes: the versions 3ints.C, struct.C, obj1.C, obj2.C, obj3.C. The most important pair of examples in this series are struct.C (which visibly passes a “pointer to a structure” down to the functions that do all the work) vs. obj1.C (which invisibly passes a “pointer to an object” down to the functions). These two programs do exactly the same thing, but obj1.C has a much simpler notation. You can’t get any notation simpler than no notation at all, can you?

    Do the exercises in classes involving obj2.C: exercises 4c, 4d, 4e, 4f, 4g, and 4h. You don’t have to do exercise 4i, because we didn’t get that far on Thursday, January 29, 2026.

    The only exercise you have to hand in is 4g, because that’s the only one that requires actual programming. Here’s how you will hand it in. In class on Thursday, January 29, 2026, we did exercise 4j where we created a directory named date and downloaded into it a C++ program consisting of the three files date.h, date.C, and main.C. Many CISC-2000_E01 students have already done this successfully, for example lov. See his date directory that holds three files? Add the code for exercise 4g into these three files. You’ll also have to add some code to the main function in main.C to test your new member functions date::prev and date::prev, something like

    	//in the main function
    
    	date yesterday {today};
    	yesterday.prev();     //Go back one day.
    	yesterday.print();
    	cout << " was yesterday.\n";
    
    	date lastWeek {today};
    	lastWeek.prev(7);     //Go back one week.
    	lastWeek.print();
    	cout << " was last week.\n";
    
    	date newYearsEve {1, 1, 2027};   //month, day, year
    	newYearsEve.prev();
    	newYearsEve.print();
    	cout << " will be New Year's Eve.\n";
    
    	date aYearAgo {today};
    	aYearAgo.prev(365);
    	aYearAgo.print();
    	cout << " was a year ago.\n";
    
    Then run the program again and see if the output was correct.

    When downloading a page or a C++ program from the class web site, it would be a good idea to press the Refresh button on your browser to make sure you’re downloading the most up-to-date version of the file.

  4. Thursday, February 5, 2026. We got up to “increment” in section 7 of Prerequisites. We will begin Operator Overloading on February 12, 2026; admire columns 1, 2, and 3. I corrected the errors in the dynamic memory allocation example (“escape from the tyranny!”) in section 14 of Classes. Sorry. Please email me at mmeretzky@forham.edu if you can think of more pairs of events I could add to the list in section 12 of Classes (“Events often happen in pairs”).

    Meditate on the following question, but you don’t have to write the code. Suppose you had to write distance and midpoint friends for a class date. Would it be easier to write these functions using the original, naïve three-data-member implementation of class date, or would it be easier (far, far easier!) using the one-data-member implementation of class date? See sections, 5, 6, 7 of Classes.

    Write an interesting class of objects. First, use mkdir to create a new subdirectory of your public_html directory. Create a .h file (a header file) and a .C file (an implementation file) for your new class, and a main.C file to create a few objects of the class (or an array, or even a vector of objects of the class) and demonstrate them. Put all three files in your new directory.

    You can invent a class whose objects exist primarily to hold data members, like the classes date and point we saw in the lectures. (If you’re having a real failure of imagination, you can make a class time holding three data members hour, minute, and second, slavishly following the original three-data-member class date. But a slavish world devoid of imagination would be a very drab place.) Or you can invent a class whose objects exist primarily to trigger a pair of events, like classes announcer (birth and death announncements) or class ofstream (open and close an output file). Or you can invent a class of big objects that contain smaller objects, like class interval, or maybe a class triangle each of whose objects contain three smaller point objects.

    Chemistry majors: how about a class element with a data member holding the element’s atomic number, and member functions returning the row and column occupied by the element in the periodic table? Math majors: how about a class vector3 with three double data members holding the components of a vector in a three-dimensional space, and friend functions named dotproduct (returning a double) and crossproduct (returning a vector3)? Please don’t name the class vector: that name is already taken.

  5. Thursday, February 12, 2026. We got as far as the input operator>> in ¶9 of Operator Overloading. Next week (Feb 19) will be a review for the midterm on Feb 26. Fordham has just invited me to teach CISC-1600 and CISC-1610 on Thursday nights in Fall 2026, starting on Thursday, August 27, 2026. You can’t take these courses again, but you can send your friends. They haven’t invited me yet to teach any courses in Summer 2026.

    Study the Operator Overloading examples we did in class. Two possibilities for this week’s deliverable:

    1. Starting with the minimalistic, stripped down class date in this program, provide it with all the operator functions we did in class on Feb 12. In other words, paste in all the individual operator functions we created in class into one big example. (I’m not asking you to write any original code.) Some of these functions will be member functions, some of them will be friends, and some will be neither. Some of these functions will be short enough to be inline (defined in the date.h file), and some of them will be too long to be inline (declared in the date.h file, defined in the date.C file). Savor the justifiable feeling of pride that will be yours when you see these functions helping each other. (For example, operator!= will do the bulk of its work simply by calling operator==, and the prefix operator++ will do the bulk of its work simply by calling operator+=.)

    2. Do the same as above, but with an interesting class of your own invention instead of with my class date.

    Math majors: why don’t you make a class complexNumber, with data members re and im, friends operator<< and operator==, and member functions operator+= and operator*=, etc. I’d like to be able to add and multiply complex numbers:

    	complexNumber c1 {10, 20};
    	complexNumber c2 {30, 40};
    	complexNumber sum {c1 + c2};   //calls operator+(c1, c2)
    
    	cout << "The product is "<< c1 * c2 << "\n";
    
  6. Thursday, February 19, 2026. Play with my new tool. Study for the midterm examination on Thursday, February 26, 2026.
  7. Thursday, February 26, 2026. No homework.
  8. Thursday, March 5, 2026. Download, compile, and run the “video game with three objects” in ¶ 22 of Inheritance. You can change the number of milliseconds in main1.C to change the tempo of the game.
  9. Thursday, March 19, 2026. Run the game, and study the main function and classes rabbit and wolf. In the main function, observe the calls to the following member functions of the terminal object: xmax and ymax, put, wait. Observe that classes rabbit and wolf have almost the same constructors. In those constructors, look at the calls to the following member functions of the terminal object: in_range, get, background, put. (You can also see a call to the beep member function of class terminal in the wolf::move member function.)

    rabbit::move and wolf::move seem very different from each other. Do they have anything in common that we can salvage? Write a destructor for classes rabbit and wolf.

  10. Thursday, March 26, 2026. Go to Inheritance and press your browser’s Refresh button. See how classes wolf and rabbit evolved and simplified through the three versions of the game.
    1. Version 1 in ¶ 25 (no inheritance):
      wolf.h, wolf.C, rabbit.h, rabbit.C
    2. Version 2 in ¶ 32 (single inheritance):
      wolf.h, wolf.C, rabbit.h, rabbit.C
    3. Version 3 in ¶ 40 (multiple inheritance):
      wolf.h, rabbit.h. There is no more wolf.C and rabbit.C.

    Go to Gateway and press your browser’s Refresh button. Follow the directions in ¶ 5 to download and run bmi.html and bmi.C. Note that you will have to create a new directory named cgi-bin (with a dash, not an underscore) to hold bmi.C. And note that you will have to put your own Fordham name into the ACTION atrribute of the FORM tag in bmi.html. Once you have verified that this form and this program work, change them to do something else. For example, you could translate Fahrenheit to Celsius, or English to Pig Latin. Feel free to use any of the entertaining widgets in this form.html.

  11. Thursday, April 9, 2026. I corrected my bug in sign. The problem was the first if statement in the for loop in sign.C, which has now been corrected to
    		if (month < s.month || month == s.month && day <= s.day) {
    
    Note that the && “binds tighter than” (i.e., has higher precedence than) the ||. Therefore the above line has the same meaning as
    		if (month < s.month || (month == s.month && day <= s.day)) {
    
    Moral: I should have tested it more. See the similar if-statment-in-a-for-loop in bmi.C.

    Write an entertaining form with widgets in a page of HTML, and then a C++ program that receives the data from these widgets. For inspiration, run the following forms (and please email me if you want me to add your own form to this list):

    1. bmi.html by an151
    2. pizza.html by ljl8
    3. bmi_deluxe.html (with an underscore _) by jc208
    4. wind.html by rz54
    5. vacation.html by fs89

    Observe that the game had a whole series of almost identical classes (carnivore.h, herbivore.h, inert.h, etc.) that differed only in the integers we plugged into them. Study how we replaced them with one template class in position.h, and then wrote some using statements in that file to let people go on using the names carnivore, herbivore, inert, etc., as if these classes still existed.

    Simiarly, observe that the game had another series of almost identical classes (wolf.h, rabbit.h, boulder.h, landmine.h, etc.) that differed only in the “mother” and “father” we plugged into them (and the char that represented them on the screen). Study how we replaced them with one template class in grandchild.h, and then wrote some using statements in that file to let people go on using the names wolf, rabbit, boulder, inert, etc., as if these classes still existed.

    I don’t want to freak you out, but the familiar C++ class string was actually created by one of these using statements. There are several flavors of strings, just as there are several flavors of grandchilds in the game.

    using  string = std::basic_string<char>;    //a plain old string holds chars
    using wstring = std::basic_string<wchar_t>; //a wstring holds wide chars
    
  12. Thursday, April 16, 2026. If you have not already done so, make a web page containing a form with widgets that launches a C++ program. Check the class’s most recent progress.

    Run this form. Can you help kwesner1 replace her map aduetog (“acceleration due to gravity”) with a plain old array or vector? Hint: her int variable planet already holds an integer in the range 1 to 8 inclusive. You can use this integer as a subscript in your new array or vector.

    Run this form. Can you help fs89 replace his snarl of if statements with something more civilized? (For inspiration, see the two-dimensional array in language1.C.) Also help him to look up items in his map the right way: change

    	//Unnecessarily searches the map twice.
    	string firstname = (m.find("firstname") != m.end() ? m["firstname"] : "Traveler");
    
    to
    	//Searches the map only once.
    	string firstname;
    
    	const auto it {m.find("firstname")};     //it is an iterator
    	if (it == end(m)) {
    		firstname = "Traveler"; //didn't find what we were looking for
    	} else {
    		firstname = it->second; //found what we were looking for
    	}
    

    Find the Unicode code chart for the (wide) characters of your ancestral language (Chinese, Russian, Greek, Arabic, Hebrew, etc.) and write a C++ program that outputs a few characters or words. For example,

    #include <clocale>
    
    	setlocale(LC_ALL, "");       //to support wide characters
    
    	wchar_t gamma {L'\x0393'};   //Unicode uppercase Greek letter gamma
    	wchar_t delta {L'\x0394'};   //Unicode uppercase Greek letter delta
    
    	wstring ws {L"\x0393\x0394"}; //a wide string containing gamma and delta
    
    	wcout << gamma << L" " << delta << L" "
    		<< ws << L"\n";
    
    The output is
    Γ Δ ΓΔ
    
    Could you write a gateway program in your cgi-bin directory that outputs a page of HTML with foreign characters?
    	wcout << L"<!doctype html>\n"
    		<< L"<HTML>\n";
    	//etc.
    
  13. Thursday, April 23, 2026. By copying jc208’s very able code in his languages.C, I was able to get kwesner1’s Bengali to work. See bengali.cgi, which is the output of this bengali.C. Thanks.

    Run the animal.C game in Strings ¶ 14. After you’ve told it that you don’t want to play again, look at the animal.txt file that the game leaves behind. Can you draw a picture of the tree whose structure is stored in this file? Then launch the game again, and observe that the game remembers everything it learned during its previous run. Contemplate the four steps in using recursion in ¶ 34.

    Come prepared with your questions for the full-semester review on April 30.

  14. Thursday, April 30, 2026. To study for the final exam on May 7, 2026, concentrate on three programs:

    1. restaurants.C in Binary. This program uses all four of the major binary operators (& | << >>). Admire the user-friendly way in which it creates the binary values of the chars without having to write numbers in hexadecimal. For example, for Delmonico’s we were able to synthesize the byte 00110001 by saying the instantly understandable sun | thu | fri instead of the cryptic 0x31.

    2. The version of the rabbit game that introduces inheritance, in ¶ 31 of Inheritance. Admire how classes wolf and rabit have very little code remaining in them, compared to the original version of the game in in ¶ 25. Most of the code has moved upstairs to the new base class wabbit.

    3. animal.C in String. Each node object in this program resides in its own separately allocated block of memory. Each question node contains two pointers (named yes and no) pointing down to its two children. Each animal node contains the same two pointers, but in an animal node the pointers have the dead-end values nullptr and nullptr because an animal node has no children. To traverse the tree of nodes (i.e., to visit every node in the tree), we have to use recursion instead of a for loop; see the functions deleteTree and save.
  15. Thursday, May 7, 2026 is the final examination at 6:00 pm EDT. Open book, open notes, closed computer, closed tablet, closed phone.

Last semester’s homework
(CISC-2000-L11 in Summer Session I 2025)

  1. Tuesday, May 27, 2025. Play with the Linux commands and the vi editor. Use wget to download one or two of the C++ programs we looked at today, and then compile and run them. (For example, how about a program such as 12hour.C or 2d.C, whose output depends on the current date and/or time?) See you in room 602 Leon Lowenstein tomorrow (May 28).
  2. Wednesday, May 28, 2025. Write a C++ program that creates a structure, and passes the address of the structure to a function. Imitate passstruct.C. Move your program to the public_html subdirectory of your home directory on storm.cis.fordham.edu, then go here and make sure your program is visible. While you’re at it, you can remove any junk files left over from the first night of the course.

    Read and compare bubble1.C and bubble2.C. Study the three versions of structure.C, structure1.C, structure2.C.

  3. Thursday, May 29, 2025. How many directories are on your $PATH? Create a bin subdirectory of your home directory on storm.cis.fordham.edu, if you have not already done so. Create and chmod the compile shellscript if you have not already done so. See Linux.

    Required reading: compare the three versions of 3ints.C, struct.C, obj1.C. The ideal way to do this would be to print them out and study them side by side.

    Then write a C++ program with a class of objects containing data members. Imitate obj1.C. For example, it could be

    Give your class some interesting member functions, certainly at least a print member function. As usual, put this C++ program in the public_html subdirectory of your home directory on storm.cis.fordham.edu.

  4. Tuesday, June 3, 2025. Study how I unsnarled the data and code in weatherreport.C (with output weatherreport.txt), turning it into the easier-to-read weatherreport2.C (with output weatherreport2.txt).

    Continue to study the evolving series of programs

    1. 3ints.C: a lot of disconnected ints
    2. struct.C: create a type of structure
    3. obj1.C: create a class of objects
    4. obj2.C: a class with a constructor
    5. obj2.3: a class whose constructor initializes the data members of the newborn object

    Hand in (i.e., place in the public_html subdirectory of your home directory on storm.cis.fordham.edu) a version of obj2.C incorporating the answers to exercises 4d, 4e, 4f in this page. If you don’t have time to finish this by Wednesday, June 4, and/or if you think we’re going to fast, we can spend some or all of our lab hour on Wednesday working on 4d, 4e, 4f.

  5. Wednesday, June 4, 2025. Think of some more examples of events that come in pairs, that can be performed by the constructor and destructor of an object. Think of some more examples of events that come in nested pairs, that can be performed by the constructors and destructors of objects created in a series of declarations.

    Write an interesting class (in a .h file and a .C file) that has one or more friend functions, as well as member functions.

  6. Thursday, June 5, 2025. We’lll have a midterm review on June 10, and the midterm itself on June 11. No homework, just study.
  7. Tuesday, June 10, 2025.
  8. Wednesday, June 11, 2025. Midterm examination.
  9. Thursday, June 12, 2025. Hand in a version of the one-data member class date (date.h, date.C) with all the operator functions we did in class today. Also add operator-=, operator- (only the one taking a date and an int), prefix operator--, and postfix operator--. Do not bother with the pedagogical function definitions. The program should also have a main.C file containing a main function that will test all these operator functions.

    Special extra homework only for ear7. Add the following code to the main function in your objRev.C. Does it produce the correct output? If not, can you debug it?

    	date d {6, 1, 2025};   //June 1, 2025
    	d.prev();
    	d.print();             //Should output 5/31/2025
    	cout << "\n";
    
    	date e {1, 1, 2025};   //January 1, 2025
    	d.prev();
    	d.print();             //Should output 12/31/2024
    	cout << "\n";
    
  10. Tuesday, June 17, 2025. Give class grade the usual overloaded operators. (It doesn’t need a copy constructor, operator=, operator[] or operator().) Observe that the operator functions for class grade are very similar to the ones we wrote for the one-data-member class date.
  11. Wednesday, June 18, 2025. Study class rabbit (in rabbit.h and rabbit.C) and class wolf (in wolf.h and wolf.C) in the video game, and also the main function. terminal.h is a good summary of the services offered by the terminal object.

    Download the game and run it. You can make little changes like changing the speed (change the 250 in the main function) or changing the background color (i.e., the background character) of the terminal object (change the argument of the constructor of the terminal object in the main function).

    Do the destructor exercise.

  12. Friday, June 20, 2025. Make sure you understand every line of the game in paragraphs 18 and 24 of Inheritance. Run the game on storm.cis.fordham.edu if you have not already done so. If you can’t download and compile it, you can run the two versions there in ~mmeretzky/game1/a.out and ~mmeretzky/game2/a.out.

    A criticism of the game in ¶ 24: we have incorrectly bundled together carnivorous appetite and manual motion in class wolf; this makes it impossible to inherit one without the other. Similarly, we have incorrectly bundled together herbivorous appetite and random motion in class rabbit; this makes it impossible to inherit one without the other. We will correct these problems with a dose of multiple inheritance and templates during the last week of the course in paragraph 32, and then with Templates.

  13. Tuesday, June 24, 2025. You now have a third version of the video game to study, using multiple inheritance in paragraph 32 of Inheritance. Note that in this version, the grandchild classes wolf and rabbit (and boulder and landmine) have become identical, except for the names of the mother and father of each grandchild, and the char with which each grandchild appears on the screen. It is therefore appropriate and easy to replace these identical grandchild classes with the single template class grandchild in paragraph 22 of Templates. The grandchild class takes three template arguments: the mother, the father, and the char.

    Do the map homework in paragraph 3 of Gateways. If you have time, play with the form and the C++ program in paragraphs 4 and 5.

  14. Wednesday, June 25, 2025.
  15. Thursday, June 26, 2025. Final examination.

Another previous semester’s homework
(CISC-2000-C01 in Spring 2025 2025)

  1. Thursday, January 16, 2025. Read the course syllabus. Make sure you can log into your account on the Fedora Linux server storm.cis.fordham.edu. Write your secret password on a piece of paper. If you forgot your secret password, submit this form to reset your secret password. Nothing to hand in this week.

    Compare binary.C, which outputs an integer as 32 bits, with hexadecimal.C, which outputs an integer as 8 hex digits. Each hex digit is an abbreviation for a series of four bits. (A series of four bits is called a nibble.) Can you compile and run these two C++ programs in your home directory on storm.cis.fordham.edu?

    Do you understand why the first for loop in loop.C has to perform an invisible multiplication and addition each time you evaluate the expression a[i]? Do you understand how the second for loop avoids this hidden arithmetic?

    Play with the Linux commands. If you put a file in the public_html subdirectory of your home directory on storm.cis.fordham.edu, see if it shows up here. (You may have to refresh this page in your browser.)

  2. Thursday, January 23, 2025. Make sure you can imitate the series of additions I made to bintodec1.C (in bintodec2.C, bintodec3.C, bintodec4.C) to catch the invalid_argument and out_of_range exceptions (and any other exceptions) that might be thrown by the function stoi.

    Admire how sdg5 generated the hexadecimal digits from right to left, and then loaded them into the array result starting at the end of the array and working forward, in his program hexadecimal.C. Compare to this hexadecimal.C.

    Note the similarities between the following programs:

    1. rocket.C looped through an array, and used a pointer (p) to access four consecutive elements of the array (p[0], p[1], p[2], p[3]) during each iteration of the loop. (Does rocket.C run smoothly on your Apple Macintosh or Windows PC? Are you really serious about animating the recursive maze.C program we ran last semester?)
    2. movingaverage.C looped through an array, and used a pointer (p) to access five consecutive elements of the array (p[-2], p[-1], p[0], p[1], p[2]) during each iteration of the loop.
    3. bubblesortintptr.C looped through an array, and used a pointer (q) to access two consecutive elements of the array (q[0], q[1]) during each iteration of the loop.

    The program passstruct.C began with the blueprint for a new type of structure (called a month). It created a variable named j of this type, and passed the address of this variable to a function named f. The function received this address as a pointer named p, and used the pointer to access the two fields inside of j. The blueprint for month had to be written up above the main function, to make it possible to mention the word month in both of the functions main and f.

    Imitating passstruct.C, write a C++ program that has a blueprint for an interesting type of structure containing a few fields. Then create a variable of this type in the main function, and pass the address of the variable down to another function. The other function will receive the address as a pointer named p and will use the pointer to access the fields inside of the structure. Have the function do something interesting with the structire, not merely outputting the fields of the structure. Name your program structure.C, and put it in the public_html subdirectory of your home directory on storm.cis.fordham.edu by 6:00 p.m. EST on Wednesday, January 29, 2025.

    For more inspiration, look at struct.C. It creates a structure named tomorrow, and passes the address of tomorrow down to the one-argument next function, which does an elaborate computation to change the three fields inside of tomorrow to the following day’s date. Good luck.

  3. Thursday, January 30, 2025. The class date in obj1.C already has the following two non-const member functions:
    	void next(int n); //Go n days into the future.
    	void next();      //Go 1 day into the future.
    
    Add two more non-const member functions
    	void prev(int n); //Go n days into the past.
    	void prev();      //Go 1 day into the past.
    
    that will make the object to which they belong move into the past.

    Test your new functions by making a date object that contains March 1, 2025. Make the object go 1 day into the past and verify that it changes into February 28, 2025. Put this program into a file named prev.C in the public_html subdirectory of your home directory on storm.cis.fordham.edu by Wednesday, February 5, 2025 at 6:00 pm EST.

    Also by next Wednesday, make a C++ program named interesting.C in your public_html that creates a class, and creates one or more objects of that class, and calls one or more member functions of these objects to do something interesting. A simple but spiritless possibility would be to create a class time containing three data members named hour, minute, second, very similar to the class date in obj1.C.

    An experiment you could try: what is the biggest number of integers you can say you want to store on storm.cis.fordham.edu in the program new3.C without throwing an exception? Is it always the same number?

    Some code you could study: do the two versions of the function categor in jr224 always return the same value for any windspeed greater than or equal to 74?

    The Rose Hill tutoring room, John Mulcahy Hall room 310, is open 11:30–5:15 M–F (only until 4:00 pm on Monday until they find coverage).

  4. Thursday, February 6, 2025. Add the following three functions to the one-file C++ program obj2.C.
    1. The class date in this program already has a constructor with three explicit arguments. Keep this constructor, but add another constructor with no explicit arguments. This no-arg constructor will initialize the newborn date object to today’s date. To get this information, the constructor will call the functions time and localtime that we saw in time.C. Test your new constructor with the following code in the main function:
      	const date t; //Call the new constructor with no explicit arguments.
      	cout << "Today is ";
      	t.print();    //Make sure that t contains today's date.
      	cout << ".\n";
      
    2. The class date in this program already has several member functions. Keep them, but add another member function declared as
      public:
      	//Declarations for member functions of class date
      	int dayOfYear() const;
      
      that will return an int, in the range 1 to 365 inclusive, that will indicate what day of the year is the object that the member function belongs to. For example, the dayOfYear member function of a date object containing January 1 of any year will return 1, and the dayOfYear member function of a date object containing December 31 of any year will return 365. (Christmas will return 359.) Your member function will have to use the numbers in the date::length array. Test your new member function with the following code in the main function:
      	const date xmas {12, 25, 2025}; //Call constructor with 3 explicit args.
              cout << "Christmas is day number " << xmas.dayOfYear()
                      << " of the year.\n";    //Make sure it's 359.
      
    3. Write a friend function declared as
      public:
      	//Declarations for member functions and friend functions of class date
      	int dayOfYear() const;                               //a member function
      	friend int distance(const date& d1, const date& d2); //a friend function
      
      and defined as
      int distance(const date& d1, const date& d2)
      {
      	//etc.
      }
      
      Its two arguments will be references to two date objects, and it will return the distance measured in days between the two objects. Think of this function as if it were subtracting d2 from d1. That means the return value will be positive if d1 is later than d2, zero if d1 and d2 are holding the same date, and negative if d2 is later than d1. Hint: distance should call dayOfYear to do some of its work. Test your new friend function with the following code in the main function:
      	const date summer {6, 20, 2025};  //first day of summer
      	const date t;                     //today
      	const int dist {distance(summer, t)};
      	cout << "Only " << dist << " days till summer.\n";
      
    Please put this homework in a file named three.C in the public_html subdirectory of your home directory on storm.cis.fordham.edu by Wednesday, February 12, 2025 at 6:00 pm EST.
  5. Thursday, February 13, 2025.

    Make a subdirectory named height in the public_html subdirectory of your home directory on storm.cis.fordham.edu:

    cd
    cd public_html
    pwd
    
    mkdir height
    ls -ld height
    
    cd height
    pwd
    
    In this new directory, place a new version of the C++ program consisting of the three files height.h, height.C, and main.C. In this new version, change the feet and inches data members of class height to the following data member.
    	double centimeters;   //the height in centimeters
    
    Keep the arguments of the constructors, and the output of the print member function, the same; the rest of the program (in this case, the main function), should have no idea that the data members have been changed.

    Extra credit, for people who know Trigonometry. Make a subdirectory named point in the public_html subdirectory of your home directory on storm.cis.fordham.edu. In this new directory, place a new version of the C++ program consisting of the three files point.h, point.C, and main.C. In this new version, change the x and y data members of class height to the following two data members

    	double r;     //the polar coördinates of the point
    	double theta; //in radians
    
    Keep the arguments of the constructors, and the output of the print member function the same; the rest of the program (in this case, the main function), should have no idea that the data members have changed. Also add two new public member functions,
    	double x() const;
    	double y() const;
    
    that will return the Cartesian coördinates of the point.

    More extra credit. Do the indentation exercise at the end of class announcer.

    See Glenmore Marshall’s instructions for installing C++ on Macintosh (not required for this course). Thanks.

    I corrected my embarrassing inefficiences in the dayOfYear member function of class date. Sorry.

  6. Thursday, February 20, 2025. Study for midterm.
  7. Thursday, February 27, 2025. No homework.
  8. Thursday, March 6, 2025.
    1. Review how we reduced the original three-data member class date (date.h, date.C, main.C) to two data members and then to one data member.
    2. Review how we added the friend function operator<< to the one-data member class date in date.h, date.C, main.C. Review how we added the (inline) member function operator+= to the one-data member class date in date.h, date.C, main.C.
    3. Create a subdirectory named grade in your home directory on storm.cis.fordham.edu.
      cd              (Go to your home directory.)
      pwd             (Make sure you arrived there.)
      ls -l           (See what you already have in your home directory.)
      
      mkdir grade     (Create a subdirectory named grade.)
      ls -ld grade    (Make sure you created the subdirectory.)
      
      cd grade        (Go down into the new subdirectory.)
      pwd             (Make sure you arrived there.)
      ls -l           (See what's there.  It should be empty, of course.)
      
      In this subdirectory, create a three-file C++ program (grade.h, grade.C, main.C) that creates a class named grade. An object of this class will hold one of 14 possible values, indicating a grade in the range F, F+, D–, D, D+, …, A–, A, A+. What data member(s) would have to be inside of each grade object to empower the grade object to hold one of these 14 possible values? Give the class a constructor that will accept one string argument such as "A" or "A-" or "B+". Give class grade a friend function operator<< and a member function operator+=, imitating what we did for the one-data member class date. Write a main function in the file main.C that will construct one or more grade objects and demonstrate that operator<< and operator+= work.

      If you just can’t get class grade to work, you can peek at my grade.h, grade.C, main.C, but I want to encourage you to do it on your own. Can you figure out how to make an operator-= member function (almost identical to operator+=)? Next week, we will make lots of other operator functions, starting with operator+ and operator++. Thank you.

  9. Thursday, March 13, 2025. The main ideas from tonight’s class:
    1. operator+= and prefix operator++ change the value of an existing object.
    2. operator+ and postfix operator++ create a new object. (operator+ can create this new object as a pass-by-value argument.)
    3. Therefore operator+= is simpler than operator+. And prefix operator++ is simpler than postfix operator++.
    4. operator+ and prefix operator++ can do some of their work by calling operator+=.
    5. Postfix operator++ can do some of its work by calling prefix operator++.
    6. operator!=, operator>, operator>=, operator<= can do some of their work by calling the two friend functions operator== and operator<.
    7. You should have a justifiable feeling of pride when one operator function calls another operator function that you have previously written. There is no speed penalty in doing this, if the operator function that you are calling is inline.
    Add the operators we did today (+, prefix ++, postfix ++, ==, !=, -, <, >, >=, <=, >>) to class grade (grade.h and grade.C). Also add -, prefix --, and postfix --. Note that you are writing two different functions named operator-, one to subtract an int from a grade, yielding a new grade object, and one to subtract a grade from a grade, yielding an int that gives the distance between the two objects. And you are writing two functions named operator+, one with an object on the left and an int on the right, and one with an object on the right and an int on the left. Add some statements to to class grade’s main.C to test each of your new functions.
  10. Thursday, March 27, 2025. Write an interesting little program with a base class and a derived class.

    Put a web page containing a form into your public_html directory. The form will launch a gateway program named display.cgi in the cgi-bin subdirectory of your public_html directory.

    cd
    cd public_html
    pwd
    ls -l
    wget https://markmeretzky.com/fordham/2000/src/gateway/form.html
    ls -l form.html
    
    mkdir cgi-bin      (Make a new directory.)
    ls -ld cgi-bin
    cd cgi-bin
    pwd
    
    wget https://markmeretzky.com/fordham/2000/src/gateway/display.C
    ls -l display.C
    c++ display.C
    ls -l a.out
    mv a.out display.cgi
    ls -l display.cgi
    

    Then edit your form.html file, and in the ACTION attribue of the FORM tag, change my login name mmeretzky to your login name. Then point your web browser at
    https://storm.cis.fordham.edu/~jsmith/form.html
    where jsmith is your login name, and press some buttons. Please let me know if this doesn’t work. Study display.C, especially how the main function loops through the map m, spitting out pairs of LI tags.

    Special homework only for kheslin2: make a BMI (Body Mass Index) form (English or Metric) that launches a C++ program to display your BMI. For example, suppose you have a widget (of type NUMBER) named height representing your height in inches. Then assuming you have created the map named m in display.C, you can get the numerical value of height by calling the function stoi (“string to integer”):

    	const int height {stoi(m["height"])}; //#include <string> for stoi
    
    Please have this ready to demonstrate for the class on Thursday, April 3, 2025. Thanks, kheslin2!
  11. Thursday, April 3, 2025. Reorganize this program interesting2.C the way we reorganized the program interesting.C into the files vehicle.h, car.h, motorcycle.h, and main.C in class on April 3. Keep the output of the program exactly the same,
    income             30.00
    capital gains      40.00
    regressive    1000100.00
    progressive     10000.00
    property          200.00
    
    but use inheritance to get rid of all the if/else statements. (You will create five classes derived from class tax; write them, and class tax itself, in six .h files. In the main function, loop through an array of pointers.)

    Put an HTML file containing a form into your public_html directory on storm.cis.fordham.edu. Put a gateway program into the cgi-bin subdirectory pf your public_html directory. It’s okay if you want to get started by making a copy of my form and my gateway, as in the first box. But then please change the form and gateway to something original and surprising.

  12. Thursday, April 10, 2025. Run the rabbit game. Press h, j, k, l to move the wolf. (This is code that last saw the light of day during the Obama Administration.) Then in the main function in main1.C, replace the rabbit object with an array (or a vector<rabbit>) of three rabbit objects (or as many as you want). For example,
            rabbit a[] {
                    {term, 10, 20},   //Please use different numbers, not mine.
                    {term, 30, 40},
                    {term, 50, 60}
            };
    
            const size_t n {size(a)};   //need <iostream> for size
    
    During each iteration of the loop in the main function, call the move member function of each rabbit in the array (or in the vector<rabbit>). You can let the game end as soon as any rabbit is eaten by the wolf. Now that you have more than one rabbit, change the victory message in main1.C to “You killed a rabbit!”.

    For the Linear Algebra of Quantum Mechanics, I recommend volume 2 of Leonard Susskind’s Theoretical Minimum series, Quantum Mechanics: The Theoretical Minimum (2014). A little book (small format paperback, 280 pp.) on neural networks I recently read was Deep Learning (2019) by John D. Kelleher, part of the MIT Press Essential Knowledge series.

  13. Thursday, April 24, 2025. Add a destructor to classes wolf and rabbit.
  14. Thursday, May 1, 2025. Here is the easter.C we ran in class today. It was a present for my Monday night CISC-1100-C01 students.

    Please run the version of the game with multiple inheritance. You can add a few boulders and landmines to main.C if you wish.

    Then follow the directions to mass produce all the grandchild classes (wolf, rabbit, boulder, landmine) by means of one grandchild.h template.