Data Structures

CSI33      D01 (51433)

Tuesday, Thursday, 2:00 pm-3:50 pm, room ME 224
 

 
Date Class Materials HW assignment
05/24 Final Exam, 2 pm - 3:50 pm, at ME 224

Some interesting reads for the summer:
1) Finish Chapter 14 and do Chapter 15 from our textbook
2) Pointers vs References:
http://www.cplusplus.com/articles/ENywvCM9/,
https://www.geeksforgeeks.org/pointers-vs-references-cpp/
https://www.geeksforgeeks.org/passing-by-pointer-vs-passing-by-reference-in-c/
3) Unique pointers (std::unique_ptr):
https://en.cppreference.com/w/cpp/memory/unique_ptr
http://www.cplusplus.com/reference/memory/unique_ptr/

You can see all your grades in this Google Spreadsheet.
Look into the row with the last four digits of your CUNY First ID (EMPLID). 
05/17 Final Exam preparation

Final exam preparation slides (they don't have all the problems from Part 3).
See the remaining problems in this file: finalExam_CSI33sample.pdf
Solutions: FinalExam_CSI33sampleSols.pdf, BFSproblem.pdf, product.cpp.

We have 12 homeoworks in total.
3 of the lowest scores with be dropped! 

The Final Grade will be composed of:
Homeworks: 20%
Quizzes: 20%
Midterm Exam: 30%
Final Exam: 30%
05/12 Sections 14.1 - 14.4

Terminology review (from CSI 35): CSI33-lecture24.pdf
Lecture slides: CSI33-lecture24.pdf
Dikstra's example: DijkstrasExample.pdf
Breadth First Search implementation in C++: BFS.h, BFS.cpp, usingBFS.cpp, input1.txt

Breadth First Search Demonstration (you tube, ~9 mins): https://www.youtube.com/watch?v=EuwG9nk0VxQ

Dijkstra algorithm Demonstration (you tude, ~9 mins): https://www.youtube.com/watch?v=8Ls1RqHCOPw

A short (~2mins) but very nice video of depth first search algorithm application: https://www.youtube.com/watch?v=mE_PCK0oFyo

In-class Work: CSI33_Lecture24InClassWork.pdf
Solutions: CSI33_Lecture24InClassWorkSols.pdf
   
05/10 Section 13.3

Lecture slides: CSI33-lecture23.pdf

programs (in C++): TreeNode.h, TreeNode.cpp, AVLTree.h, AVLTree.cpp, TestAVLTree.cpp
programs (from the book, in Python): TreeNode.py, AVLTree.py, helpForAVL.py

in-class work (with solutions):
CSI33-AVL-In-Class-Practice.pdf,
avl_handout-CSVirginiaEDU.pdf
 
Suggested exercises (for practice, not for grade):

1) Multiple-Choice questions: p. 481 / 10
2) Short-Answer Questions: p. 481 / 2
3) AVL trees (Short Answer questions): page 481 / 4-11,
Answers: Chapter13-AVL-answers.pdf
4) Look through the AVL code in Python and lecture slides - understand how the rotations are done. Finish up the AVL.py code.
Comments
: you can use the following code for testing/seeing what is happenning(just add it to your program) helpForAVL.py
5) Look through the AVL code in C++ thoroughly
 
05/05 Sections 13.3-13.5 in C++

Lecture slides: CSI33-Lecture22.pdf

programs (in C++): mapUse.cpp,
programs (from the book and not, in Python): HashLetter.py, test_HashLetter.py

C++ map reference: http://www.cplusplus.com/reference/map/map/

Suggested exercises (for practice, not for grade):

0) Look through the hash examples in Section 13.5
1) True/False questions: p. 478 / 1, 2
2) Short-Answer Questions: pp. 479 - 480/ 1, 2, 4, 5, 8, 9
3) In-class work
Answers: Chapter13-answers.pdf

Self-study: starts on page 471
HashTable.py, test_HashTable.py (demonstrates hash table using chaining),
HashTable2.py, test_HashTable2.py (demonstrates hash table using open addressing with linear probing)
05/03 Sections 13.1-13.2 Priority queues and heaps

Lecture slides: CSI33-Lecture21.pdf

programs: Heap.py, usingHeap.py,
Heap.h, Heap.template, testingHeap.cpp

In-class Work: see lecture slides, files to use: PQueue_ideas.py
Answers/solutions: PQueue.py

Quiz 6 is based on topics about recursion ,from Sections 6.1 - 6.6

 
04/28 Section 7.5 in C++ - NO CLASS MEETING TODAY!

Please look through the C++ implementation of the BST class. I am working on notes right now and will post them as soon as I complete them. I will also to a template BST class and will post it later today.

Quiz 6 is moved to Tuesday, May 3rd

See the homework assignment as well!

Notes on Python to C++ code convertion: to be posted

programs (in C++):
TreeNode.h, TreeNode.cpp, usingTreeNode.cpp,
BST.h, BST.cpp, usingBST

Template version will be posted later

Useful links:
BST delete node: http://www.algolist.net/Data_structures/Binary_search_tree/Removal
Insertion and deletion (6 mins video): https://www.youtube.com/watch?v=wcIRPqTR3Kc
Comment: deletion procedure here follows a different strategy: right subtree, leftmost element.

In-class work: see lecture slides

Quiz 6 is based on topics about recursion ,from Sections 6.1 - 6.6
HW12 (due date: Thursday, 05/12) - last HW assignment
1) programming exercises: p. 248 / 2, 3, 5 - you can do in C++ or in Python versions, it is your choice
Python test code you can use for these problems: TestCodeForHWAssignment.py, for C++ use a similar one

2) define the reverse operation for BSTs (in C++ or in Python implementations - your choice) that will reverse the structure of the BST, i.e. for every node, all nodes in the left subtree have values greater than the value of the node; and all nodes in the right subtree have values less than the value of the node.

Suggested exercise (for practice, not for grade):
1) define the delete operation for BSTs in our C++ code (use Python's code)
04/26 Sections 7.5

Lecture slides: CSI33-Lecture19.pdf

programs (from the book): TreeNode.py, BST.py
other programs: usingBST.py

Useful links:
BST delete node: http://www.algolist.net/Data_structures/Binary_search_tree/Removal
Insertion and deletion (6 mins video): https://www.youtube.com/watch?v=wcIRPqTR3Kc
Comment: deletion procedure here follows a different strategy: right subtree, leftmost element.

In-class work: see lecture slides
Solutions: CSI33Leture19InClassWorkSols.pdf, InClassWorkDay13.py
 
Suggested exercises (not for grade):
1) Short Answer questions: p. 248 / 2, 3, 4
Solutions: Chapter7-questionsAnswers.pdf

2) Write unit tests for class BST to test insert_rec and find method, by doing the following:
Insert the following elements, one by one into a tree: 7, 3, 8, 2, 5, 9, then by using BST's method asList compare the produced by that method list with list [2,3,5,7,8,9] - this is one unit test for insert_rec method.
To test the find method: create the same BST as above, and find 8, 2, 9, and 5; compare the result with the numbers themselves. Then try to find 11, 1, and 4 and compare the result of each search with None.
  Friday, April 15th - Friday, April 22nd, Spring Break



You can see all your grades in this Google Spreadsheet.
Look into the row with the last four digits of your CUNY First ID (EMPLID).
04/14 Sections 7.1-7.4

Lecture slides: CSI33-Lecture18.pdf

programs (from the book): TreeNode.py

In-class work: CSI33_Day18_InClassWork.pdf
Answers: CSI33Lecture18pics.pdf

Quiz 5 based on Sections 5.3 - 5.4

Announcement:
Our Final Exam is scheduled for Tuesday, May 24th, from 2 pm to 3:50pm, at ME 224
 
HW11 (due date: Thursday, 04/28):
Attention: from now on, when you submit your homework, make sure the code compiles/runs

Recall singly linked lists (in both, Python and C++), i.e. every ListNode instance has two attributes: item and link. Define a method reverse() of LList class (in either Python or C++ implementations of our LList class), that would reverse the list.
Here is an example (click on the picture to see it at a higher resoution):


Suggested exercises (not for grade):
1) True-False questions: p. 245 / 1-5
2) Multiple-Choice questions: p. 246 / 2, 3
3) Short-Answer questions: p. 248 / 6


Solutions: Chapter7-questionsAnswers.pdf
04/12 Sections 6.4-6.6

Lecture slides: CSI33-Lecture17.pdf
programs (from the book): mergeSort.py, hanoi.py


Useful links: check out the online Tower of Hanoi puzzle

You can watch a video on Merge Sort here: http://en.wikipedia.org/wiki/Merge_sort
Suggested exercises (not for grade):
1) Use our Python code (mergeSort.py) and write the definition of Merge Sort in C++, define it is a template function. Test it.
2) You can compare the running times of the Selection sort (selection.cpp) and Merge sort (use the definition you wrote and tested). You can put the code of both procedures in one header file, say sort.h, and then use them: test_sort.cpp, test_sort2.cpp.
04/06 Sections 6.1-6.3

Lecture slides: CSI33-Lecture16.pdf

programs (from the book): fact.py, reverse.py, anagrams.py, power.py, bsearch.py, fib.py

In-class work: see lecture slides
Solutions/answers: maxRec.py

Quiz 4 today, based on Sections 5.1 - 5.2

Quiz 5 will be next Thursday, and will be based on Sections 5.3 - 5.4
Suggested exercises:
(for practice, not for grade):
1) What list is returned by anagrams("word")?
2) True-False questions: p. 212 / 1, 2, 3, 6
3) Multiple-Choice questions: p. 213 / 1, 4, 5, 6
4) Trace recPower(4,8) and and figure out exactly how many multiplications it does.
5) Short Answer questions: p.214 / 1, 5
6) programming exercises: p. 215 / 1, 5
Solutions: Chapter6Answers_part1.pdf, Chapter6Answers_part2.pdf
 
04/04 Sections 12.1-13.2

Lecture slides: CSI33-Lecture15.pdf
programs (from the book and not):
maximum.cpp, vec1.cpp, vec2.cpp, vec3.cpp
Stack we defined before: Stack.h, Stack.cpp, StackTesting.cpp
Template class Stack: Stack.h, StackTesting.cpp

Reference manual for Vector class template: http://www.cplusplus.com/reference/vector/vector/

Algorithms library reference manual: http://www.cplusplus.com/reference/algorithm/

In-class Work:
1) Implement a template minimum function and test it on int and double type values.
Solution: minimumInClassWork.cpp

2) Implement a Queue using templates along with the code to test it. This is a suggested HW assignment.
Solution
: Queue.h, testingQueue.cpp
HW10 (due date: Thursday, 04/15):
Attention: from now on, when you submit your homework, make sure the code compiles/runs
(1) Programming excercise: implement a template version of the average function (you may assume that we are planning to use it on the arrays of integers, floats and doubles only): average.cpp.
(2) Programming excercise: p. 442 / 3
Feel free to use these starters: TemplateList_forHelp.h, test_TemplateList.cpp
the header file has all the declarations you'll need, so you only need to add missing definitions;
the testing has a good enough testing code for you;
another suggestion would be to put all the definitions that are missing into the header file (after the class declaration and the cin and cout declarations), then you don't have to create a file with extension .template - it seems to be a good way.

Suggested exercises (for practice, not for grade):

1) True-False questions: p. 440 / 1, 2, 5

2) Multiple-Choice questions: p. 440-441 / 1, 2, 4

3) Programming exercise: p. 442 / 2
Solution: Queue.h, testingQueue.cpp
Answers: Chapter12questionsAnswers.pdf
Summarize all the data structures we explored so far with the run-time efficiency of common operations!!!

You can see all your grades in this Google Spreadsheet.
Look into the row with the last four digits of your CUNY First ID (EMPLID).
03/31 Sections 5.3-5.5

Lecture slides: CSI33-lecture14.pdf

programs (from the book): MyQueue.py, palindrome.py , C++ versions will be done in the next class meeting

In-class work: see the lecture slides, CabCompany.pdf, TestingCab.py
Solution: CabCompany.py

Self-study:
time-driven simulation: simulation.py, CheckerSim.py
Event-driven simulation: simulationEventDriven.py, CheckerSimEventDriven.py

Quiz 3 today, based on linked lists (in both, Python and C++).
 
HW 9 (due date: Monday, 04/11)
Attention: from now on, when you submit your homework, make sure the code compiles/runs
programming exercises:
1) p. 184 / 3 (use Stack to evaluate the post-fix expression as shown in lecuture slides), and
2) p. 184 / 4 (make sure to pay attention to all requirements in this exercise)

Suggested exercises:
1) True-False questions: p. 181 / 1-4
2) Multiple-Choice questions: p. 182 / 1-5
3) Short-Answer questions: p. 183 / 1

Answers/Solutions: Chapter5-questionsAnswers-part1.pdf, Chapter5-questionsAnswers-part2.pdf
03/29 Sections 5.1-5.2

Lecture slides: CSI33-lecture13.pdf

programs (from the book): Stack.py, Stack.h, Stack.cpp, StackTesting.cpp, parensBalance2.py

In-class assignment: see lectures slides.
Solutions/answers: In-classWorkAnswers.pdf, Stackunittesting.py

Quiz 4 next week on Thursday, will be based on Sections 5.1 - 5.2


 
Check out these useful videos:
Infix to Postifx:
https://www.youtube.com/watch?v=rA0x7b4YiMI
Infix to Prefix:
https://www.youtube.com/watch?v=fUxnb5eTRS0

Suggested exercises:
1) Implement the balanced parentheses check in C++
03/24 Topic: linked lists in Python and C++
Sections 11.1-11.5 (C++)
Plan:
1) we will look at the generators in the Python code for linked lists, and then
2) proceed with the C++ implementation

Lecture slides: CSI33-lecture11.pdf, CSI33-lecture12.pdf

Programs: ListNode.py, LList.py, testingLList.py,
ListNode.h, LList.h, LList.cpp, testLList.cpp

Additional practice:
1) Define a generator function that will be generaing Fibonacci numbers. Work on it on your own, then
see the 2 possible answers: Section4_5InClassWorkGenerator.py, Section4_5InClassWorkGenerator.py
Which version do you like better?
2) define cout operation for the linked list implementation in C++
A solution: LList2.h, LList2.cpp, testList2.cpp
3) Prepare a table of time complexities of operations of LList class we defined.

Quiz 3 next week Thursday, based on linked lists (in both, Python and C++).
HW 8 (due date: Thursday, 04/07)
Attention: from now on, when you submit your homework, make sure the code compiles/runs
Programming exercise: p. 424 / 2
You can use this code to check that your program works correctly: Chapter11-testLList2.cpp. Feel free to add additional tests.
Note that you are to work on our C++ source files. Modify, add methods, etc, but not start from scratch.

Suggested exercises (for practice, not for grade):

1) True-False questions: p. 422 / 1, 2, 5

2) Multiple-Choice questions: p. 423 / 1, 2, 4

3) Short-Answer questions: p. 424 / 1, 2
Solutions: Chapter11questionsAnswers.pdf
03/22 Midterm Exam

The midterm grade will be composed of HWs average (50%) and Midterm Exam (50%)
03/17 No meeting today

I am not feeling well today, and therefore I will make the preparation to Midterm Exam as online, asynchronous.
Here are the questions I was planning to work on today in class: CSI33MidtermExamInClassPractice2022.pdf

I will be posting answers to the first two parts along with short videos shortly.
I will also post a video of beginning of work on Part 3 problem, and then a solution.

You can find the study guide on Midterm Exam and Final Exam page

Answers and explanations to the questions from Part 1 and Part 2
Part 2, problem 1 (video explanation, 2:55 mins)
Part 2, problem 2 (video explanation, 11:19 mins)
Part 2, problem 3 (video explanation, 7:52 mins)
Part 3:
Video intro for Python coding, LibraryPatrons.py, Library-PatronsTesting.py (files are updated on Friday, March 18th, at 4:10pm)
C++ implementation: Library.h, Library.cpp, Library-PatronsTesting.cpp
Comments to C++ implementation:
1) Library was announced as a friend to PatronsRecord class, so that attributes of PatronsRecords instances are accessible from the Library instance (it is not a good approach, it is better to define accessor methods)
2) Note that two functions of Library class: loan and returnBook take areference to PatronsRecord instances. This allows to update the booksOnLoan parameter of the same instance of the PatronsRecord class.

03/15 Topic: linked lists in Python and C++
Sections 4.4, 4.5, 4.7 (Python)

Lecture slides: CSI33-lecture11.pdf

Programs: ListNode.py, LList.py, testingLList.py

In-class work: see the last slide in the lecture slides
Solutions: Section4_4InClassWork.py (work with LList),
Fibonacci numbers generator (2 versions): Section4_5InClassWorkGenerator.py, Section4_5InClassWorkGenerator.py
Which version do you like better?

Quiz 2 at the end of the class today
HW 7 (due date: Thursday, 03/31)
programming exercises: p. 152 / 1, 3 (do both in one file, LList.py)
you can use this test code to test your program: Chapter4-prog1_3LList-testing.py

Suggested exercises:
1) True-False questions: p. 148 / 1, 2, 4, 5
2) Multiple-Choice questions: p. 149 / 1-4
3) take a look at two versions of __copy__ method for LList class's implementation on page 132.
Solutions/answers: Chapter4-questionsAnswersSuggestedProblems.pdf
03/10 Topic: linked lists in Python and C++
Sections 4.1-4.3 (Python)

Quiz 2 on Tuesday, March 15th, based on Sections 10.1 - 10.3

Lecture slides: CSI33-lecture10.pdf

Programs: Section4_2example.py, ListNode.py

For in-class work: Sections4_1-4_3InClassWork.py, Section4_2example2.py

In-class work: see lecture slides (slides 14 and 15) and use this file (it is using a more elegant approach to creating a collection of linked nodes): problems1-2
Answers:
    problems 1-2: ListNode_classwork.py, Sections4_1-4_3InClassWorkProblems1-2.py;
    problems 3-4: In-classWorkProblems3_4.pdf

Very useful read about classes, namespaces and many more: https://docs.python.org/3/tutorial/classes.html
Suggested exercises
(not for grade, but highly recommended):
1) Short-Answer questions: p. 151 / 2
Answers: Chapter4-questionsAnswers.pdf
2) Complete all the in-class work
03/08 Sections 10.4, 10.5

Lecture slides: CSI33-lecture08-part2.pdf (we will continue implementaiton of List class in C++)

programs (from the book): List.h, List.cpp, testList.cpp
Next step (overloading input for objects of type List): List2.h, List2.cpp, testList_2.cpp

Additional resources:
CPython List operations time complexity: https://wiki.python.org/moin/TimeComplexity
HW 6 (due date: Thursday, 03/17)

Let's work on Rational class in C++. We will not need dynamical memory allocation, as rational numbers can be represented at fractions, a/b, where a in integer value and b is a non-zero integer value. Some part of the class definition is already in place. Grab these files and look through them thorougly: Rational.h, Rational.cpp, testingRational.cpp.
You will see that the constructor, the copy constructor, the operation + and comparison operation < are defined, along with helper-methods. Note that operation + is defined as member method/function, and the comparison operation < is defined as standalone method.

You are to continue working on this class to:
1) add three other basic operators - (subtraction), *(multiplication), and /(division) as member methods/functions of the class Rational (see the declaration and definition of addition operator +), see page 339 for their signatures;
2)
add the five comparison operators <=, >, >=, ==, and != as standalone functions (see the declaration and definition of the > operator), see page 337 for their signatures;
no need to define the input (>>) and output (<<) operators (they are written as standalone functions/methods), they are already defined for your convinience!
Tutoring by Christopher Lee in person and online Friday 12pm to 6pm and Tuesday 12pm to 3pm
online only, Sunday 12pm to 6pm and Monday 12pm to 5pm.

For in-person tutoring I believe you still need to sign up here: http://www.bcc.cuny.edu/academics/learning-commons/ 
03/03 Sections 3.1, 3.2, 3.5, and 3.6

Lecture slides: CSI33-lecture08.pdf, CSI33-lecture08-part2.pdf (we only looked at the header file of the List class)

programs (from the book): List.h, List.cpp, testList.cpp
Check out this one as well: unsigned.cpp

For self-development:
Investigate two data types in Python: array and set in Python.
Suggested exercises
(not for grade, but highly recommended):
1) True-False questions: p. 100 / 2, 3, 6
2) Short-answer questions: p.102 / 3, 4

Solutions: Chapter3-questionsAnswers-part1.pdf

Suggested project: page 104, programming exercise 9
03/01 Sections 3.3, 2.6

Quiz 1 will be next week Tuesday, at the end of the class. It will be based on Sections 1.2 and 1.3 only.

Lecture slides: CSI33-lecture07.pdf

more programs (from the book):
unitTestingCard.py

Self-development: Section 3.4 talks about a Bridge game. You can read it and watch this nice video on how to play Bridge:
rules: https://www.acbl.org/learn/
video: https://www.youtube.com/watch?v=Tyd7KlsRYO4
another video: https://www.youtube.com/watch?v=9yzS_26fICk
Here is the code of the Hand.py
HW 5 (due date: Thursday, 03/10)

1) Programming Exercises: p 103 / 1, 2, 3- all of these exercises should be implemented in one file Deck.py
Test all the operations, send the tests with your HW submission!

2) Write unit tests to test the methods suit, suitName and rankNameof Card class in Card.py. Use Chapter2-unitTestingCardHW.py
  You can see all your grades in this Google Spreadsheet.
Look into the row with the last four digits of your CUNY First ID (EMPLID).
02/24 Sections 2.1-2.3, and 3.3 from the book.

Study plan:
1) watch video discussing abstract data types and Card class (~ 25mins)
2) look at the Card.py (you can ignore the methods __lt__, __ne__, and __le__ for the time being, we will use them later) and testCard.py files
3) watch video discussing encapsulation, polymorpismi and inheritance (4:30 mins)
4) watch video about the Deck class (~ 13 mins)
5) What is the run-time complexity of the shuffle() method?
6) look at the Deck.py and testDeck.py files

Lecture slides: CSI33-lecture06.pdf

Programs:
cardADT.py, test_cardADT.py,
Card-spec.py,
Card.py, testCard.py,
Deck.py, testDeck.py

HW 4 (due date: Thursday, 03/03)

Implement the card game given in this description in Python.
02/22 No in-person meeting today, please follow the study plan:
1) watch this video: Algorithm Analysis (continue with Binary Search) ~12 mins long
2) Grab the handout, and work on the three problems on one side of it with the help of this video: Handout, problems 1-3 on one side
3) Flip the page of the handout over and work on the last problem.
Do items 1) and 2) on your own: copy the program, run it, see what the function returns when n = 1, when n = 2, and when n=10. Write down the results.
Then proceed with this video that is working on items 3) - 5)

The handout: CSI33-Lecture05InClassPractice2.pdf
Suggested exercise (for practice, not for grade):
1) Look at your implementation of the Selection Sort.
What assymptotic running time does it have?
Here is the running time analysis of the Selection Sort.
2) estimate the run-time complexity of the following block of code:
# n is a positive integer
s = 0
for i in range(n):
      for j in range(10):
            s += 1
3) estimate the run-time complexity of the following block of code:
# the program finds a square root of n, if the answer is an integer value:
n = int(input("Enter a positive integer:"))
assert n >= 1
i = 1
while i * i <= n:
      if i * i == n:
            return i
      else: i+= 1
return "not an integer"
02/17 Sections 1.1, 1.2, and 1.3

Lecture slides - part 1, Lecture slides - part 2

In-class work: CSI33-Lecture05Handout.pdf, CSI33-Lecture05InClassPractice2.pdf
Solutions: CSI33-Lecture05InClassPractice2-answers.pdf

Additional materials: BinarySearchIllustrated.pdf

Additional resources: Check out this simple explanation of big-O notation:
https://medium.freecodecamp.org/big-o-notation-simply-explained-with-illustrations-and-video-87d5a71c0174
HW 3 (due date: Thursday, 02/24):
Programming Exercise #9 , page 38 from Textbook (write it in Python)
comments:
1) Write the program in Python, do not use any built-in stuctures other than Python list
2) function squeeze should not modify the original list; instead, it should return a new list.
3) pay attention to everything you are asked to do!

Suggested exercises (for practice, not for grade):
1) Look at the example of a simple statistics program (interface) on page 15 in the textbook
2) True/False questions: p. 33 / 4-6, 9, 10 - not for grade
3) Multiple Choice questions: pp.34-35 / 1-6, 10 - not for grade
    Solutions: Chapter1solsTFMConly.pdf
4) Short-answer questions: p. 36 / 8 - not for grade
    Solution: Chapter1ShortAnswerQuestions.pdf
5) read about docstring conventions at http://www.python.org/dev/peps/pep-0257/
6) Watch a video about O, Ω, and Θ notations: https://youtu.be/6Ol2JbwoJp0
02/15 Topics to be covered:
Chapter 8: Sections 8.1 Introduction and 8.2 C++ History and Background
Chapter 10: Sections 10.1 Introduction, 10.2 C++ pointers, and 10.3 Dynamic Arrays

Lecture slides

Practice questions
Answer to question 1 (picture)
Suggested exercises (for practice, not for grade):
1) True-False questions: p. 396 / 3, 4,
2) Multiple-Choice questions: p. 397 / 1, 2, 3, 5
3) Short-Answer questions: p. 399 / 5, 6
Solutions/Answers: Chapter10-questionsAnswers.pdf

More practice with pointers: http://condor.depaul.edu/ntomuro/courses/309/notes/pointer_exercises.html
  Homeworks, Midterm Exam and Final Exam warning:
The homework, midterm exam, and final exam work must be solely your work.
They are not for group work, they are not to be looked for the solutions in online resources.
If I notice that your homework is similar to somebody else in our class, both parties' homework score will be zero (same for Midterm and Final Exam).
If I notice that you found a solution in online resources, your score will be zero as well.
Both cases, copying from somebody or finding and solution in online resources, are academic dishonesty.
You will be given first and last warning.
If I notice anything hapenning again, you will be reported to the chairperson and you may end up with a failing grade for this class.

Academic Integrity
Academic dishonesty (such as plagiarism and cheating) is prohibited at Bronx Community College and is punishable by penalties, including failing grades, dismissal and expulsion. For additional information and the full policy on Academic Integrity, please consult the BCC College Catalog.
02/10 There was no meeting on Tuesday, Februrary 8th as it was following Friday schedule.

Today we will refresh our memory about classes in Python and C++. We will be working on the class Complex of a complex number in its rectangular form (a+bi)

Lecture slides

Programs: ComplexNumber.py, testingComplexNumberClass.py;
complexNumber.h, complexNumber.cpp, testingComplexNumber.cpp

Some useful links:
1) Errors and Exceptions in Python
2) Modern C++ best practices for exceptions and error handling

Picture of the smart lock for the HW assignment:
HW 2 (due date: Thursday, 02/17):
White a class that will emulate a smart door lock with pin pad.
Name the class SmartLock and see the features it should have:
  • every smart lock comes with an admin pin code, i.e. every instance of the class SmartLock should have admin's pin code as a required parameter.
  • the length of any pin code is only four digits (not more, not less)
  • the smart lock can have more than one pin code that will open the door. For example: the admin code, the code for kids, the code for in-laws, the code for cleaning crew, etc.
  • any smart lock can store up to 10 pin codes (not more)
  • to enter a new pin-code, define a method AddNewPinCode() that should have two parameters: admin's pin code (for verification) and new pin code
  • the smart lock doesn't need to store information about pin code's dedication (for kids or for in-laws, it doesn't matter to the lock)
  • any pin code, except for the admin's pin code, can be removed, hence define a method RemovePinCode() that should take two parameters: admin's pin code (for verification) and the pin code to be removed
  • The lock has only two states: OPEN and LOCKED, hence think about having a "state" attribute to store the state of the lock
  • define a method EnterPin() that takes only one parameter: a pin code. If the pin code is one of the valid ones, the door lock should change it's state to the opposite one, i.e. if it was locked, it should become ulocked, and vice versa, if it was unlocked, it should become locked.
  • define a method Lock(), that should lock the smart lock independently at what state was it in
  • Finally, define a method CheckState() that doesn't take any parameters, but returns the "state" of the lock to us - whether it is locked or not (you can either return True or False, or , 0 or 1, where True(1) is for "LOCKED" and False(0) for "UNLOCKED")

    Declare the class in a header file .h, put all the necessary definitions into the implementation .cpp file (if you find it necessary), finally the test code put into a separate .cpp file. Send all the files to me as attachments to an email with subject HW 2 in the subject field.
02/03 Today we will finish slides and programs from previous class and will move on to next lecture slides.

Lecture slides
Handout: Selection Sort - Note that I found some errors in the pseudocode, they are fixed as of 7:10pm, Feb. 7th

the programs we did in class:
from previous class slides: sumOfSquares_withFunctions.py, SumOfSquares.cpp, linearSearch.cpp
from today's slides: SelectionSort.py - the code is fixed following the fix in pseudocode.
HW 1 (due date: Thursday, 02/10):
implement the Selection sort in C++.
In your implementation:
* define a function SelectionSort that takes two formal parameters: the array and its size,
* assume that the capacity of the array is 100 elements,
* you may also assume that we are working only with integer values, but you can work with decimal numbers as well, just be consistent!

Send your cpp file as attachment to an email with subject HW 1 in the subject field.
02/01 Hello and welcome to CSI 33 class.
I plan to spend week and a half - two weeks on Python and C++ languages review. Therefore, make sure that you have both compilers available and ready to be used.

If we don't have the compilers installed in our lab, we can use the following online compilers for now:
Python at replit or Python at OnlineGDB
C++

Announcements:
First two chapters of the book are available through e-reserves:
http://bcc-cuny.libguides.com/er.php?b=c
Choose CSI33 from the list

Lecture 1 slides - we stopped on slide 9 and I proposed that you start working on that problem in both Python and C++.


The programs we did in class: productAndAverageOfThreeDecimals.py, productAndAverageOfThreeDecimals_withFunction.py, ProductAndAverage.cpp
 
HW 0 (due date: Thursday, 02/03):
1) order the textbook

2) get the Python interpreter and C++ compiler, make sure they are working