From 0deddfabde8a98f2c019672791bd896e439faec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ga=C5=82ecki?= Date: Mon, 19 Oct 2026 13:20:16 +0200 Subject: [PATCH] cs1-lab2 --- cs1_lab02.Rmd | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/cs1_lab02.Rmd b/cs1_lab02.Rmd index 404993e3d..fe94769b9 100644 --- a/cs1_lab02.Rmd +++ b/cs1_lab02.Rmd @@ -5,39 +5,39 @@ material: Instruction 2 --- ## 1. -Write a program using a function which prints: +Write a program which prints `"Hello!"`, using a function: ```c++ #include -void FunView(); // declaration of a function: line ended with semicolon! +void printHello(); // function declaration: line ended with semicolon! int main() // main function { - FunView(); // call the function FunView + printHello(); // call the function printHello return 0; } - // definition of the function FunView -void FunView() // function header: contains return type and name -{ - printf("Hello!"); // function starting bracket -} // function ending bracket + // definition of the function printHello +void printHello() // function header: contains return type and name +{ // function opening bracket + printf("Hello!"); +} // function closing bracket ``` ## 2. Modify the program by adding three new functions. -First function should increment the global variable `Number` by $5$, e.g.: +The first function should increment the global (meaning defined outside of the `main` function) variable `Number` by $5$, e.g.: ```c++ void IncNumber() { Number = Number + 5; // or better: Number += 5; } ``` -Second function should decrement variable `Number` by 3. -Third function should print current value of variable `Number`. -The variable should be declared as global (e.g. after declaration of the function but before the beginning of the main function) and initialize it with $10$. +The second function should decrement the variable `Number` by 3. +The third function should print the current value of variable `Number`. +The variable should be declared as global (e.g. after declaration of the functions but before the beginning of the main function) and initialized with $10$. Remember about proper declaration of the functions. -Inside main function call the function according to the following pattern: +Inside `main`, call the functions according to the following pattern: - print value of the variable `Number`; - increment value of the `Number` by 5 and repeat it three times; @@ -48,7 +48,7 @@ Inside main function call the function according to the following pattern: ## 3. Create a new program which solves the quadratic equation. -Here is a proposition of the program layout: +Here is a suggestion for the program layout: ```c++ #include