Please enable JavaScript to use CodeHS

Data Structures in C++

Description

In this lesson, students learn basic input and output in C++ and will make a Haiku. Students will be exposed to the concept of variables, but more detail will follow in the next lesson.

Objective

Students will be able to:

  • Print to the console
  • Read in from the console
  • Explain the difference between the getline and cin commands
Description

In this lesson, students will learn the different variable types available in C++ and will learn the syntax for declaring and initiating these variables.

Objective

Students will be able to explain different variable types in order to choose the best option for various programming situations.

Description

In this lesson, students will learn different C++ syntax used to compare two variables, use logical operators such as and, or, and not, and apply these to conditional statements.

Objective

Students will be able to use logical and comparison operators and apply them within the context of conditional statements (if/else statements).

Description

In this lesson, students will learn to construct and apply for loops and while loops in C++. They will then apply these concepts to real-world problems.

Objective

Students will be able to use and construct for loops and while loops and explain when to use each type.

Description

In this lesson, students will learn to create functions in C++ as well as study some of the intricacies of C++ functions such as pass-by-reference and function prototypes.

Objective

Students will be able to create functions and apply different C++ standards in order to streamline their programs.

Description

In this lesson, students complete a summative assessment of the unit’s learning objectives.

Objective

Students will be able to:

  • Prove their knowledge of C++ basic concepts through a multiple choice quiz
Description

In this lesson, students learn about vectors, a data structure that stores elements of a given type in a linear arrangement. Similar to lists in Python or ArrayLists in Java, vectors are dynamically resizable, allowing elements to be inserted, removed, and updated without the need of allocating additional memory for its elements.

Objective

Students will be able to:

  • Declare and initialize a vector
  • Access and modify elements of a vector
  • Iterate through a vector using a for and for-each loop
  • Utilize vectors to solve real-world problems
Description

In this lesson, students learn how to provide default values for function parameters. Default parameters are used if a function is called without passing arguments. If an argument is provided, the default value is ignored.

Objective

Students will be able to:

  • Write functions with default arguments
  • Write prototypes with default arguments
  • Write overloaded functions with default arguments
  • Identify appropriate situations for defining default parameters
Description

In this lesson, students will be introduced to the idea of a struct. A struct is a basic C++ element that is used to store multiple data elements (members) in a single variable. Students will explore how to create and access structs in this lesson.

Objective

Students will be able to:

  • Create user-defined structs
  • Access and update struct member values
  • Understand when and where structs can be used
Description

In this lesson, students will learn how to read and write data from a file in order to open up more options to process larger volumes of data.

Objective

Students will be able to:

  • Read information in from a file
  • Process information from a file
  • Write information out to a file
Description

In this lesson, students will learn how to write try/catch statements to handle built-in errors as well as catch custom errors in order to have programs run efficiently and enhance user experiences.

Objective

Students will be able to:

  • Write try/catch statements
  • Catch standard C++ errors
  • Throw and catch custom errors
Description

In this lesson, students complete a summative assessment of the unit’s learning objectives.

Objective

Students will be able to:

  • Prove their knowledge of C++ concepts through a multiple choice quiz
Description

In this lesson, students will learn what a header file and implementation file are, and the role these files play in creating a library.

Objective

Students will be able to describe the purpose of a library and discuss the different parts of a header and implementation file as they are used in libraries.

Description

In this lesson, students will explore the Util library that will be utilized through the rest of the course.

Objective

Students will be able to understand how libraries make their code easier to develop and how to build and use the CodeHS Util library.

Description

In this lesson, students complete a summative assessment of the unit’s learning objectives.

Objective

Students will be able to:

  • Prove their knowledge of libraries through a multiple choice quiz
Description

In this lesson, students learn about two-dimensional (2D) vectors, a data structure that stores elements in a grid-like arrangement of “rows” and “columns.” Every element of a 2D vector is a vector, similar to how every element of a 2D array is an array.

Objective

Students will be able to:

  • declare and initialize a 2D vector
  • access and modify elements of a 2D vector
  • iterate through a 2D vector using a for and for-each loop
  • utilize 2D vectors to solve real-world problems
Description

In this lesson, students learn about stacks, a linear data structure that follows the LIFO (Last In First Out) principle. Similar to the behavior of real-world stacks, such as a stack of plates or deck of cards, elements of a stack are both inserted and removed from the top of the stack.

Objective

Students will be able to:

  • declare an empty stack
  • add elements to a stack using the push() method
  • remove elements from a stack using pop() method
  • access the top value of a stack using the top() method
  • perform other basic stack operations including size() and empty()
Description

In this lesson, students learn about queues, a linear data structure that follows the FIFO (First In First Out) principle. Similar to the behavior of real-world queues, such as a waiting queue or printing queue, elements of a queue are both inserted at the back of the queue and removed from the front of the queue.

Objective

Students will be able to:

  • declare an empty queue
  • add elements to the back of a queue using the push() method
  • remove elements from the front of a queue using the pop() method
  • access values from the front and back of the queue using the front() and back() method, respectively.
  • perform other basic stack operations including size() and empty()
Description

In this lesson, students complete a summative assessment of the unit’s learning objectives.

Objective

Students will be able to:

  • Prove their knowledge of 2D vectors, stacks, and queues through a multiple choice quiz
Description

In this lesson, students learn how to create and use pairs and iterators. While these tools will not be used extensively here, both of them will be used later in the module as students explore sets and maps.

Objective

Students will be able to:

  • Explain how pairs and iterators are used and how they differ from other tools in C++
  • Create and use a pair in the proper setting
  • Iterate through a vector using an iterator
Description

In this lesson, students learn how to create and use sets. Sets are useful data structures and are different than other data structures students have seen since they are stored without an index value.

Objective

Students will be able to:

  • Explain how sets are different than other data structures they have encountered and where they can be used.
  • Create, insert, update, and access members of a set
  • Use an operator overload to use a struct with a set
Description

In this lesson, students learn how to create and use maps. Maps are very handy data structures that use a key instead of an index to access values.

Objective

Students will be able to:

  • Explain how maps are different than other data structures they have encountered and where they can be used.
  • Create, insert, update, and access members of a map
Description

In this lesson, students complete a summative assessment of the unit’s learning objectives.

Objective

Students will be able to:

  • Prove their knowledge of sets and maps through a multiple choice quiz
Description

In this lesson, students learn what functional recursion is and how to write functional recursive code.

Objective

Students will be able to:

  • Explain what recursion is and the different parts of a recursive function
  • Write basic recursive functions
  • Solve real-world problems using functional recursion.
Description

In this lesson, students learn what procedural recursion is and how to write procedural recursive code.

Objective

Students will be able to:

  • Explain the difference between procedural and functional recursion.
  • Write basic recursive functions
  • Understand the difference between a depth-first and a breadth-first search
  • Solve real-world problems using functional recursion.
Description

In this lesson, students learn the basics of a recursive backtracking algorithm and apply that to several different projects.

Objective

Students will be able to:

  • Create a basic recursive backtracking algorithm
  • Solve more complex recursive backtracking problems
Description

In this lesson, students complete a summative assessment of the unit’s learning objectives.

Objective

Students will be able to:

  • Prove their knowledge of recursion through a multiple choice quiz
Description

In this lesson, students learn about pointers, a variable that holds a memory address. Pointers are one of the key concepts in learning programming and are used for implementing several data structures.

Objective

Students will be able to:

  • Declare a variable as a pointer using the dereference operator (*)
  • Assign a pointer to an existing memory address using the reference operator (&) and a new memory address using the new keyword
  • Declare and initialize pointers that point to data structures
  • Declare and initialize data structures that store pointers
  • Declare and call functions that take a pointer type as a parameter
  • Use the arrow operator (->) to methods through a pointer in lieu of using the dot operator (.)
Description

In this lesson, students learn about linked lists, a linear data structure in which elements are not stored next to each other in memory. Linked lists consist of nodes that each contain a data element and a pointer to the next node in the linked list.

Objective

Students will be able to:

  • Use object-oriented programming to implement the linked list data structure
  • Insert new nodes into a linked list
  • Traverse a linked list using a standard while loop
    traverse a linked list using recursion
Description

This lesson introduces students to the idea of graphs by using several examples and expanding on these examples. Graphs is a very broad topic and the lesson only scratches the surface of the topic.

Objective

Students will be able to:

  • Explain what graphs are and what they are used for
  • Make changes to existing graphs and customize the implementation
Description

In this lesson, students complete a summative assessment of the unit’s learning objectives.

Objective

Students will be able to:

  • Prove their knowledge of pointers, linked lists, and graphs through a multiple choice quiz