- C++ intorduction
- Development environment setup
- Primitive types & variables
- Operators
- Conditions
- Loops
- Functions
Within the .devcontainer
folder, you'll find a file that describes a C++ development environment. By utilizing this file in Visual Studio Code, you can establish a connection to a Linux-based development environment. The steps involved are as follows:
- Make sure you have Docker Desktop installed and running on your computer
- Install the Remote Development extension pack in Visual Studio Code Once the installations are complete, follow these steps:
- Open the Command Palette (usually by pressing Ctrl+Shift+P) and search for
Dev Containers: Clone Repository in Container Volume
- You may need to authorize the extension for GitHub authentication. You will be redirected to your web browser to complete this process
- A development container will be created and started in the background. You may see a terminal window open while the container is being created
In the code, you will find variable declarations that need to be completed with initialized declarations. Please select the appropriate value from the commented line above for each variable.
Write the toChar
function return value so that it converts the asciiValue
variable, which is passed as a parameter, to a char
type using static_cast
operator
The if statement condition shall be true if the currently iterated animal
instance is of type Dog
The if statement condition shall be true if the currently iterated animal
instance is of type Cat
Convert the SignedInt
structure to an UnsignedInt
type using bitwise copying. Can you determine what the value of the unsignedInt->value
member will be?
Observe where and how the result
variable is declared. Initialize it to 0.0 in the main
function
Extend the divide
function so that it throws an exception when attempting to divide by zero
Implement a try-catch
block that calls the divide
function and can catch any exceptions thrown by it
Create a boolean variable that can be used as a condition in the if statement below to determine if a number is even or odd
Create an instance of the class above so that it can be used as a condition in the if statement below to determine if a number is even or odd. This demonstrates that the condition part of an if statement can be an object of a class that can be unambiguously converted to a boolean
Complete the implementation of the selectMenu
function using a switch statement to print out the selected meals. Implement only one meal type per case. Tip: you can use the fallthrough effect here.
Implement a switch statement that can print the day of the week corresponding to a given number (e.g., 1 - Monday, ...). The day number should be the value returned by the getRandomNumber
function. Tip: you can declare and initialize variable within the selection statement itself.
Implement a conditional statement that can determine whether a constant variable holds a positive or negative number
In the main
function, you will find an array containing numbers
. Print the numbers in the array to the console using the following loop types:
- traditional for loop
- do-while loop
- while loop
- range-based for loop
In the main
function, create an instance of the above class to drive a single iteration of the following while loop. The example aims to demonstrate that a loop's condition can be an instance of a class that can be unambiguously converted to a boolean type.
The SimpleArray
class implements a custom container with a fixed size, storing integer values. Implement a range-based for loop to print the elements of the created instance (myArray
). The example illustrates that range-based for loops work with custom containers that define begin()
and end()
methods.
Implement the printMessage
function that takes a string variable as a parameter containing the message
to be printed and an integer times
indicating how many times the message should be printed. If no argument is provided for times
when calling the function, it should print the message once.
Implement the calculatePoint
function that returns a Point
structure with a new point that is shifted 1 unit in the positive direction relative to the input x
and y
values
Implement the calculatePointAndDistance
function that returns a tuple
containing two points derived from the input parameters, with coordinates (x1
, y1
) and (x2
, y2
), as well as the distance between the two points.
Implerment the swap
function that exchanges the values of two variables. The modification should be visible to the caller.
Implement the getLength
function that returns the length of the input string.
Implement the max
function that returns the greater of the input parameters a
and b
. The return type of the function should be deduced from the return expression.
Implement the isVowel
inline function that determines whether the input character is a vowel
Implement the factorial
function that calculates the factorial of the input variable number
. The function can be called with a compile-time constant expression, and call it in the main
function with value 5
Implement the sumElements
function that sums the elements of the input vector. This function should not throw any exceptions
The cleanup
function checks whether the numbers
pointer points to an allocated memory area and, if so, frees the allocated space. Register this function to run before the program terminates normally.