# Lab & HW 10 : File I/O + Standard Library + Advanced Uses of Pointers
## Lab 10-1: TA Simulator
### Lab 10-1 Background
This Lab hopes that you can simulate a teaching assistant giving a question and write a program code to generate test data.I believe you all have experience in encountering incorrect answers to questions given by teaching assistants. It is not an easy task to generate completely correct test cases.
As for how this "test cases" came about? A problem usually goes through the following steps from scratch:
Step 1. Come up with / copy a set of questions. Most TAs choose to use and fine-tune existing questions, firstly, they don’t have to think about new topic themselves, and secondly, archaeological questions are less likely to make mistakes.
Step 2. Define input/output formats and ranges. The range of the question (such as the size of n) usually directly affects the difficulty of the question.
Step 3. Write a code that generates the input of random test cases or Just write down some test cases.
Step 4. Write the correct answer code (solution) to the original question. Note that errors in this step will result in incorrect answers.
Step 5. Give the input generated in Step 3 to the solution code to calculate the answer (the output of test case).
Step 6. Several more solutions are written to check whether the generated output is correct. Unfortunately, time is too tight and this step is often omitted.
For generating random numbers, you may need the following function:
https://www.runoob.com/cprogramming/c-function-srand.html
https://www.runoob.com/w3cnote/c-time-func-summary.html
```
#include <stdlib.h>
srand() // set a random seed
rand() // generating a random numbers
#include <time.h>
time() // get current time
```
### Lab 10-1 requirements
1. AC [Lab 10-1](https://oj.cerana.tech/contest/21/problem/1) (15 pt)
2. demo & Explain your generation strategy (10 pt)
**Note that your test data must ensure that the results are different every time you execute it.**
## Lab 10-2: TA Debugger
### Lab 10-2 requirnments
0. Confirm your OS type (windows, mac, linux...)
1. AC [Lab 10-2](https://oj.cerana.tech/contest/21/problem/2) (10 pt)
2. Debugging sample output on E3 using "diff" command & demo (15 pt)
For Windows users, you can use the "FC" command
```
diff A.txt B.txt
//is equal to
FC A.txt B.txt
```
Hint:
You can I/O files by directly executing the executable (e.g. Use ./main generated by Makefile) instead of copying.
```
your_code.exe < A.txt
// input
your_code.exe > B.txt
// output
your_code.exe < A.txt > B.txt
// input + output
```
(Not recommended) You can also use online comparison tools directly, if you are in a hurry to get off work: https://www.diffchecker.com/text-compare/
## Homework 10-1: qsort test (25 pt)
### Homework 10-1 requirnments
1. Implement "qblebesort.c" and "bubblebesort.c"
* bubblebesort.c: It can execute single or multiple test data (using while(scanf)), and AC Lab 10-2.
* qblebesort.c: It has the same function as bubblebesort.c, the only difference is that the sort method is changed to qsort (please refer to the professor's slide), and the compare function is changed to the following version.

2. Use the code from Lab 10-1 AC as input to "qblebesort.c" and "bubblebesort.c".
3. Compare the sum of bubblebe string lengths of these two sorting methods. (5 pt)
4. Try to achieve that the lines of "bubblebesort.c" is twice that of "qblebesort.c" while only generating one test data n = ? (n can exceed 1000, 5 pt)
(Instead of exactly double, you can have a margin of error of 10%)
5. Try to achieve that the lines of "bubblebesort.c" is same that of "qblebesort.c" while only generating one test data n = ? (n can exceed 1000, 5 pt)
6. Use the timing code in Lab 9-1 to achieve that the execution times of "bubblebesort.c" is 1k times that of "qblebesort.c" while only generating one test data n = ? (n can exceed 1000, 5 pt)
(Instead of exactly double, you can have a margin of error of 30%)
7. Try to explain the difference in the number of string outputs & execution time between the two. (5 pt)
Hint: You can use "#ifdef" to submit code that accomplishes the above tasks at the same time
## Homework 10-2: Debugger Report (25 pt)
Assignment:
Please refer to the following code (code file HW10_Debugger.c has been
posted on e3), and use a C program debugger (e.g., GDB) to identify and fix all bugs in the code.
Restrictions:
You can only modify the code in TO DO, and you cannot declare any additional variables or use functions.

## Submission
Compress your lab & homework to .zip file
lab
```
{student_id}_lab10
├── {student_id}_lab10-1
| └──{student_id}_lab10-1.c
└── {student_id}_lab10-2
└──{student_id}_lab10-2.c
```
compress {student_id}_lab10 to {student_id}_lab10.zip and submit to e3
homework
```
{student_id}_hw10
├── {student_id}_hw10-1
| └──qblebesort.c
| └──bubblebesort.c
| └──{student_id}_hw10-1-3.pdf
| └──{student_id}_hw10-1-4.pdf
| └──{student_id}_hw10-1-5.pdf
| └──{student_id}_hw10-1-6.pdf
| └──{student_id}_hw10-1-7.pdf
└── {student_id}_hw10-2
└──{student_id}_hw10-2.c
└──{student_id}_hw10-2.pdf
```
hw10-1-3~6 must contain the following information
1. What kind of test data was generated
2. The process of how to generate your test data
3. The execution results
compress {student_id}_hw10 to {student_id}_hw10.zip and submit to e3
