Ske algo lab/lab 1 notes
รุ่นแก้ไขเมื่อ 19:49, 5 สิงหาคม 2561 โดย Jittat (คุย | มีส่วนร่วม)
- This is part of ske algo lab
Notes for lab 1
In this lab, you will learn C++ by working on exercises. Tasks 01 - 07 are simple tasks to familiarize you to C++ syntax. Tasks 08 - 10 are slightly more problem-solving tasks. As we proceed into the course, you will get more problem-solving tasks.
The following are additional notes for lab 1.
- General notes:
- Data types: you will see explicitly int and bool. You will also use string constant.
- 01 Hello, C++
- Pay attention to the comments on namespaces, i.e., the line using namespace std.
- 02 while loop
- We use cin to read the data from the user.
- Since we have using namespace std at the top, we can use cout to output integers and endl to force new line.
- 04 check_prime
- This task shows how to define a function. In C++, you have true and false for bool type.
- You can use % to mod.
- 05 Next prime
- In this task, you have to submit the source file.
- 06 Classic stars
- You can use nested loops. But you don't have to. You can use functions to avoid writing nested loops.
- 08 Close enough
- Example 1: pairs that are close are (15 - 10), and (15 - 21)
- Example 2: pairs that are close are (1 - 6), and (6, 11)