Skip to content

Commit db3cf22

Browse files
committed
chapter 3 update
1 parent 1594bce commit db3cf22

File tree

7 files changed

+110
-25
lines changed

7 files changed

+110
-25
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.out
2+
settings.json
3+
week01/~$Lecture01.pptx
4+
week02/~$Lecture02.pptx
5+
week03/~$Lecture03.pptx

README.md

+1-25
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,7 @@ Course 'CS205 C/C++ Program Design' in 2021 Fall at Southern University of Scien
88

99
## [Chapter 2: Data Types and Arithmetic Operators](week02/README.md)
1010

11-
## Chapter 3: Loops and Branching Statements
12-
13-
### if-else if- else
14-
15-
### ? : operator
16-
17-
### for loop (break, continue)
18-
19-
### while loop (break, continue)
20-
21-
### switch case (break )
22-
23-
### goto
24-
25-
### Relational expressions
26-
27-
<, <=, >, >=, ==, !=
28-
29-
### Logical expressions ( and, or, not), precedence
30-
31-
### bool and integers
32-
33-
### Lab
34-
* a calculator?
35-
* Makefile (how to manage multiple source files using a Makefile)
11+
## [Chapter 3: Loops and Branching Statements](week03/README.md)
3612

3713
## Chapter 4: Data Structures
3814

week03/Lecture03.pptx

178 KB
Binary file not shown.

week03/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Chapter 3: Loops and Branching Statements
2+
3+
## if-else if- else
4+
5+
## ? : operator
6+
7+
## for loop (break, continue)
8+
9+
## while loop (break, continue)
10+
11+
## switch case (break )
12+
13+
## goto
14+
15+
## Relational expressions
16+
17+
<, <=, >, >=, ==, !=
18+
19+
## Logical expressions ( and, or, not), precedence
20+
21+
## bool and integers
22+
23+
## Exercises
24+
25+
* a calculator?
26+
27+
* Makefile (how to manage multiple source files using a Makefile)

week03/examples/for.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int sum = 0;
6+
for(int i = 0; i < 10; i++)
7+
{
8+
sum += i;
9+
cout << "Line " << i << endl;
10+
}
11+
cout << "sum = " << sum << endl;
12+
13+
return 0;
14+
}

week03/examples/if.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
int num = 10;
7+
if (num < 5)
8+
cout << "The number is less than 5. " << endl;
9+
10+
if (num == 5 )
11+
{
12+
cout << "The number is 5." << endl;
13+
}
14+
else
15+
cout << "The number is 5." << endl;
16+
17+
if (num < 5)
18+
cout << "The number is less than 5." << endl;
19+
else if (num > 10)
20+
cout << "The number is greater than 10." << endl;
21+
else
22+
cout << "The number is in range [5, 10]." << endl;
23+
24+
if(num < 20)
25+
if(num < 5)
26+
cout << "The number is less than 5" << endl;
27+
else
28+
cout << "Where I'm?" << endl;
29+
30+
int * p = new int[1024];
31+
if (p)
32+
cout << "Memory has been allocated." << endl;
33+
34+
return 0;
35+
}

week03/examples/while.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int num = 10;
6+
while(num > 0)
7+
{
8+
cout << "num = " << num << endl;
9+
num--;
10+
}
11+
12+
num = 10;
13+
do
14+
{
15+
cout << "num = " << num << endl;
16+
num--;
17+
}while (num > 0);
18+
19+
num = 10;
20+
while (num > 0)
21+
{
22+
cout << "num = " << num << endl;
23+
num--;
24+
if (num == 5)
25+
break;
26+
}
27+
return 0;
28+
}

0 commit comments

Comments
 (0)