-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathcs1_lab02.Rmd
91 lines (76 loc) · 2.12 KB
/
cs1_lab02.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
number: 2
course: Computer Science 1
material: Instruction 2
---
## 1.
Write a program using a function which prints:
```c++
#include <stdio.h>
void FunView(); // declaration of a function: line ended with semicolon!
int main() // main function
{
FunView(); // call the function FunView
return 0;
}
// definition of the function FunView
void FunView() // function header: contains return type and name
{
printf("Hello!"); // function starting bracket
} // function ending bracket
```
## 2.
Modify the program by adding three new functions.
First function should increment the global 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$.
Remember about proper declaration of the functions.
Inside main function call the function according to the following pattern:
- print value of the variable `Number`;
- increment value of the `Number` by 5 and repeat it three times;
- print value of the variable `Number`;
- decrement value of the `Number` by 3; do it two times;
- increment value of the `Number` by 5;
- print value of the variable `Number`;
## 3.
Create a new program which solves the quadratic equation.
Here is a proposition of the program layout:
```c++
#include <math.h>
#include <stdio.h>
// declaration of functions
void ReadData();
void SolveQuadEq();
void PrintSolution();
// declaration of global variables
double a, b, c, delta;
double x1, x2;
// main function
int main()
{
ReadData();
SolveQuadEq();
PrintSolution();
return 0;
}
// definitions of other functions
void ReadData()
{
// fill the function with proper code
}
void SolveQuadEq()
{
// fill the function with proper code
}
void PrintSolution()
{
// fill the function with proper code
}
```