Unit 2 Study Guide and Review: Dealing with Data and Compound Types

2a. List and use the operators in the C++ language

  1. What are the operators and the order of precedence?

Operators are an essential component of computer programming, as it allows the program to make decisions. Understanding the order of precedence allows us to know how a program will interpret instructions and carry out these instructions. For a comprehensive list of operators, review this article.

2b. Define and use arrays, struct, unions, and enumerations

  1. What is the purpose of a struct and how is it used?
  2. What is the purpose of an enumeration type and how is it used?
  3. What is the purpose of a union type and how is it used?
  4. What is the purpose of an array and how is it used?

A struct is a user-defined type that is used to create an array with multiple data types stored in a single element. To create a struct, use the following format:

typedef struct person_s
{
    char *name;
    int age;
} person_t;

(person_t is the name of the struct.)

To create an instance of the struct, you can declare it in main:

person_t molly;

To review structs, review this page.

An enum is a user-defined type that consists of a set of named constants. It essentially represents list of possible values. Only these values listed in the enum list are considered appropriate values.

typedef enum { GREET, ASK_OK, ASK_STUDY, CELEBRATE } action_type;

You can review enumeration types by reading this page

Review this page for more information on the use of a union.

Arrays are a container that holds a sequence of content of the same data type. To declare an array, you provide a datatype, name and size.

char a[50];

After the array has been declared, you can refer to the array by referencing its index. To review arrays, review Chapter 4 of Programming in C++.

2c. Use pointers

  1. How do you declare a pointer?
  2. How do you de-reference a pointer?
  3. How do you pass a pointer?

Pointers are a way to store data. Instead of referring to the actual value of a dataset, you refer to its address. You then access the value by referring to the pointer to value. For additional information on pointers, refer to this page.

2d. Use the functions of the string class

  1. How do you use string functions to manipulate string variables?

This article lists many of the string functions that can be used. Make sure you understand how to read and interpret this information and correctly apply the information. The substring function, in particular, is very important. The substring retrieves a portion of the string based on the starting index and the length of the the substring.

Unit 2 Vocabulary

This vocabulary list includes terms that might help you with the review items above and some terms you should be familiar with to be successful in completing the final exam for the course.

Try to think of the reason why each term is included.

  • Array
  • Data structure
  • De-reference
  • Enumeration
  • Operator
  • Order of precedence
  • Pointer
  • Self-reference
  • Struct
  • Typedef
  • Union
Last modified: Monday, November 6, 2017, 12:50 PM