# Fundamentals of Programming Test 1 Study Guide This is a group test. The test format will be: - multiple choice - fill in the blank - parsons puzzles - coding questions - short answer questions ## I. Input and Output 1. **Cin and Cout** - `cin` is used for reading input from the standard input (usually the keyboard), while `cout` is used for printing output to the standard output (usually the console). - Input using `cin` is typically followed by variable names, and output using `cout` involves printing literals and variables. ### **cin (Standard Input):** - `cin` is used to read input from the user through the console. - It is linked to the standard input device, which is usually the keyboard. **Example:** ```cpp #include <iostream> using namespace std; int main() { int number; cout << "Enter a number: "; cin >> number; cout << "You entered: " << number << endl; return 0; } ``` In this example, the program prompts the user to enter a number, reads it using `cin`, and then displays the entered number using `cout`. ### **cout (Standard Output):** - `cout` is used to display output to the console. - It is linked to the standard output device, which is usually the console or terminal. **Example:** ```cpp #include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; int age = 25; cout << "My age is: " << age << endl; return 0; } ``` In this example, the program uses `cout` to display the "Hello, World!" message and the value of the `age` variable. The `<<` operator is used with `cout` for output, and the `>>` operator is used with `cin` for input. Additionally, `endl` is used to insert a newline character and flush the output buffer, making the output appear on a new line. Remember to include the `<iostream>` header at the beginning of your program to use `cin` and `cout`. The `using namespace std;` statement allows you to use `cin` and `cout` without explicitly specifying the namespace. 2. **File I/O** - `ifstream` and `ofstream` are classes in C++ for handling input and output operations with files. - Opening a file is done using the `open()` method, and files should be closed using `close()` after usage. - Error handling involves checking whether a file is open before performing read or write operations. In C++, file input and output are facilitated by the use of file streams. Two commonly used classes for file handling are `ifstream` (for file input) and `ofstream` (for file output), both of which are part of the `<fstream>` header in the C++ Standard Library. Here's an explanation of file input and output with example code: ### **File Input (`ifstream`):** - `ifstream` is used for reading data from a file. **Example:** ```cpp #include <iostream> #include <fstream> using namespace std; int main() { ifstream inputFile("example.txt"); if (inputFile.is_open()) { int number; while (inputFile >> number) { cout << "Read from file: " << number << endl; } inputFile.close(); } else { cout << "Unable to open the file." << endl; } return 0; } ``` In this example, the program attempts to open a file named "example.txt" for reading. It then reads integers from the file and displays them on the console. ### **File Output (`ofstream`):** - `ofstream` is used for writing data to a file. **Example:** ```cpp #include <iostream> #include <fstream> using namespace std; int main() { ofstream outputFile("output.txt"); if (outputFile.is_open()) { outputFile << "Hello, File Output!" << endl; outputFile << "This is a new line." << endl; outputFile.close(); cout << "Data has been written to the file." << endl; } else { cout << "Unable to open the file for writing." << endl; } return 0; } ``` In this example, the program opens a file named "output.txt" for writing and then writes two lines of text to the file. Remember to handle file stream errors and close the files after use. Additionally, the file modes can be adjusted by providing additional parameters to the file stream constructors (e.g., `ios::in` for input, `ios::out` for output). The `is_open()` function is often used to check if a file has been successfully opened. Always include the `<fstream>` header to use file stream classes in C++. ## II. Output Manipulation 3. **`iomanip` Library** - The `iomanip` library provides manipulators that allow formatting of output. - `setw` sets the width of the next input or output field, `setprecision` controls the number of digits displayed in floating-point numbers, and `fixed` sets the floating-point display to a fixed number of decimal places. - The manipulator `endl` is used to insert a newline character and flush the output buffer. In C++, the `<iomanip>` header provides several manipulation functions that allow you to control the formatting of output when using streams like `cout`. Here's an explanation of some commonly used manipulation functions along with examples: ### **`setw(int n)` - Set Width:** - Sets the field width for the next output. **Example:** ```cpp #include <iostream> #include <iomanip> using namespace std; int main() { cout << setw(10) << "Hello" << setw(10) << "World" << endl; return 0; } ``` Output: ``` Hello World ``` ### **`setprecision(int n)` - Set Precision:** - Sets the decimal precision for floating-point numbers. **Example:** ```cpp #include <iostream> #include <iomanip> using namespace std; int main() { double pi = 3.141592653589793; cout << setprecision(4) << pi << endl; return 0; } ``` Output: ``` 3.142 ``` ### **`setfill(char c)` - Set Fill Character:** - Sets the fill character for the field. **Example:** ```cpp #include <iostream> #include <iomanip> using namespace std; int main() { cout << setfill('*') << setw(10) << "Hello" << endl; return 0; } ``` Output: ``` *****Hello ``` ### **`left` and `right`:** - `left`: Sets the output alignment to the left. - `right`: Sets the output alignment to the right. **Example:** ```cpp #include <iostream> #include <iomanip> using namespace std; int main() { cout << left << setw(10) << "Left" << right << setw(10) << "Right" << endl; return 0; } ``` Output: ``` Left Right ``` ### **`unsetf` - Unset Flags:** - Unsets the specified format flags. **Example:** ```cpp #include <iostream> #include <iomanip> using namespace std; int main() { cout << setiosflags(ios::hex) << "Hex: " << 255 << endl; cout << unsetf(ios::hex) << "Decimal: " << 255 << endl; return 0; } ``` Output: ``` Hex: ff Decimal: 255 ``` ### **`fixed` and `scientific`:** - `fixed`: Display floating-point numbers in fixed-point notation. - `scientific`: Display floating-point numbers in scientific notation. **Example:** ```cpp #include <iostream> #include <iomanip> using namespace std; int main() { double value = 12345.6789; cout << fixed << value << endl; cout << scientific << value << endl; return 0; } ``` Output: ``` 12345.678900 1.234568e+04 ``` These manipulation functions provide flexibility in formatting output and are useful for controlling the appearance of data in the console. ## III. Simple Data Types 4. **Data Types** - Fundamental data types include integers (`int`), floating-point numbers (`float`, `double`), characters (`char`), and others. - User-defined data types like `struct` and `class` allow the creation of custom data structures. In C++, simple data types, also known as primitive or fundamental data types, represent basic building blocks for storing and manipulating data. These types are used to define variables that hold single values. Here's a detailed explanation of some common simple data types in C++: ### **Integer Types:** - **int:** Represents integer numbers. ```cpp int integerNumber = 42; ``` - **char:** Represents a single character using ASCII values. ```cpp char character = 'A'; ``` - **short:** Represents a short integer. ```cpp short shortInteger = 32767; ``` - **long:** Represents a long integer. ```cpp long longInteger = 123456789L; ``` - **unsigned:** Represents only positive integers (non-negative). ```cpp unsigned int positiveInteger = 100; ``` ### **Floating-Point Types:** - **float:** Represents single-precision floating-point numbers. ```cpp float floatingPointNumber = 3.14f; ``` - **double:** Represents double-precision floating-point numbers (larger range and precision than float). ```cpp double doublePrecisionNumber = 3.1415926535; ``` - **long double:** Represents extended precision floating-point numbers. ```cpp long double extendedPrecisionNumber = 3.14159265358979323846L; ``` ### **Boolean Type:** - **bool:** Represents boolean values, either `true` or `false`. ```cpp bool isTrue = true; bool isFalse = false; ``` ### **Void Type:** - **void:** Represents the absence of a specific type. It's often used as a return type for functions that do not return a value. ```cpp void exampleFunction() { // Some code } ``` ### **Wide Character Type:** - **wchar_t:** Represents wide characters (larger character set than char, often used for internationalization). ```cpp wchar_t wideCharacter = L'€'; ``` These simple data types are essential for defining variables and handling various kinds of data in C++ programs. It's important to choose the appropriate data type based on the range and precision required for a particular variable. For example, using `int` for whole numbers, `float` or `double` for floating-point numbers, and `bool` for true/false conditions. Additionally, the `sizeof` operator can be used to determine the size of a variable in bytes. ## IV. Operators 5. **Arithmetic and Assignment Operators** - Basic arithmetic operators (`+`, `-`, `*`, `/`, `%`) perform addition, subtraction, multiplication, division, and modulo operations, respectively. - Assignment operators (`=`, `+=`, `-=`, `*=`, `/=`) assign values to variables, and compound assignment operators combine assignment with arithmetic operations. ```cpp #include <iostream> using namespace std; int main() { // Arithmetic operators: +, -, *, /, % // Addition int sum = 5 + 7; cout << "Sum: " << sum << endl; // Subtraction int difference = 10 - 3; cout << "Difference: " << difference << endl; // Multiplication int product = 4 * 6; cout << "Product: " << product << endl; // Division float quotient = 15.0 / 2; cout << "Quotient: " << quotient << endl; // Modulus (remainder) int remainder = 17 % 5; cout << "Remainder: " << remainder << endl; // Increment and Decrement int number = 8; cout << "Original Number: " << number << endl; // Increment by 1 number++; cout << "After Increment: " << number << endl; // Decrement by 1 number--; cout << "After Decrement: " << number << endl; // Compound Assignment Operators int value = 10; value += 5; // equivalent to value = value + 5; cout << "Updated Value: " << value << endl; return 0; } ``` In this example: - The program performs addition, subtraction, multiplication, and division using the basic arithmetic operators (`+`, `-`, `*`, `/`). - The modulus operator (`%`) calculates the remainder of the division. - Increment (`++`) and decrement (`--`) operators are used to increase or decrease the value of a variable by 1. - Compound assignment operators (`+=`) are demonstrated for shorthand assignment with addition. When you run this program, it will output the results of the arithmetic operations and demonstrate the use of different arithmetic operators in C++. 6. **Logical Operators** - Logical operators (`&&`, `||`, `!`) are used to perform logical AND, OR, and NOT operations. 7. **Relational Operators** - Relational operators (`<`, `>`, `<=`, `>=`, `==`, `!=`) are used to compare values and return boolean results. 8. **Pre/Post Increment** In C++, both pre-increment and post-increment are unary operators used to increase the value of a variable by 1. However, they have a crucial difference in when the increment takes place concerning the expression involving the variable. ### **Pre-increment (`++variable`):** - In pre-increment, the value of the variable is increased before the expression is evaluated. - The incremented value is used in the expression. **Example:** ```cpp #include <iostream> using namespace std; int main() { int num = 5; // Pre-increment int result = ++num; cout << "Result: " << result << endl; // Output: 6 cout << "Original num: " << num << endl; // Output: 6 return 0; } ``` ### **Post-increment (`variable++`):** - In post-increment, the current value of the variable is used in the expression before the increment takes place. - The variable is increased after the expression is evaluated. **Example:** ```cpp #include <iostream> using namespace std; int main() { int num = 5; // Post-increment int result = num++; cout << "Result: " << result << endl; // Output: 5 cout << "Original num: " << num << endl; // Output: 6 return 0; } ``` In both examples, the variable `num` is initially set to 5. After the increment operation, `num` becomes 6. The crucial distinction lies in the value used in the expression and when the increment occurs. - In pre-increment (`++num`), the value is increased before being used in the expression. - In post-increment (`num++`), the original value is used in the expression, and the increment occurs afterward. Understanding the difference between pre-increment and post-increment is essential, especially in situations where the order of operations matters. ## V. Variables 9. **Declaration and Initialization** - Variables must be declared before use, specifying the data type. Initialization is assigning a value to a variable at the time of declaration. ### **Variable Declaration:** - Variables must be declared before use, specifying the data type and an optional initial value. ```cpp int age; // Declaration of an integer variable double salary; // Declaration of a double-precision floating-point variable char grade = 'A'; // Declaration and initialization of a character variable ``` ### **Variable Initialization:** - Variables can be initialized at the time of declaration, providing an initial value. ```cpp int count = 10; // Initialization of an integer variable float pi = 3.14f; // Initialization of a single-precision floating-point variable ``` ### **Variable Assignment:** - After declaration, variables can be assigned new values during the execution of the program. ```cpp age = 25; // Assigning a new value to the 'age' variable salary = 50000.5; // Assigning a new value to the 'salary' variable ``` ### **Data Types:** - C++ supports various data types, including int, float, double, char, bool, etc., each with its own size and range. ```cpp int integerNumber = 42; double pi = 3.14159; char grade = 'A'; bool isTrue = true; ``` ### **Scope of Variables:** - The scope of a variable defines where it is accessible within the program. - Local variables are defined within a specific block or function, while global variables are accessible throughout the entire program. ```cpp int globalVar = 100; // Global variable int main() { int localVar = 50; // Local variable within the main function // ... return 0; } ``` 10. **Constants** - Constants are declared using the `const` keyword and cannot be modified once defined. In C++, a variable is a named storage location in the computer's memory that holds a value. Variables provide a way to store and manipulate data within a program. C++ allows the use of various data types to define variables, each with its own set of characteristics and limitations. Additionally, C++ supports the use of constants, which are variables whose values cannot be changed once assigned. Here's a detailed explanation of variables and constants in C++: ### **Constant Declaration:** - Constants are declared using the `const` keyword. ```cpp const int MAX_VALUE = 100; const double PI = 3.14159; ``` ### **Advantages of Constants:** - Constants provide a way to define values that should not be changed during the program's execution. - They make the code more readable and help prevent accidental modification of critical values. ```cpp const float TAX_RATE = 0.08; ``` ### **Enumerations (Enum):** - Enums allow the creation of named constant values. ```cpp enum Days { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }; ``` ```cpp Days today = Wednesday; ``` ### **Literal Constants:** - Literal constants are directly used in the code without being assigned a name. ```cpp double circumference = 2 * 3.14159 * radius; ``` Understanding variables and constants is fundamental to programming in C++. Proper use of data types and constants enhances code clarity, maintainability, and helps prevent errors. ## VI. Type Conversion 11. **Implicit and Explicit Type Conversion** - Implicit type conversion occurs automatically when assigning values of different types. - Explicit type conversion involves the programmer explicitly converting a value from one type to another using casting, e.g., `static_cast`. In C++, type conversion refers to the process of converting a value from one data type to another. It's essential to understand type conversions, as they can occur implicitly (automatically by the compiler) or explicitly (manually specified by the programmer). Type conversions are classified into two main categories: implicit conversions and explicit conversions. ### Implicit Type Conversions (Type Coercion): 1. **Promotion:** - Occurs when a value of a smaller data type is automatically converted to a larger data type without loss of information. ```cpp int integerNumber = 42; double doubleNumber = integerNumber; // Implicit conversion (int to double) ``` 2. **Demotion:** - Involves automatically converting a value of a larger data type to a smaller data type. This may result in loss of information. ```cpp double pi = 3.14159; int truncatedPi = pi; // Implicit conversion (double to int, information loss) ``` ### Explicit Type Conversions: 1. **C-style Cast:** - Traditional C-style casting can be used, but it's not recommended in C++ due to potential risks and lack of clarity. ```cpp double pi = 3.14159; int truncatedPi = (int)pi; // C-style cast (double to int) ``` 2. **Functional Cast (static_cast):** - The `static_cast` operator is a safer and more explicit way to perform type conversions in C++. It is checked at compile-time for validity. ```cpp double pi = 3.14159; int truncatedPi = static_cast<int>(pi); // static_cast (double to int) ``` **Example:** ```cpp #include <iostream> using namespace std; int main() { double pi = 3.14159; int truncatedPi = static_cast<int>(pi); cout << "Original Pi: " << pi << endl; cout << "Truncated Pi: " << truncatedPi << endl; return 0; } ``` In this example, the `static_cast` operator is used to explicitly convert the double value of `pi` to an integer, resulting in the truncation of the decimal part. This type of casting is preferred in modern C++ as it provides better type safety and makes the code more readable. ### When to Use `static_cast`: - Use `static_cast` when the conversion is well-defined and safe. - Prefer `static_cast` for most numeric conversions to indicate explicit intent. - Use `static_cast` for converting pointers and references. - Avoid C-style casts for type conversions in C++ to ensure safer code. Type conversions play a crucial role in C++ programming, and understanding when and how to use them is essential for writing correct and maintainable code. `static_cast` is a recommended approach for explicit type conversions in C++. ## VII. Input Functions 12. **`cin.get()`, `getline()`, `ignore()`, `putback()`, and `peek()`** - `cin.get()` reads a single character, `getline()` reads a line of text, `ignore()` skips a specified number of characters, `putback()` puts a character back into the input stream, and `peek()` allows you to check the next character without consuming it. In C++, the standard input and output streams (`cin` and `cout`) provide several member functions for handling input. Here's a detailed description of some commonly used input functions: `get`, `getline`, `peek`, `ignore`, and `putback`, along with sample code for each. ### **get() Function:** - The `get()` function is used to read a single character from the input stream. ```cpp #include <iostream> using namespace std; int main() { char ch; cout << "Enter a character: "; ch = cin.get(); cout << "You entered: " << ch << endl; return 0; } ``` ### **getline() Function:** - The `getline()` function is used to read a line of text from the input stream. ```cpp #include <iostream> #include <string> using namespace std; int main() { string input; cout << "Enter a line of text: "; getline(cin, input); cout << "You entered: " << input << endl; return 0; } ``` ### **peek() Function:** - The `peek()` function is used to look at the next character in the input stream without removing it from the stream. ```cpp #include <iostream> using namespace std; int main() { char ch; cout << "Enter a character: "; ch = cin.peek(); cout << "You entered: " << ch << endl; return 0; } ``` ### **ignore() Function:** - The `ignore()` function is used to skip characters in the input stream up to a specified delimiter or a specified number of characters. ```cpp #include <iostream> using namespace std; int main() { char ch; cout << "Enter a sentence: "; cin.ignore(5, ' '); // Ignore up to 5 characters or until a space is encountered cin.get(ch); cout << "First non-ignored character: " << ch << endl; return 0; } ``` ### **putback() Function:** - The `putback()` function is used to put a character back into the input stream. ```cpp #include <iostream> using namespace std; int main() { char ch1, ch2; cout << "Enter two characters: "; ch1 = cin.get(); cin.putback(ch1); ch2 = cin.get(); cout << "Characters entered: " << ch1 << " and " << ch2 << endl; return 0; } ``` These input functions provide flexibility when reading user input in a C++ program. They are particularly useful for handling various scenarios, such as reading single characters, entire lines, or peeking at the next character without consuming it. It's important to note that these functions can be combined to create more complex input processing logic. ### Example: Using getline with the Third Parameter and Reading from a File Suppose you have a file named "sample.txt" with the following content: ``` John Doe:25 Engineering ``` Now, let's write a C++ program to read this file using getline and handle the transition between >> and getline using ignore: ```cpp #include <iostream> #include <fstream> #include <string> using namespace std; int main() { ifstream inputFile("sample.txt"); if (!inputFile.is_open()) { cerr << "Error opening the file." << endl; return 1; } string name; int age; string department; // Reading the name using getline with a custom delimiter ':' getline(inputFile, name, ':'); // Reading the age using >> inputFile >> age; // Ignore the newline character after the age inputFile.ignore(); // Reading the department using getline getline(inputFile, department); // Displaying the information cout << "Name: " << name << endl; cout << "Age: " << age << endl; cout << "Department: " << department << endl; inputFile.close(); return 0; } ``` In this example: - `getline(inputFile, name, ':')` reads the name until the colon (':') delimiter is encountered. - `inputFile >> age` reads the age using the stream extraction operator (`>>`). - `inputFile.ignore()` is used to ignore the newline character after reading the age. - `getline(inputFile, department)` reads the department using the default newline delimiter. This example demonstrates a combination of `getline` with a custom delimiter and the use of `ignore` to handle transitions between different input methods when reading from a file. ## VIII. Differentiating between `get()`, `getline()`, and `>>` In C++, `get`, `getline`, and `>>` (cin with stream extraction operator) are methods used for reading input from the standard input stream (`cin`) or other input streams. Each has its own characteristics and use cases: 13. **`get()` Function:** - **Usage:** `cin.get(variable)` - **Description:** - Reads a single character from the input stream, including whitespace characters like spaces and newline characters. - Does not discard leading whitespaces by default. - **Example:** ```cpp char ch; cin.get(ch); ``` - **Note:** - `get` can be used to read characters until a specified delimiter or the end of the line. 14. **`getline()` Function:** - **Usage:** `getline(cin, variable)` - **Description:** - Reads an entire line of text until a newline character (`'\n'`) is encountered or until a specified delimiter is found. - Discards the newline character from the stream. - **Example:** ```cpp string line; getline(cin, line); ``` - **Note:** - `getline` is often used to read entire lines of input, making it suitable for handling strings with spaces. 15. **`cin >> variable` (Stream Extraction Operator):** - **Usage:** `cin >> variable` - **Description:** - Reads data from the input stream until whitespace (space, tab, newline) is encountered. - Skips leading whitespace characters by default. - **Example:** ```cpp int number; cin >> number; ``` - **Note:** - `>>` is commonly used for reading individual values, such as integers or floating-point numbers. **Key Differences:** - `get` reads single characters, including whitespace. - `getline` reads entire lines until a newline character or a specified delimiter. - `>>` reads data until whitespace is encountered, skipping leading whitespaces. **Choosing the Right One:** - Use `get` when you need to process individual characters or when handling custom delimiters. - Use `getline` when reading entire lines of text or when handling strings with spaces. - Use `>>` for reading individual values like integers or floating-point numbers. In summary, the choice between `get`, `getline`, and `>>` depends on the specific requirements of your input data and how you want to handle it in your C++ program. Each method is designed for different scenarios, so choose the one that best fits your needs. ## Practice Questions Below are practice questions for the upcoming test. ### Programming Questions *Questions in Cengage are also a good practice option.* 1. Develop a C++ program to take two numbers as input, calculate and display their sum and product. 2. Write a C++ program that reads data from a file, calculates the average, and outputs the result. The file contains 10 numbers (one per line). 3. Create a C++ program that generates a formatted table of mathematical operations (e.g., addition, subtraction, multiplication) for a range of numbers, utilizing the setw function and other manipulators from the iomanip library to align the columns neatly. The program should take user input for the range of numbers and display the results in a well-organized table format. 4. Design a program that reads a sentence using `getline()` and outputs the number of characters, words, and lines in the sentence. 5. Implement a C++ program that uses file I/O to copy the contents of one file to another. The original file contains 2 lines with spaces. 6. Create a C++ program that reads the initial quantity and cost price of three different products from a file. Calculate the total value of each product by multiplying its quantity by the cost price. Determine the selling price for each product with a fixed profit margin of 20%. Display the product details, including the initial quantity, cost price, total value, and selling price, in a formatted table. Write this information to an output file for future reference. 7. Write a program that calculates the area of a circle using user input for the radius. 8. Create a C++ program that reads a list of numbers from a file, finds the maximum and minimum values, and outputs them. The file contains 10 integers on one line. 9. Implement a program that converts temperatures between Celsius and Fahrenheit based on user input. ### Short Answer Questions 1. Explain the distinction between `cin`, `get()` and `getline()` in handling input operations. 2. Elaborate on the functionality of the `setw` function from the `iomanip` library and its impact on output formatting. 3. Discuss the importance of type conversion in C++ programming, providing examples. 4. Describe the significance of the `const` keyword in variable declarations and its role in maintaining code integrity. 5. Provide a scenario where file input/output in C++ would be beneficial and explain how it enhances program functionality. ### Multiple-Choice Questions (Choose the correct option) 1. What is the purpose of `ifstream` and `ofstream` in C++? a. String manipulation b. File input/output c. Variable declaration d. Memory allocation 2. Which library provides manipulators for formatting output in C++? a. `<iostream>` b. `<iomanip>` c. `<cmath>` d. `<cstdlib>` 3. What is the role of `setprecision` in the `iomanip` library? a. Sets the width of the output field b. Controls the number of decimal places in floating-point numbers c. Skips characters in the input stream d. Outputs a newline character 4. What does the `const` keyword indicate in a variable declaration? a. It represents a constant integer. b. It denotes a constant character. c. The variable cannot be modified. d. It specifies a constant function. 5. Which operator is used for the modulo operation in C++? a. `%` b. `*` c. `/` d. `^` 6. What is the purpose of the `peek()` function in C++? a. Reads a single character from the input stream b. Skips a specified number of characters c. Checks the next character without consuming it d. Puts a character back into the input stream 7. What is the difference between `cin.get()` and `getline()`? a. `cin.get()` reads a line of text, while `getline()` reads a single character. b. `cin.get()` reads a single character, while `getline()` reads a line of text. c. There is no difference; they are interchangeable. d. `cin.get()` and `getline()` perform the same function. 8. In C++, how is explicit type conversion achieved? a. Automatically during assignments b. Using the `static_cast` keyword c. By using the `auto` keyword d. Implicitly during arithmetic operations 9. Which of the following is a compound assignment operator in C++? a. `=` b. `==` c. `+=` d. `\=` 10. What is the purpose of the `ignore()` function in C++? a. Ignores any characters in the output stream. b. Ignores a specified number of characters in the input stream. c. Puts a character back into the input stream. d. Reads a single character from the input stream.