Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .idea/editor.xml
Comment thread
Ttiki marked this conversation as resolved.
Resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 20 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 4.3)
project(LearnCPP)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Each exercise has its own main(), so build it as a separate program.
add_executable(LearnCPP c0/helloworld.cpp)
add_executable(Variables c1/Variables.cpp)
add_executable(InitialisationType c1/InitialisationType.cpp)
add_executable(ListInitialisation c1/ListInitialisation.cpp)
add_executable(MaybeUnused c1/MaybeUnused.cpp)
add_executable(cout c1/cout.cpp)
add_executable(cin c1/cin.cpp)
add_executable(buffering c1/buffering.cpp)
add_executable(LiteralsVariables c1/LiteralsVariables.cpp)
add_executable(Expression c1/Expression.cpp)
add_executable(FirstProgram c1/FirstProgram.cpp)
set(CMAKE_CXX_STANDARD 20)

# c0/PrintStandard.cpp contains only comments, so it has no executable target.
add_executable(LearnCPP c0/helloworld.cpp
c0/helloworld.cpp
c0/helloworld.cpp
c0/PrintStandard.cpp
c1/Variables.cpp
c1/Variables.cpp
c1/InitialisationType.cpp
c1/ListInitialisation.cpp
c1/MaybeUnused.cpp
c1/cout.cpp
c1/cin.cpp
c1/buffering.cpp
c1/LiteralsVariables.cpp
c1/Expression.cpp
c1/FirstProgram.cpp
c1/ChapterFinalQuizz.cpp
c1/ChapterFinalQuizz.cpp
)
38 changes: 38 additions & 0 deletions c1/ChapterFinalQuizz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Created by Clément Combier on 05/10/2026.
//

#include <iostream>

int myProgram() {
int x, y {};
std::cout << "Enter an integer:";
std::cin >> x;

std::cout << "Enter another integer:";
std::cin >> y;

std::cout << x + "+" + y + "=" x+y +". \n";
std::cout << x + "-" + y + "=" x-y + ". \n";

return 0;
}

// Solution
int main() {

myProgram();

std::cout << "Enter an integer: ";
int x{};
std::cin >> x;

std::cout << "Enter another integer: ";
int y{};
std::cin >> y;

std::cout << x << " + " << y << " is " << x + y << ".\n";
std::cout << x << " - " << y << " is " << x - y << ".\n";

return 0;
}
8 changes: 4 additions & 4 deletions c1/ListInitialisation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ int main()
// Initializing an int with fractional value 4.5 requires the compiler to convert 4.5 to a value an int can hold.
// Such a conversion is a narrowing conversion, since the fractional part of the value will be lost.

//int w1 { 4.5 }; // compile error: list-init does not allow narrowing conversion
int w1 { 4.5 }; // compile error: list-init does not allow narrowing conversion

//int w2 = 4.5; // compiles: w2 copy-initialized to value 4
//int w3 (4.5); // compiles: w3 direct-initialized to value 4
int w2 = 4.5; // compiles: w2 copy-initialized to value 4
int w3 (4.5); // compiles: w3 direct-initialized to value 4

return 0;
}
}
Loading