Home C++ Learning Setup C++ Basics Foundations Core Intermediate Advanced Professional Systems Expert Practice Fundamentals Tasks First C++ Lesson C++ Get Started C++ Syntax Statements C++ Output Print Text New Lines Comments Variables Format Output Change Values Multiple Variables Variable Names Real-Life Variables Data Types Characters Numbers Decimal Precision sizeof Type Real-Life Extended Types Type Conversion Constants Operators Arithmetic Assignment Comparison Logical Booleans Precedence If If Else Else If Short If Switch While Do While C++ Help Login

BYTE FORGE EDU / C++ Learning Track

C++ Lessons

Build on C-style command line learning and move into C++ streams, strings, vectors, functions, classes, and structured beginner projects.

Track: C++ Programming
Compiler: Clang++
Main folder: cpp_lessons
Lesson files use cpp_topic_number prefix

Setup And First C++ Program

These lessons prepare the student to understand C++ source files, compile with Clang++, and run programs in CMD.

001 - What Is C++?

C++ is a compiled programming language used for command line tools, games, desktop software, systems, and larger structured projects.

002 - C++ Work Files

Source files, folders, file extensions, and how C++ lesson materials are stored.

cpp_workfiles_002
003 - First C++ Program

Create a small program with main, cout, and return 0.

cpp_firstprogram_003
004 - Compile With Clang++

Compile a .cpp file into an .exe file using Clang++.

cpp_compileclang_004
005 - Run EXE In CMD

Run the compiled C++ program and read its output in the command prompt.

cpp_runexe_005
006 - Compiler Errors

Learn how to read simple C++ compiler errors and fix one problem at a time.

cpp_errors_006
015 - C++ Get Started

Prove the full source file, Clang++, EXE, and CMD output workflow from one simple task package.

016 - C++ Syntax

Build the visible C++ program skeleton: include line, main, braces, statements, and return 0.

017 - Statements

Learn that a C++ program is made from statements and that simple statements usually end with semicolons.

018 - C++ Output

Use visible output as the first proof that the C++ program ran correctly.

019 - Print Text

Print exact text labels with std::cout.

020 - New Lines

Use newline characters so C++ output stays readable line by line.

021 - Comments

Add simple comments that explain the code for humans.

022 - Create Variables

Create simple integer variables and print their values.

023 - Format Output

Print integer values clearly with std::cout and readable labels.

024 - Change Values

Change a variable after it was created and print both the start and final value.

025 - Multiple Variables

Create and print more than one variable in the same program.

026 - Variable Names

Use readable variable names that explain what the value means.

027 - Real-Life Variables

Connect variable names to practical values like temperature and score.

028 - Data Types

Use int, char, and float in one small beginner program.

029 - Characters

Store and print one-character values with char.

030 - Numbers

Compare whole-number and decimal-number values in C++.

031 - Decimal Precision

Print the same decimal value with different precision settings.

032 - sizeof

Inspect how many bytes common data types use.

033 - Type Real-Life

Match real values like score, grade, and temperature to suitable data types.

034 - Extended Types

Use long and double in one beginner-friendly program.

035 - Type Conversion

Convert one value between basic types and compare the printed result.

036 - Constants

Use const values when data should stay fixed.

037 - Operators Overview

Understand operators as symbols that act on values and variables.

038 - Arithmetic Operators

Practice add, subtract, multiply, and divide in one small report.

039 - Assignment Operators

Use = and short update forms like += for small value changes.

040 - Comparison Operators

Compare values and print true or false style results.

041 - Logical Operators

Combine conditions with AND, OR, and NOT checks.

042 - Booleans

Store and print true/false style values with bool.

043 - Operator Precedence

See how brackets change expression order and final results.

044 - If

Run a code block only when a condition is true.

045 - If Else

Choose between two result paths from one condition.

046 - Else If

Check several conditions in order and stop on the first match.

047 - Short Hand If

Use the ternary operator as a short form for choosing one of two values.

048 - Switch

Select one branch from fixed integer cases.

049 - While Loop

Repeat code while the loop condition stays true.

050 - Do While Loop

Run the loop body first and check the stop condition after it.

C++ Basics

The first C++ syntax lessons. Each item will become its own lesson page and downloadable code files.

007 - cout / cin

Print text and read input using C++ streams.

cpp_coutcin_007
008 - Variables

Store numbers, text, boolean values, and simple data.

cpp_variables_008
009 - If / Else

Make decisions with conditions and comparison operators.

cpp_ifelse_009
010 - Loops

Repeat code with while, for, and do while.

cpp_loops_010
011 - Functions

Split programs into reusable blocks.

cpp_functions_011
012 - Arrays

Store fixed-size groups of values.

cpp_arrays_012
013 - string

Work with text using the C++ string type.

cpp_string_013
014 - vector

Store lists that can grow while the program runs.

cpp_vector_014
015 - Classes

Group data and functions into simple objects.

cpp_classes_015
016 - Files

Write and read simple text files.

cpp_files_016

C++ Practice Projects

After syntax lessons, these projects can use the same C++ folders and file prefix system.

Student Profile Program

Use variables, string, input, and formatted output.

Calculator With Functions

Use functions, numbers, and menu logic.

Quiz With vector

Use vector, score, and repeated questions.

Contact List

Use string, vector, and simple records.

Inventory Program

Use classes or structs to organize items.

Console Game Menu

Use loops, functions, and game state.

C++ Fundamentals Task Catalog

These exercises establish the C++ foundation needed before templates, advanced classes, dynamic memory ownership, libraries, engines, operating-system work, and embedded development. C++ carries low-level control forward from C while adding stronger types, streams, strings, containers, classes, and reusable abstractions.

1.a CHAR VARIABLES AND ASCII BASICS

CHAR
What is learned: CHAR VARIABLES AND ASCII BASICS
Why it matters: Characters and bytes are used for text, device commands, serial data, protocols, and memory-level processing.

  • 1.a1
    Declare one "char" variable, store letter "A", and print it with "std::cout".
  • 1.a2
    Declare three "char" variables, store initials, and print them on one line.
  • 1.a3
    Store one digit as a character, print the character and then print its ASCII code as integer.
  • 1.a4
    Read one character from keyboard and print "You typed: X".
  • 1.a5
    Read two characters and print them in reverse order.
  • 1.a6
    Store lowercase letter and print its uppercase variant using ASCII math.
  • 1.a7
    Store uppercase letter and print its lowercase variant using ASCII math.
  • 1.a8
    Check if a character is between "A-Z", "a-z", or "0-9".
  • 1.a9
    Print a small ASCII table from code 65 to 90.
  • 1.a10
    Make a program that reads one character and tells if it is vowel or consonant.

2.a INTEGER VARIABLES AND BASIC ARITHMETIC

INT
What is learned: INTEGER VARIABLES AND BASIC ARITHMETIC
Why it matters: Integers are used for counters, indexes, timing, states, measurements, containers, and control decisions.

  • 2.a1
    Declare two "int" variables and print their sum.
  • 2.a2
    Read two integers and print sum, subtraction, multiplication, and division.
  • 2.a3
    Read one integer and print its square and cube.
  • 2.a4
    Read three integers and print the largest one.
  • 2.a5
    Read three integers and print the smallest one.
  • 2.a6
    Swap two integers using a third variable and print before and after.
  • 2.a7
    Swap two integers without a third variable.
  • 2.a8
    Read one integer and check if it is even or odd.
  • 2.a9
    Read one integer and check if it is positive, negative, or zero.
  • 2.a10
    Read seconds as integer and convert to hours, minutes, and seconds.

3.a FLOAT VARIABLES AND SIMPLE REAL NUMBER TASKS

FLOAT
What is learned: FLOAT VARIABLES AND SIMPLE REAL NUMBER TASKS
Why it matters: Float values support sensors, physics, graphics, simulation, control systems, and engineering calculations.

  • 3.a1
    Declare one "float" variable and print it with "std::fixed" and "std::setprecision(2)".
  • 3.a2
    Read two "float" values and print their sum and average.
  • 3.a3
    Read rectangle width and height as "float" and print area and perimeter.
  • 3.a4
    Read circle radius as "float" and print diameter, circumference, and area.
  • 3.a5
    Read temperature in Celsius and print Fahrenheit.
  • 3.a6
    Read temperature in Fahrenheit and print Celsius.
  • 3.a7
    Read speed and time, then print distance.
  • 3.a8
    Read base and height of triangle and print area.
  • 3.a9
    Read three "float" values and print the largest one.
  • 3.a10
    Read item price and quantity, then print total price with "std::fixed" and "std::setprecision(2)".

4.a UNSIGNED CHAR AS A SMALL NUMBER AND BYTE

UNSIGNED INTEGER TYPES
What is learned: UNSIGNED CHAR AS A SMALL NUMBER AND BYTE
Why it matters: Unsigned integers represent bytes, flags, registers, sizes, colors, network fields, and hardware states.

  • 4.a1
    Declare "unsigned char" with value 255 and print it as a number.
  • 4.a2
    Declare "unsigned char" with value 0 and increment it ten times.
  • 4.a3
    Read a number from 0 to 255 into an "unsigned int", convert it to "unsigned char", and print it.
  • 4.a4
    Store an ASCII code in "unsigned char" and print both the number and character.
  • 4.a5
    Use "unsigned char" as a byte and print it in decimal and hexadecimal.
  • 4.a6
    Store red, green, and blue values in three "unsigned char" variables.
  • 4.a7
    Add two small "unsigned char" values and print the result as "unsigned int".
  • 4.a8
    Test whether bit 0 of an "unsigned char" value is set.
  • 4.a9
    Set, clear, and toggle one bit in an "unsigned char" value.
  • 4.a10
    Read four byte values and print them as fake IPv4 format "a.b.c.d".

4.b UNSIGNED INT FOR NON-NEGATIVE WHOLE NUMBERS

UNSIGNED INTEGER TYPES
What is learned: UNSIGNED INT FOR NON-NEGATIVE WHOLE NUMBERS
Why it matters: Unsigned integers represent bytes, flags, registers, sizes, colors, network fields, and hardware states.

  • 4.b1
    Declare one "unsigned int" and print it with "std::cout".
  • 4.b2
    Read one positive number into "unsigned int" and print it.
  • 4.b3
    Read two "unsigned int" values and print their sum.
  • 4.b4
    Read two "unsigned int" values and print product and division.
  • 4.b5
    Subtract a bigger unsigned number from a smaller one and observe the result.
  • 4.b6
    Print the maximum "unsigned int" value by using "std::numeric_limits<unsigned int>::max()" from "<limits>".
  • 4.b7
    Use "unsigned int" for a counting loop from 0 to 20.
  • 4.b8
    Read an "unsigned int" and classify it as 0-100, 101-1000, or above 1000.
  • 4.b9
    Use an "unsigned int" as a bit-field value and test its first eight bits.
  • 4.b10
    Read file size in bytes as "unsigned int" and convert it to kilobytes and remaining bytes.

5.a MORE PRECISION THAN FLOAT

DOUBLE
What is learned: MORE PRECISION THAN FLOAT
Why it matters: Double precision is important for accurate calculations, simulation, science, and engineering software.

  • 5.a1
    Declare one "double" value and print it with "std::fixed" and "std::setprecision(6)".
  • 5.a2
    Read two "double" values and print sum, difference, product, and division.
  • 5.a3
    Read resistor voltage and current as "double" and print power using "P = U * I".
  • 5.a4
    Read length, width, and height as "double" and print box volume.
  • 5.a5
    Read loan amount, interest percent, and print one-year result.
  • 5.a6
    Compare same value stored in "float" and "double" and print both.
  • 5.a7
    Read three "double" values and print their average with "std::setprecision(4)".
  • 5.a8
    Convert millimeters to meters using "double".
  • 5.a9
    Read analog sensor value as "double" and print if it is below, inside, or above allowed range.
  • 5.a10
    Read frequency and period values and verify relation with simple calculations.

6.a PLUS, MINUS, MULTIPLY, DIVIDE, MODULO

BASIC OPERATORS
What is learned: PLUS, MINUS, MULTIPLY, DIVIDE, MODULO
Why it matters: Arithmetic operators power calculations, conversions, timers, counters, game rules, and control algorithms.

  • 6.a1
    Read two integers and print "a+b".
  • 6.a2
    Read two integers and print "a-b".
  • 6.a3
    Read two integers and print "a*b".
  • 6.a4
    Read two integers and print integer division and remainder.
  • 6.a5
    Make a calculator that uses one operator character "+ - * /".
  • 6.a6
    Read one number and increment it with "++", then print.
  • 6.a7
    Read one number and decrement it with "--", then print.
  • 6.a8
    Use "+=", "-=", "*=", "/=" on one variable and print after each step.
  • 6.a9
    Read one number and print "number % 10" to get last digit.
  • 6.a10
    Read one 3-digit integer and print sum of its digits.

7.a COMPARISONS AND DECISIONS

RELATIONAL AND LOGICAL OPERATORS
What is learned: COMPARISONS AND DECISIONS
Why it matters: Comparisons, logical operators, and bool values control program flow, safety conditions, menus, and machine states.

  • 7.a1
    Read two integers and print if first is greater than second.
  • 7.a2
    Read two integers and print if they are equal or not equal.
  • 7.a3
    Read age and print if person is adult.
  • 7.a4
    Read one number and check if it is between 10 and 99.
  • 7.a5
    Read one year and check if it is leap year with simple rules.
  • 7.a6
    Read username length and password length values and check if both meet minimum size.
  • 7.a7
    Read exam score and attendance percent and print if student passes.
  • 7.a8
    Read temperature and humidity and print if greenhouse alarm should be on.
  • 7.a9
    Read three side lengths and check if they can form a triangle.
  • 7.a10
    Read work voltage and current state and print if machine can start.

7.b LOGICAL AND, OR, AND NOT

RELATIONAL AND LOGICAL OPERATORS
What is learned: LOGICAL AND, OR, AND NOT
Why it matters: Comparisons, logical operators, and bool values control program flow, safety conditions, menus, and machine states.

  • 7.b1
    Read two integer conditions and print the result of "condition1 && condition2".
  • 7.b2
    Read two integer conditions and print the result of "condition1 || condition2".
  • 7.b3
    Read one integer condition and print the result of "!condition".
  • 7.b4
    Make and print the full truth table for logical AND "&&".
  • 7.b5
    Make and print the full truth table for logical OR "||".
  • 7.b6
    Read age and permission state and allow entry only when both are valid.
  • 7.b7
    Read alarm state and emergency state and activate warning when either is true.
  • 7.b8
    Read one value and use logical NOT to detect zero.
  • 7.b9
    Combine "&&", "||", and "!" in one machine-start condition with parentheses.
  • 7.b10
    Compare logical operators with bitwise operators using values 0, 1, 2, and 3.

7.c C++ BOOL VALUES

RELATIONAL AND LOGICAL OPERATORS
What is learned: C++ BOOL VALUES
Why it matters: Comparisons, logical operators, and bool values control program flow, safety conditions, menus, and machine states.

  • 7.c1
    Declare one "bool" value as "true" and print it as 1.
  • 7.c2
    Print "true" and "false" with "std::boolalpha".
  • 7.c3
    Read an integer and store the comparison "value > 0" in a "bool" variable.
  • 7.c4
    Store an equality comparison in "bool" and print the result.
  • 7.c5
    Toggle one "bool" value with logical NOT.
  • 7.c6
    Combine two "bool" values with logical AND.
  • 7.c7
    Combine two "bool" values with logical OR.
  • 7.c8
    Use a "bool" variable to represent a hardware input state.
  • 7.c9
    Use three "bool" values for power, safety, and start permission.
  • 7.c10
    Print a small machine-status report using "std::boolalpha".

8.a SHIFT LEFT, SHIFT RIGHT, AND MASKS

BITWISE SHIFTS AND BITWISE BASICS
What is learned: SHIFT LEFT, SHIFT RIGHT, AND MASKS
Why it matters: Bitwise operations control flags, registers, packed data, permissions, protocols, and embedded hardware.

  • 8.a1
    Store number 1 and shift it left by 1, 2, 3, and 4 positions.
  • 8.a2
    Store number 128 and shift it right by 1, 2, 3 positions.
  • 8.a3
    Read one integer and print result of "value << 1".
  • 8.a4
    Read one integer and print result of "value >> 1".
  • 8.a5
    Use bitwise AND to check if a number is odd or even.
  • 8.a6
    Store one byte value and test if bit 0 is set.
  • 8.a7
    Store one byte value and test if bit 7 is set.
  • 8.a8
    Set bit 3 in a value using OR.
  • 8.a9
    Clear bit 2 in a value using AND with mask.
  • 8.a10
    Toggle bit 4 in a value using XOR.

8.b BITWISE AND

BITWISE SHIFTS AND BITWISE BASICS
What is learned: BITWISE AND
Why it matters: Bitwise operations control flags, registers, packed data, permissions, protocols, and embedded hardware.

  • 8.b1
    Calculate "12 & 10" and print the decimal result.
  • 8.b2
    Print two input values and their bitwise AND result in decimal and hexadecimal.
  • 8.b3
    Use "value & 1" to check if an integer is odd or even.
  • 8.b4
    Use a mask to read bit 0 from an "unsigned char" value.
  • 8.b5
    Use a mask to read bit 3 from an "unsigned char" value.
  • 8.b6
    Keep only the lower four bits of an "unsigned char" value.
  • 8.b7
    Keep only the upper four bits of an "unsigned char" value.
  • 8.b8
    Clear bit 2 with an AND mask.
  • 8.b9
    Compare "char", "unsigned char", and "unsigned int" AND results after conversion.
  • 8.b10
    Read a machine-state byte and print which masked input bits are active.

8.c BITWISE OR

BITWISE SHIFTS AND BITWISE BASICS
What is learned: BITWISE OR
Why it matters: Bitwise operations control flags, registers, packed data, permissions, protocols, and embedded hardware.

  • 8.c1
    Calculate "12 | 10" and print the decimal result.
  • 8.c2
    Print two input values and their bitwise OR result in decimal and hexadecimal.
  • 8.c3
    Set bit 0 in an "unsigned char" value.
  • 8.c4
    Set bit 3 in an "unsigned char" value.
  • 8.c5
    Set two bits at the same time with one OR mask.
  • 8.c6
    Combine two non-overlapping status masks into one value.
  • 8.c7
    Add a READ permission bit to a permission value.
  • 8.c8
    Add WRITE and EXECUTE permission bits to a permission value.
  • 8.c9
    Combine four digital input states into one "unsigned int" state value.
  • 8.c10
    Build one output-control byte by setting selected motor, lamp, and alarm bits.

8.d BITWISE XOR

BITWISE SHIFTS AND BITWISE BASICS
What is learned: BITWISE XOR
Why it matters: Bitwise operations control flags, registers, packed data, permissions, protocols, and embedded hardware.

  • 8.d1
    Calculate "12 ^ 10" and print the decimal result.
  • 8.d2
    Print two input values and their bitwise XOR result in decimal and hexadecimal.
  • 8.d3
    Toggle bit 0 in an "unsigned char" value.
  • 8.d4
    Toggle bit 4 in an "unsigned int" value.
  • 8.d5
    Toggle two selected bits with one XOR mask.
  • 8.d6
    Apply the same XOR mask twice and verify that the original value returns.
  • 8.d7
    Compare two bytes with XOR and print whether any bit is different.
  • 8.d8
    Count changed low-order bits between two small integer values.
  • 8.d9
    Use XOR to invert selected output-state bits without changing the others.
  • 8.d10
    Build a small two-value XOR demonstration table.

8.e BITWISE NOT

BITWISE SHIFTS AND BITWISE BASICS
What is learned: BITWISE NOT
Why it matters: Bitwise operations control flags, registers, packed data, permissions, protocols, and embedded hardware.

  • 8.e1
    Apply "~" to an "unsigned char" value and print the converted byte result.
  • 8.e2
    Apply "~" to an "unsigned int" value and print decimal and hexadecimal results.
  • 8.e3
    Invert all eight bits of one byte value.
  • 8.e4
    Create a clear-bit mask by using NOT on a one-bit mask.
  • 8.e5
    Clear bit 0 with "value & ~(1u << 0)".
  • 8.e6
    Clear bit 5 with "value & ~(1u << 5)".
  • 8.e7
    Invert only the lower four bits while preserving the upper four bits.
  • 8.e8
    Compare logical NOT "!" with bitwise NOT "~" for values 0 and 1.
  • 8.e9
    Print an original mask and its bitwise complement in hexadecimal.
  • 8.e10
    Use a complemented mask to disable selected machine-output bits.

8.f LEFT AND RIGHT SHIFT

BITWISE SHIFTS AND BITWISE BASICS
What is learned: LEFT AND RIGHT SHIFT
Why it matters: Bitwise operations control flags, registers, packed data, permissions, protocols, and embedded hardware.

  • 8.f1
    Shift "unsigned char" value 1 left from bit 0 through bit 7.
  • 8.f2
    Shift "unsigned int" value 1 left by 1, 4, 8, and 16 positions.
  • 8.f3
    Shift byte value 128 right until it becomes zero.
  • 8.f4
    Compare multiplication by 2 with a one-position left shift for safe small values.
  • 8.f5
    Compare division by 2 with a one-position right shift for positive integers.
  • 8.f6
    Build a mask for a user-selected bit position with "1u << position".
  • 8.f7
    Extract bits 4 through 7 from an "unsigned int" using shift and AND.
  • 8.f8
    Place a four-bit value into bits 8 through 11 using shift and OR.
  • 8.f9
    Combine two "unsigned char" values into one "unsigned int" word.
  • 8.f10
    Split one "unsigned int" word into high and low byte values.

8.g COMBINED BITWISE OPERATIONS

BITWISE SHIFTS AND BITWISE BASICS
What is learned: COMBINED BITWISE OPERATIONS
Why it matters: Bitwise operations control flags, registers, packed data, permissions, protocols, and embedded hardware.

  • 8.g1
    Set one bit, test it, toggle it, and clear it in sequence.
  • 8.g2
    Pack four Boolean input states into the first four bits of one byte.
  • 8.g3
    Unpack the first four bits of a byte into four printed ON or OFF states.
  • 8.g4
    Store an RGB332 color value by combining reduced red, green, and blue fields.
  • 8.g5
    Extract red, green, and blue fields from an RGB332 byte.
  • 8.g6
    Build a simple permission byte and test READ, WRITE, and EXECUTE flags.
  • 8.g7
    Compare two machine-state bytes and print changed bits.
  • 8.g8
    Copy selected bits from one integer into another using AND, NOT, and OR.
  • 8.g9
    Rotate an eight-bit value left by one position using shifts and OR.
  • 8.g10
    Make a console bit-tool that can set, clear, toggle, and test one selected bit.

9.a C++ STREAM OUTPUT AND IOMANIP

COUT AND OUTPUT FORMATTING
What is learned: C++ STREAM OUTPUT AND IOMANIP
Why it matters: C++ stream formatting makes diagnostics, tables, logs, measurements, and command-line tools readable.

  • 9.a1
    Print one integer with "std::cout".
  • 9.a2
    Print one unsigned integer with "std::cout".
  • 9.a3
    Print one float using "std::fixed" and "std::setprecision(2)".
  • 9.a4
    Print one double using "std::fixed" and "std::setprecision(4)".
  • 9.a5
    Print one char and its ASCII code using "static_cast<int>".
  • 9.a6
    Print a table with columns name, age, and score using "std::setw".
  • 9.a7
    Align values left and right using "std::left" and "std::right".
  • 9.a8
    Print decimal, hexadecimal, and octal views using "std::dec", "std::hex", and "std::oct".
  • 9.a9
    Print a simple invoice using "std::setw", "std::fixed", and "std::setprecision".
  • 9.a10
    Print sensor values in one formatted machine-status line with C++ streams.

10.a SHORT REAL-WORLD EXERCISES

MIXED BASIC TASKS
What is learned: SHORT REAL-WORLD EXERCISES
Why it matters: Mixed exercises connect C++ language rules into practical programs and reusable problem-solving skills.

  • 10.a1
    Read device name as std::string, then read id as int and print a summary line.
  • 10.a2
    Read voltage, current, and resistance values and print known electrical relations.
  • 10.a3
    Read PLC input byte value and print whether each first 4 bits is ON or OFF.
  • 10.a4
    Read motor runtime in seconds and print hours, minutes, seconds.
  • 10.a5
    Read tank width, length, height and print volume in liters.
  • 10.a6
    Read three exam scores and print average and pass/fail.
  • 10.a7
    Read one ASCII character and print next character in sequence.
  • 10.a8
    Read operator code as unsigned int and print if it is inside allowed range.
  • 10.a9
    Read analog value as double and print scaled engineering value.
  • 10.a10
    Build a mini console report that prints one row with id, name, value, and state.

13.a TYPE SIZE, RANGE, AND LIMITS

MORE BASIC C++ CATEGORIES TO ADD BEFORE DEEP TOPICS
What is learned: TYPE SIZE, RANGE, AND LIMITS
Why it matters: Limits, validated streams, casts, and precedence prevent data loss, invalid state, and low-level defects.

  • 13.a1
    sizeof char, int, float, and double
  • 13.a2
    "std::numeric_limits<char>::min()" and "max()"
  • 13.a3
    "std::numeric_limits<int>::min()" and "max()"
  • 13.a4
    "std::numeric_limits<unsigned int>::max()"
  • 13.a5
    "std::numeric_limits<float>::lowest()" and "max()"
  • 13.a6
    "std::numeric_limits<double>::lowest()" and "max()"
  • 13.a7
    integer overflow observation
  • 13.a8
    unsigned wraparound observation
  • 13.a9
    float precision observation
  • 13.a10
    choose a suitable type for ten example values

13.b CIN AND SAFE BASIC INPUT

MORE BASIC C++ CATEGORIES TO ADD BEFORE DEEP TOPICS
What is learned: CIN AND SAFE BASIC INPUT
Why it matters: Limits, validated streams, casts, and precedence prevent data loss, invalid state, and low-level defects.

  • 13.b1
    Read one "int" with "std::cin".
  • 13.b2
    Read one "unsigned int" with "std::cin".
  • 13.b3
    Read one "float" with "std::cin".
  • 13.b4
    Read one "double" with "std::cin".
  • 13.b5
    Read one "char" with "std::cin".
  • 13.b6
    Read two integers in one "std::cin" statement.
  • 13.b7
    Check whether "std::cin" is in a valid state after input.
  • 13.b8
    Detect invalid input, call "std::cin.clear()", and discard the bad line.
  • 13.b9
    Read one full text line with "std::getline" into "std::string".
  • 13.b10
    Build one validated input and output summary program using C++ streams.

13.c TYPE CONVERSION AND CASTING

MORE BASIC C++ CATEGORIES TO ADD BEFORE DEEP TOPICS
What is learned: TYPE CONVERSION AND CASTING
Why it matters: Limits, validated streams, casts, and precedence prevent data loss, invalid state, and low-level defects.

  • 13.c1
    convert int to float with "static_cast<float>"
  • 13.c2
    compare integer division with floating-point division
  • 13.c3
    convert float to int with "static_cast<int>" and observe removed fractional part
  • 13.c4
    cast one operand with "static_cast<double>" before division
  • 13.c5
    convert char to integer ASCII code with "static_cast<int>"
  • 13.c6
    convert integer ASCII code to char with "static_cast<char>"
  • 13.c7
    convert unsigned char to unsigned int with "static_cast<unsigned int>"
  • 13.c8
    compare implicit conversion with C++ "static_cast"
  • 13.c9
    calculate average without losing the fractional result
  • 13.c10
    identify which conversions may lose data

13.d OPERATOR PRECEDENCE AND EXPRESSIONS

MORE BASIC C++ CATEGORIES TO ADD BEFORE DEEP TOPICS
What is learned: OPERATOR PRECEDENCE AND EXPRESSIONS
Why it matters: Limits, validated streams, casts, and precedence prevent data loss, invalid state, and low-level defects.

  • 13.d1
    compare "a + b * c" with "(a + b) * c"
  • 13.d2
    combine subtraction and division
  • 13.d3
    combine modulo and addition
  • 13.d4
    compare pre-increment and post-increment in separate statements
  • 13.d5
    use parentheses to make calculation order explicit
  • 13.d6
    calculate a percentage expression correctly
  • 13.d7
    calculate Celsius to Fahrenheit with correct numeric types
  • 13.d8
    find and fix an expression with integer division error
  • 13.d9
    split one complex expression into named intermediate variables
  • 13.d10
    print every intermediate result of a mixed expression