[toc]
# Subject: TS0101 Compute the square root
- **Description:**
The Babylonian algorithm to compute the square root of a positive number n is as follows:
1. Make a guess at the answer (you can pick n/2 as your initial guess).
2. Compute r = n / guess .
3. Set guess= (guess + r) / 2.
4. Go back to step 2 for as many iterations as necessary. The more steps 2 and 3 are repeated, the closer guess will become to the square root of n.<br>
Write a program that inputs a double for n, iterates through the Babylonian algorithm until the guess subtract the previous guess smaller than 0.01, and outputs the answer as a double to two decimal places. Your answer should be accurate even for large values of n.
- **Input:**
391.00
- **Output:**
19.77
| Sample Input | Sample Output |
| ------------ | ------------- |
| 400.5 | 20.01 |
|65189451651.5192165|255322.25 |
|1894651654984.11318|1376463.46|
|...| |
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0102 ComputeHMS

---
---
# Subject: TS0103 Pattern_Output
- **Description:**
Write a program to display the following “*” pattern on the screen.
- **Input:**
None.
- **Output:**
Display the following “*” pattern on the screen.
- Sample Input:
```
```
- Sample Output:
```
*
*
*
* *
* *
*
```
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0104 Input_Output 1
- **Description:**
Given an arbitrary integer INPUT ( INPUT ), follow the requirements below to
output it:<br>
If the number of characters in INPUT (including the negative sign) is less
than 10 digits, fill in the space at the beginning, so that the number of spaces plus the number of characters in INPUT just meets 10 digits.
- **Input:**
Each line represents an INPUT, the program continues to request input, and ends if EOF is read.
- **Output:**
Each line is output according to the requirements of the problem.

- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0105 Compute Sphere Volume
- **Description:**
Given a radius r, please compute and output the volume of a sphere with radius r. PI = 3.14159265358979323846
- **Input:**
Input radius r(float).The program continues to request input, and ends if EOF is read.
- **Output:**
Output the volume of a sphere, and take the decimal point to the sixth place.
| Sample Input | Sample Output |
| -------- | -------- |
| 47.0 | 434892.765432 |
| 21.682 | 42695.944922 |
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0201 Compute Standard Deviation

---
---
# Subject: TS0202 LeaderBoard


---
---
# Subject: TS0201 Square Code
- **Description:**
The spaces are removed from the English text and the characters are written into a square (or rectangle).
- **Input:**
Input a string without whitespace.
- **Output:**
The coded message is obtained by reading down the columns going left to right.
| Sample Input | Sample Output |
| -------- | -------- |
|HaveANiceDay<br>Idontknowwhoyouare,butiwillfoundyou<br>helloworld |HAe<br>aND<br>via<br>ecy<br>Iny,in<br>doobld<br>owuuly<br>nwatfo<br>thriou<br>koewu<br>hol<br>ewd<br>lo<br>lr|
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0204 Print Standard Format
- **Description:**
You are a IT employee in a company, your manager request you to print out N employee’s information, as make sure the result remains clean. Every employee has information of Name, Salary, Bonus.
- **Input:**
Input Integer N(10^6 >= N > 0) at the start of the line. With next N pieces of employee information. Every information comes with three data: Name, Salary(Between 10^9 ~ 0) and Award(Between 10^9 ~ 0) .Separate three data with space.<br>
*The name doesn’t contain space.<br>
Program ends after reading of EOF.
- **Output:**
For every test data(from this input N to next input N, is a pair of test data.)Please make sure the width of every column is same as the longest width of other all data in that column. Besides, separate columns with symbol |. Symbol | separates two spaces away from other data.
| Sample Input | Sample Output |
| -------- | -------- |
| 3<br>Alexandrescu 20000000 99999<br>Frank 100000 50<br>Andy 1 1<br>4<br>Andy 100 200<br>Anna 400 9999<br>Lipp 200 200<br>Stan 500 200| Alexandrescu\| 20000000\| 99999<br> Frank\| 100000\| 50<br> Andy\| 1\| 1<br>Andy\| 100\| 200<br>Anna\| 400\| 9999<br>Lipp\|200\| 200<br>Stan\| 500\| 200 |
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0205 Adding Large Numbers
- **Description:**
Given two integers A, B. Please calculate the adding result of A+B, notice that the maximum bits of the number can approximate to 10000.
Don’t try to use **long long**, **long long int**, or **_m128**, etc. These variable types are invalid because the maximum bits of the given number will approximate to 10000((10^10000)-1).
Make sure the input number is valid, or print “**Not a valid number, please try again.**”
Please package the big number as a **structure** (e.g. struct BigInt…) with a simple object type for each bit.
To add the two big numbers, please use the "function Add(...)" shown as below.<br>
P.S. **const&** won’t affect the grammar of parameter passing but can avoid unnecessary memory usage. Use it or not depends on you.
```
Struct BigInt
{
…
}
BigInt Add(const BigInt &lhs,const BigInt &rhs)
{
//Calculation
Return …;
}
int main()
{
BigInt a,b;
…Input a,b
BigInt result = Add(a,b);
…Output result
}
```
- **Input:**
The first line of input contains an integer N (100 > N > 0), which indicates there’re N following data pairs. Note that every two lines makes a data pair, and each pair contains two big integers A and B on a line by itself. The maximum bits of A, B is(10^l0000) – 1.
- **Output:**
Print the result of A+B.
| Sample Input | Sample Output |
| -------- | -------- |
| 3<br>43789507384925798320000000000000000000000000001<br>44997439848794037580000000000000000000000000002<br>1bbbba45<br>1234567<br>1<br>9| 8878694723371983590000000000000000000000000003<br> Not a valid number, please try again.<br> 10 |
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0206 Compute The Tax
- **Description:**
In one state. single residents are subject to the following income tax:
Income Amount of tax
Not over $750 l% of income
$750—$2,250 $7.50 plus 2% of amount over $750
$2,250—$3,750 $37.50 plus 3% of amount over $2,250
$3,750-$5,250 $82.50 plus 4% of amount over $3,750
$5,250—$7,000 $142.50 plus 5% of amount over $5,250
Over $7,000 $230.00 plus 6% of amount over $7,000
- **Input:**
Float larger than 0.
- **Output:**
Output the tax.
| Sample Input | Sample Output |
| -------- | -------- |
| 750<br>2250<br>4000 | 7.50<br>37.50<br>92.50 |
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0301 Occurrenc Counting
- **Description:**
Write a program that reads in an array of type int from a file, the file named
“intArray.txt”. Please note that the number of entries is not limited. Your
program determines how many entries are used. The output is to be a two-column
list. The first column is a list of the distinct array elements; the second
column is the count of the number of occurrences of each element. The list
should be sorted on entries in the first column, largest to smallest.
- **Input:**
For the array values: –12 3 –12 4 1 1 –12 1 –1 1 2 3 4 2 3 –12
- **Output:**
N Count
4 2
3 3
2 2
1 4
–1 1
–12 4
The two integers are divided by one tab(\t).
| Sample Input | Sample Output |
| -------- | -------- |
|13 8 -4 0 8 -8 8 -1 12 0|N count<br>13 1<br>12 1<br>8 3<br>0 2<br>-1 1<br>-4 1<br>-8 1|
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0302 Text-based histogram
- **Description:**
Generate a text-based histogram for a quiz given to a class of students. The quiz is graded on a scale from 0 to 5. Write a program that allows the user to enter grades from a file “grade.txt” for each student. As the grades are being entered, the program should count, using an array, the number of 0’s, the number of 1’s, the number of 2’s, the number of 3’s, the number of 4’s, and the number of 5’s. The program should be capable of handling an arbitrary number of student grades.Output the histogram count at the end.
- **Input:**
if the input grades are 3 0 1 3 3 5 5 4 5 4
- **Output:**
the program should output
1 grade(s) of 0
1 grade(s) of 1
0 grade(s) of 2
3 grade(s) of 3
2 grade(s) of 4
3 grade(s) of 5
| | Sample Input | Sample Output |
| ---------------- | -------- | ------------- |
| 第一組測資與輸出 | 3 0 1 3 3 5 5 4 5 4 | 1 grade(s) of 0 <br>1 grade(s) of 1<br>0 grade(s) of 2<br>3 grade(s) of 3<br>2 grade(s) of 4<br>3 grade(s) of 5 |
| 第二組 | 0 5 0 5 0 4 5 5 4 3 4 5 1 4<br> 1 5 5 1 4 3 5 5 0 1 1 1 1 3<br> 0 1 1 5 4 4 4 2 2 4 1 2 3 2 <br>2 0 2 2 0 4 | 7 grade(s) of 0 <br>10 grade(s) of 1 <br>7 grade(s) of 2 <br>4 grade(s) of 3 <br>10 grade(s) of 4 <br>10 grade(s) of 5 |
| 第三組 | 3 0 4 1 2 1 1 4 2 0 2 0 4 5<br> 2 5 4 3 4 5 2 5 4 4 3 3 1 5 <br>1 0 4 2 0 4 0 3 2 0 3 2 2 3<br> 5 2 0 2 0 3 4 1 4 3 1 0 5 1 <br>4 5 1| 10 grade(s) of 0<br>9 grade(s) of 1<br>11 grade(s) of 2<br>9 grade(s) of 3<br>12 grade(s) of 4<br>8 grade(s) of 5 |
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0303 Input_Output3
- **Description:**
Given an arbitrary number X(double), a positive integer M, a positive integer N, and a character C, please output it as follows: <br>
The decimal (excluding the decimal point) must occupy N characters in the output and the decimal number N digits must be unconditionally discarded. If the decimal part of X is less than N digits, please make up 0.<br>
If the corrected number of X characters (including negative and decimal points) is less than M words, please fill in the input character C at the beginning of the number, so that the number of characters C plus the number itself contains exactly the number of characters. Meet the M digits.
- **Input:**
Each line represents a group of X, M, N, and C. The four inputs are separated by spaces.
The program continues to ask for input, and ends if EOF is read.
Please note that C may be a space.
- **Output:**
Each line is output according to the requirements of the topic.
| Sample Input | Sample Output |
| -------- | -------- |
| 3.14159265358979323846 5 2 G | G3.14 |
| 3.14 8 3 X | XXX3.140 |
| 3 8 0 C | CCCCCCC3 |
| -3 8 5 C | -3.00000 |
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0304 CPU Bit Growth
- **Description:**
Suppose a CPU with a k-bit can compute a maximum integer of (2^k) - 1, and every 10 years k will grow by a multiple of 2. Suppose that your company first released a 4-bit CPU in 1900, and the largest integer of its operation is 15 (so 8bits will be released in 1910, and 1920 is 16 bits... and so on).<br>
Now given the year Y, find a maximum positive integer N, so that N! is within the CPU calculation range of the current year.<br>
Test time limit: 5.0 seconds
- **Input:**
Each line has a positive integer Y ( 2200 >= Y >= 1900 ).
The input method is unlimited input until the end of EOF is read.
- **Output:**
Output N, so that N! is within the CPU calculation range of the current year.
| Sample Input | Sample Output |
| -------- | -------- |
| 1900 | 3 |
| 1910 | 5 |
| 2097 | 134480 |
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0305 Simple Drawing Program
- **Description:**
Please design a simple drawing program (fill the background with *), allow users to draw square, Isosceles right triangle and lines on the console (for figure, fill with Upper X)
- **Input:**
At the beginning, allow users to enter the size of the drawing board(m*n).After that, enter the corresponding drawing code. S indicates square, T indicates Isosceles right triangle, L indicates lines. According to different figures, there follows various input information:<br>
S: input integer width(the width of the square). And coord x,y, drawing will start from x,y(calculates from the left-up corner of the square).<br>
T: input integer width(the side-length of the triangle). And coord x,y and the side the triangle faces. Which are respectively LU(Left Up),LD(Left Down),RU(Right Up),RD(Right Down).While drawing, the x,y indicates the position of right angle.<br>
L: input two pairs of coord x1,y1 & x2,y2.Drawing from x1,y1 to x2,y2 (Except straight line, it would possible be tilted lines with +-45 Angle).
Enter EXIT,end the program.<br>
※Please notice the coordinate, the left-up corner is 0,0 while right-down corner is m-1,n-1.
※If the following figure violates the border of drawing board,please output
“Out of range.”.And there no need to modify the board.
※Notice that for any figure,if the given width is 1 you’ll need to draw a point.
※You need to output a result every draw,separates each with a line of space.
※Expect the test data testing border violation, we ensure all input data is drawable.
※Any operation about string,please implements with std::string,or not points will be given.
- **Output:**
After drawing a figure or an error message,output a newline.
| Sample Input | Sample Output |
| -------- | -------- |
| 5 6<br>S<br>2<br>0 0<br>S<br>2<br>100 100<br>L<br>0 4 4 4<br>T<br>2<br>1 3<br>LU<br>EXIT| XX***<br>XX***<br>***** <br>\*\*\*\*\*<br>\*\*\*\*\*<br>\*\*\*\*\*<br><br>Out of range.<br><br>XX***<br>XX***<br>\*\*\*\*\*<br>\*\*\*\*\*<br>XXXXX<br>\*\*\*\*\*<br><br>XX***<br>XX***<br>\*X\*\*\*<br>XX\*\*\*<br>XXXXX<br>*****|
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0401 Class Point in plane
- **Description:**
The type Point is a fairly simple data type, but under another name (the template class pair) this data type is defined and used in the C++ Standard Template Library, although you need not know anything about the Standard Template Library to do this exercise. Write a definition of a class named **Point** that might be used to store and manipulate the location of a point in the plane. You will need to declare and implement the following member functions:
a. A member function set that sets the private data after an object of this class is created.
b. A member function to move the point by an amount along the vertical and horizontal directions specified by the first and second arguments.
c. A member function to rotate the point by 90 degrees clockwise around the origin.
d. Two const inspector functions to retrieve the current coordinates of the point.
Document these functions with appropriate comments. Embed your class in a test program that requests data for several points from the user, creates the points, then exercises the member functions.
- **Input:**
Replace the main from main.cpp.
- **Output:**
Please see sample out.
| Sample Input | Sample Output |
| -------- | -------- |
|main.in|0 5<br>1 7<br>7 -1<br>-1 -7<br>-7 1<br>1 7|
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0402 Fraction
- **Description:**
Define a class for a type called Fraction. This class is used to represent a ratio of two integers. Include mutator functions that allow the user to set the numerator and the denominator. Also include a member function that returns the value of the numerator divided by the denominator as a double, **but if the value can only represent by an integer, then it should be represented integer**. Include an additional member function that outputs the value of the fraction reduced to lowest terms. For example, instead of outputting 20/60 the function should output 1/3. This will require finding the greatest common divisor for the numerator and denominator, and then dividing both by that number. Embed your class in a test program.
- **Sample Input**
Replace main.cpp
```
int main()
{
Fraction f1, f2;
f1.setNumerator(4);
f1.setDenominator(2);
f1.getDouble();
f1.outputReducedFraction();
f2.setNumerator(20);
f2.setDenominator(60);
f2.getDouble();
f2.outputReducedFraction();
return 0;
}
```
- **Sample Output**
2
2
0.333333
1/3
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0403 Greatest Common Divisor
- **Description:**
Please write a program and use the recursive function GCD(...) (abbreviation for Greatest Common Divisor) to find the greatest common divisor of two positive integers.
- **Input:**
Input two positive integers **a** and **b** (a, b <= 2147483647).
- **Output:**
Output the greatest common divisor of two positive integers **a** and **b**.
| Sample Input | Sample Output |
| -------- | -------- |
|33 11<br>2147483 997<br>125 475|11<br>1<br>25|
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0404 Bank Account
- **Description:**
Write a definition of a class named BankAccount that will be used to store and amount of money call balance which are integers. You will need to declare and implement the following things:
a. Create a constructor “BankAccount(x)” that set the balance with initial value x. also have a default constructor “BankAccount()”that set balance with initial 0.
b. save(x): A member function to save money in the bank with an amount by the argument.
c. withdraw(x): A member function to withdraw money in the bank with an amount by the argument.
d. getBalance(): a const inspector functions to retrieve the current balance of the bank.
e. A static variable named: allMoneyInBank that track the total amount of BankAccounts have store.
f. A static function named: getAllMoneyInBank() that return the value of allMoneyInBank.
Noticed that the balance of BankAccount can be negative number so as allMoneyInBank
- **Sample Input**
Replace main.cpp
```
#include "BankAccount.h"
int main(void) {
BankAccount bankAccount1(200), bankAccount2, bankAccount3(-100);
cout << BankAccount::getAllMoneyInBank() << endl;
bankAccount1.withdraw(100);
cout << bankAccount1.getBalance() << endl;
cout << BankAccount::getAllMoneyInBank() << endl;
bankAccount2.save(50);
cout << bankAccount2.getBalance() << endl;
cout << BankAccount::getAllMoneyInBank() << endl;
system("PAUSE");
return 0;
}
```
- **Sample Output**
100
100
0
50
50
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0405 Collatz Conjecture
- **Description:**
Collatz conjecture, which also known as 3N+1 conjecture, is a conjecture in mathematics that concerns a sequence defined as follows:
(1) Input N
(2) If N equals 1, end calculation
(3) 
(4) Goto Step 2
All the positive number that smaller than 1 million use this method to calculate will finally equal 1. You need to find out how many times you check if N equal 1 (include the number itself). The times of calculation is cycle length.
For example, if 22 is inputted,
the result will be: 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
the cycle length of 22 is 16.
- **Input:**
Enter a pair of positive integer i and j, separate by space. This program allows multiple test. User can enter until read EOF. (0 < i,j < 1,000,000)
- **Output:**
Find the maximum cycle length that can be produced by any numbers between i and j (include i and j). Print i, j and the maximum cycle length, separate by space.
| Sample Input | Sample Output |
| -------- | -------- |
|1 10<br>200 100<br>201 210<br>900 1000<br>200| 1 10 20<br>200 100 125<br>201 210 89<br>900 1000 174|
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0501 Hot dog stand
- **Description:**
You operate several hot dog stands distributed throughout town. Define a class named HotDogStand that has a member variable for the hot dog stand’s ID number and a member variable for how many hot dogs the stand sold that day. Create a constructor that allows a user of the class to initialize both values. Also create a function named justSold that increments the number of hot dogs the stand has sold by one. This function will be invoked each time the stand sells a hot dog so that you can track the total number of hot dogs sold by the stand. Add another function named thisStandSoldAmount that returns the number of hot dogs sold. Add a static variable that tracks the total number of hot dogs sold by all hot dog stands and a static function named allStandSoldAmount that returns the value in this variable. Finally, add function named print that prints this stand’s ID and how many hot dogs have sold that day, which a space between them. Write a main function to test your class with at least three hot dog stands that each sell a variety of hot dogs.
- **Sample Input**
Replace main.cpp
```
int main(void)
{
HotDogStand stand1("Stand1", 0);
HotDogStand stand2("Stand2", 100);
HotDogStand stand3("Stand3");
stand1.justSold();
stand2.justSold();
stand3.justSold();
stand1.print();
stand2.print();
stand3.print();
std::cout << "Total Sold : " << HotDogStand::allStandSoldAmount() << std::endl;
return 0;
}
```
- **Sample Output**
Stand1 1
Stand2 101
Stand3 1
Total Sold : 103
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0502 Design Month Class
- **Description:**
Define a class called Month that is an abstract data type for a month. Your class will have one member variable of type int to represent a month (1 for January, 2 for February, and so forth).
Include all the following member functions:
1. a constructor to set the month using the first three letters in the name of the month as three arguments, a constructor to set the month using an integer as an argument (1 for January, 2 for February, and so forth), a default constructor.
2. an input function name inputInt that reads the month as an integer.
3. an input function name inputStr that reads the month as the first three letters in the name of the month.
4. an output function name outputInt that output the month as an integer.
5. an output function name outputStr that outputs the month as the first three letters in the name of the month.
6. a member function name nextMonth that returns the next month as a value of type Month. Embed your class definition in a test program.
<br>Note that if month out of range, set the month to January.
- **Input:**
Replace the main from main.cpp and enter the test data in input.txt.
- **Output:**
See the Sample Output.
| Sample Input | Sample Output |
| -------- | -------- |
|main1.in<br>sample.in|Month1 = 1 Jan<br>Month2 = 2 Feb<br>Month3 = 3 Mar<br>Month4 = 4 Apr<br>Month5 = 5 May<br>Month6 = 6 Jun|
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0503 Student Records
- **Description:**
Write a program that records at most 10 student data by structures. There are four function for user to use:
(1) insert (up to 10 records), (2) search, (3) delete, (4) print.<br>
A record of a student is defined as follow:
```
typedef struct {
char firstName[25];
char lastName[30];
char phone[15];
} StRec;
```
- **Input:**
Enter a string to call the function. There are four kinds of command (insert, delete search and print). Except “print” command, the other three command need to enter with firstName, lastName and phone. Use space to separate each data. The print command only needs to enter “print”.
Format of four commands:
(1) insert + firstName + lastName + phone
(E.g. insert Harry Potter 0987654321)
(2) delete + firstName + lastName + phone
(E.g. delete Harry Potter 0987654321)
(3) search + firstName + lastName + phone
(E.g. search Harry Potter 0987654321)
(4) print
(firstName <= 25 letters, lastName <= 30 letters, phone <= 15 numbers)
User can enter command until read EOF.
- **Output:**
User needs to check for the input format. (1) the length of firstName or lastName or phone is too long. (2) Input is not the four commands. (3) phone is not number. If any problems meet the above conditions, print “Input Error” and re-enter a command.
When insert is called, insert the record after last record. If there are already 10 records or the record already exists (firstName and lastName and phone are the same as input data), print “Insert Error”.
When delete is called, finds the record and delete it. If it does not exist, print “Delete Error”.
When search is called, finds the record and print which index the record is in. If it does not exist, print “Search Error”.
When print is called, print all records. Please print three data and separate them by space (e.g. Harry Potter 0987654321). If there are no records, print “Print Error”.
| Sample Input | Sample Output |
| -------- | -------- |
|||
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0504 Sudoku Checker
- **Description:**
A Sudoku is a 9x9 grid that is completed when every 3x3 square, row and column consist of the numbers 1-9.
For this task, you will be given a completed 9x9 square, Create a function that checks to make sure each 3x3 square contains each number from 1-9 exactly once, and there are no duplicates. Furthermore, each row and each column doesn’t contain duplicates with no numbers outside the range 1~9.
- **Input:**
81 integers separated with comma for each line, with input sequence 1~81 corresponding to the position drawn below. Color signifies 3x3 squares for checks.

- **Output:**
As Sample:

- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0505 Advanced Class Point in plane
- **Description:**
The type Point is a fairly simple data type, but under another name (the template class pair) this data type is defined and used in the C++ Standard Template Library, although you need not know anything about the Standard Template Library to do this exercise. Write a definition of a class named Point that might be used to store and manipulate the location of a point in the plane. You will need to declare and implement the following member functions:
a. A member function set that sets the private data after an object of this class is created. Attention! The data must be an array of float in size 2, initialized by zero.<br>
b. A member function to move the point by an amount along the horizontal and vertical directions specified by the first and second arguments.<br>
c. A member function to rotate the point by 90 degrees clockwise around the origin.<br>
d. A member function to reflect point in the origin.<br>
e. Two const inspector functions to retrieve the current coordinates of the point (horizontal and vertical).<br>
f. A copy constructor used to copy value of other point.<br>
g. A destructor used to release memory before the instance of class destroyed. Avoiding memory leak!<br>
Document these functions with appropriate comments. Embed your class in a test program that requests data for several points from the user, creates the points, then exercises the member functions.
- **Sample Input**
main.in
```
int main(void) {
Point point;
point.Set(0, 5);
cout << point.RetrieveHorizontal() << " " << point.RetrieveVertical() << endl;
point.Reflect();
cout << point.RetrieveHorizontal() << " " << point.RetrieveVertical() << endl;
point.Move(1, 2);
cout << point.RetrieveHorizontal() << " " << point.RetrieveVertical() << endl;
point.Rotate();
cout << point.RetrieveHorizontal() << " " << point.RetrieveVertical() << endl;
Point copy = point;
cout << "Copy point:" << endl;
cout << copy.RetrieveHorizontal() << " " << copy.RetrieveVertical() << endl;
return 0;
}
```
- Sample Output
0 5
0 -5
1 -3
-3 -1
Copy point:
-3 -1
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0601 Complex
- **Description:**
Define a class for complex numbers. A complex number is a number of the form as following:
a+b*i
b+c*i
where for our purposes, a and b are numbers of type double, and i is a number that represents the quantity ${\sqrt -1}$.Represent a complex number as two values of type double. Name the member variable **realValue** and **imaginaryValue**. (The variable for the number that is multiplied by i is the one called imaginary)
Define a class named **Complex**. Include a constructor with two parameters of type double that can be used to set the member variables of an object to any values. Include another constructor that has only a single parameter of type double; call this parameter **readPart** and define the constructor so that the object will be initialized to realPart + 0*i. Include a default constructor that initializes an object to 0(0 + 0i).
Using real() to get **realValue** and imag() to get **imaginaryValue**. By the way, you have to define norm() to get the norm of complex which defined as ${\sqrt {a^2+b^2}}$.
Overload all the following operator so that they can apply to the Complex : ==, +, -, *, >>, and << correctly. You should write a test program to test your class.
- **Input:**
No input.
- **Output:**
As the following sample.
- **Sample Input**
```
#include"complex.h"
int main()
{
// test constructors
Complex x, y(3), z(-3.2, 2.1);
cout << "x = " << x << "y = " << y << "z = " << z << endl << endl;
x = Complex(3, -4);
cout << "testing members and support functions as well as"
<< " output operator:\n"
<< "complex number x = " << x << endl
<< "real part: " << x.real() << endl
<< "real part from friend real(x): " << real(x) << endl
<< "imaginary part: " << x.imag() << endl
<< "imaginary part from friend imag(x) : " << imag(x) << endl
<< "norm: " << norm(x) << endl << endl;
cout << "test operator ==:" << endl << endl;
if (x == y)
cout << "x = y" << endl << endl;
else
cout << "x!=y" << endl << endl;
cout << "test complex arithmetic and output routines: \n\n";
y = Complex(1, -1);
cout << "x = " << x << "y = " << y << "z = " << z << endl << endl;
z = x + y;
cout << "z = x + y = " << z << endl;
z = x * y;
cout << "z = x * y = " << z << endl;
z = x - y;
cout << "z = x - y = " << z << endl;
z = x / y;
cout << "z = x / y = " << z << endl << endl;
//test of automatic conversion double -> complex by the constructor.
double d(2.0);
cout << "d: " << d << " x: " << x << endl;
cout << "x+d: ";
z = x + d;
cout << z << endl;
z = x - d;
cout << "x-d: ";
cout << z << endl;
z = x * d;
cout << "x*d: ";
cout << z << endl;
z = x / d;
cout << "x/d: ";
cout << z << endl;
z = d + x;
cout << "d+x: ";
cout << z << endl;
z = d - x;
cout << "d-x: ";
cout << z << endl;
z = d * x;
cout << "d*x: ";;
cout << z << endl;
z = d / x;
cout << "d/x: ";;
cout << z << endl;
//test whether double/complex and complex/complex give same result:
Complex two(2, 0);
cout << "two/x: ";
cout << two / x << endl;
cout << "\nGetting data from standard input: \n";
cin >> x >> y;
cout << "data read is: x = " << x << " y = " << y << endl << endl;
return 0;
}
```
- Sample Output
```
x = 0 + 0*i
y = 3 + 0*i
z = -3.2 + 2.1*i
testing members and support functions as well as output operator:
complex number x = 3 + -4*i
real part: 3
real part from friend real(x): 3
imaginary part: -4
imaginary part from friend imag(x) : -4
norm: 5
test operator ==:
x!=y
test complex arithmetic and output routines:
x = 3 + -4*i
y = 1 + -1*i
z = -3.2 + 2.1*i
z = x + y = 4 + -5*i
z = x * y = -1 + -7*i
z = x - y = 2 + -3*i
z = x / y = 3.5 + -0.5*i
d: 2 x: 3 + -4*i
x+d: 5 + -4*i
x-d: 1 + -4*i
x*d: 6 + -8*i
x/d: 1.5 + -2*i
d+x: 5 + -4*i
d-x: -1 + 4*i
d*x: 6 + -8*i
d/x: 0.24 + 0.32*i
two/x: 0.24 + 0.32*i
Getting data from standard input:
data read is:
x = 3 + 4*i
y = 5 + 6*i
```
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0602 Prime Number

---
---
# Subject: TS0603 Number Game
- **Description:**
A mathematician has designed a number game, but he doesn't know how to implement it on a computer, so he wants to ask for your help.
The rule of the game is giving an integer A and an integer list S(1<=S[i]<= 2^32 – 1), and you need to find the number in the list S that can be obtained by using the product of the digits decomposed by the integer A.
For example, given the integer A = 456 which can be decomposed into A1 = 4, A2 = 5 and A3 = 6. Assuming that one of the numbers we read from list S is E = 30, since E = A2 * A3, we consider E to be legitimate. But if we read the number E = 12, we can see that E cannot be derived from A1, A2 and A3 by multiplication, so we consider E to be illegitimate. Your task is to find all the legitimate numbers in list S.<br>
Please design a class called **NumberGame **to implement this game.
The class **NumberGame** should contains following member functions:
- void SetInput(int): set the given integer **A**.
- void ProcessInput (): splitting the integer **A** into several digits.
- void SetFileName(string): set the file name of the file where list **S** is located.
- void LoadNumberList(): read list **S** from the file.
- void PrintAllValid(): print all the valid numbers in **S** ascendingly
- void Reset(): reset all variables.
*Time limit: 2 second.*
- **Input:**
No inputs.<br>
** List S contains up to 50,000,000 numbers.
** The main() function in your submission will be replaced when judging.
** You can use the main() function in “Other Notes” to test your program.
- **Output:**
The result of executing your program with the given main function.
- Sample Input
```
int main() {
NumberGame Game;
Game.SetInput(1234);
Game.ProcessInput();
Game.SetFileName("number.txt");
Game.LoadNumberList();
Game.PrintAllValid();
Game.Reset();
cout << "\n";
Game.SetInput(2345);
Game.ProcessInput();
Game.SetFileName("number.txt");
Game.LoadNumberList();
Game.PrintAllValid();
system("pause");
}
```
- Sample Output
1
2
3
4
8
24<br>
2
3
4
5
8
24
60
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0604 N Dim Vector
- **Description:**
Define a class named VecNf as a n-dimensional float vector. Please implement the following functions and overload the following operations for VecNf.<br>
The data inside VecNf should NOT share with others. So make sure any copy/assign operations would make a hard copy.
1. Some proper constructor
i. Construct one-dimensional null/zero vector in default.
ii. Using (float *S, int N) as parameter, construct using the first N elements of array S.
iii. Any other constructor to make sure VecNf can be called by value.
iv. Do not print anything when constructor called.
2. Assignment operator --- VecA = VecB (Assign a VecNf with VecNf), When
assignment operator called, print“ASSIGNMENT!!!”
in a line.
3. Subscript operator (int Index) --- Vec [Index] (Return the reference of the
Index-th element of Vec. The first element is Vec[0])
4. Arithmetic operator ---
i. VecA plus(+) VecB (vector addition)
ii. VecA minus(-) VecB (vector subtraction)
iii. VecA product(*) VecB (inner product)
iv. float product(*) Vec (scale operation)
v. Vec product(*) float (scale operation)
5. Size() --- return the dimensional of VecNf.
For any arithmetic operator, make sure the two VecNf have the same dimensional. If they are not, print “dimensions inconsistent” in a line and return 0.0f or 1-Dim Null/Zero vector.
- **Input:**
The input is defined by the main function.
We will change the main function for testing.
- **Output:**
The output is defined by the main function.
We will change the main function for testing.
- **Sample Input**
```
#include<iostream>
#include "VecNf.h"
using namespace std;
void doNothing(VecNf tar) { return; }
int main()
{
float a_value[] = { 3.0, 2.0 };
float b_value[] = { 1, 2, 3 };
float c_value[] = { 6, 5, 4 };
VecNf A(a_value, 2);
VecNf B(b_value, 3);
VecNf C(c_value, 3);
VecNf T;
T = A; // Assignment
for (int i = 0; i < T.Size(); i++) {
cout << T[i] << “ ”;
} cout << endl;
T = B; // Assignment
for (int i = 0; i < T.Size(); i++) {
cout << T[i] << “ ”;
} cout << endl;
T = B + C; // Vector addition
for (int i = 0; i < T.Size(); i++) {
cout << T[i] << “ ”;
} cout << endl;
doNothing(T); // call by value
cout << C * B << endl; // Scale
cout << A * C << endl; // Inconsistent
system("pause");
return 0;
}
```
- **Sample Output**
ASSIGNMENT!!!
3 2
ASSIGNMENT!!!
1 2 3
ASSIGNMENT!!!
7 7 7
28
dimensions inconsistent
0
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
# Subject: TS0605 Observation Diary



---
---
# Subject: TS0701 FormWord
- **Description:**
Some word games require the player to find words that can be formed using the letters of another word. For example, given the word SWIMMING then other words WING, SING, MIMING, etc. Write a program that lets the user set a word and then output all the words contained in the file words.txt that can be formed from the letters of the set word. Please use the following partial class member function to do your project.
```
Class Form {
private:
string input;
string fileName;
public:
void SetInputWord(string inputWord);
void ProcessInputWord();
void SetFileName(string fileName);
void Load_CompaerWord();
void PrintFoundWords();
};
```
Please note that the comparison is not case-sensitive, but the output should keep the case of the original file.
- **Input:**
main.in & words.txt
- **Output:**
sample.out
| Sample Input | Sample Output |
| -------- | -------- |
|main.in|sample.out|
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0702 Array To Interger
- **Description:**
Write a class that convert a string into an integer. For example, given the string “1234” the function should return the integer 1234.If you do some research, you will find that there is a function named atoi and also the stringstream class that can do this conversion for you. However, in this Programming Project, you should write your own code to do the conversion. Also write a suitable test program.
!!!Using class.
```
class Atoi {
private:
string beTrans;
char sign;
public:
Atoi();
Atoi(string s);
void SetString(string s);
const string GetString();
int Length();
bool IsDigital();
int StringToInteger();
};
```
- **Input:**
input_main.cpp<br>input.txt
- **Output:**
output.txt<br>
**要輸出atoi前+20的數字和直接atoi的數字**
Length()是多少個數字
StringToInteger()是印出轉換後的數字
- **第一組測資與輸出**
- **Sample Input**
input_main.cpp<br>
05
11
23
-10
-11
8946
- **Sample Output**
4
520
4
2
5
4
4
1120
4
2
11
4
4
2320
4
2
23
4
4
-1020
4
2
-10
4
4
-1120
4
2
-11
4
6
894620
4
4
8946
4
- **第二組**
- **Sample Input**
input_main.cpp
46506
-096504
56400
00494
- **Sample Output**
7
4650620
4
5
46506
4
8
-9650420
4
6
-96504
4
7
5640020
4
5
56400
4
7
49420
4
5
494
4
- [ ] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [x] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0703 Seven-segment Display
- **Description:**
Write a program that prompts the user for a number and then displays the number, using characters to simulate the effect of a seven-segment display.
- **Input:**
Give numbers. Please ignore the characters not number.
The number of characters in one line no more than 100.
Finish when EOF.
- **Output:**
Print the input numbers by seven-segment format.
Example: If input is 83-5, then output will be

※For convenience, the ‘*’ above means ‘ ’, the true output use ‘ ’(blank).
- **Sample Input**
1234567890
- **Sample Output**

- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0704 Levenshtein Distance
- **Description:**
Levenshtein distance is a measurement method of similar strings which measuring the difference between two sequences. The Levenshtein distance between two words is the minimum number of single-character edits.(insertions, deletions or substitutions)
For example, the Levenshtein distance between "kiitten" and "sitting" is 4. There is no way to do it fewer than four edit.
(1) kiitten -> siitten (substitution of “s” for “k”)
(2) siitten -> sitten (deletions of “i” at the third place of siitten)
(3) sitten -> sittin (substitution of “i” for “e”)
(4) sittin -> sitting (insertion of “g” at the end)
Note: Upper letter and lower letter are considered different letter.
- **Input:**
Enter two paragraphs of text and separate by Enter. This program allows multiple case. User can enter until read EOF.
Note: Input must be in the range of ASCII.
- **Output:**
Find the minimum distance between two text and print that number(int).
- **Sample Input**
Google
Facebook
Winter is coming
Here comes Winter
I am the bone of my sword. Steel is my body and fire is my blood. I have created over a thousand blades. Unknown to death. Nor known to life.
I am the bone of my code. Steel is my structure, and fire is my algorithm. I have fixed over a thousand bugs. Unknown to dawn. Nor known to night.
- **Sample Output**
8
14
37
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0706 Shisensho
- **Description:**
Shisensho(四川省) is a classic tile-matching game. The objective of the game is to match all the pairs and clear the board.<br>
Rules:
Player choose a pair of identical tiles to connect, and the connection path must not exceed two turns. If the requirements are met, two tiles will be eliminated. The player’s task is to eliminate all the tiles on the board. The game is over if future moves are not possible and tiles are left on the board, or the player successfully removes all the tiles.
Some legal patterns of connection path are shown as follow:

To simplify the game, we start the game with a 6*6 board and only have 9 different symbols
(represented by characters :‘1’, ‘2’, ‘3’, … , ‘9’).<br>
Your quest is to determine whether the given pair is legal according to the rules shown above.
If it is legal, eliminate the pair and print out “pair matched”.
If it is not legal, do nothing and print out “bad pair”.<br>
The status of the board (the remaining tiles) should always be updated when you receive a legal pair,
which means the same input might have different results over time.
- **Input:**
[Beginning]
Given 6*6 characters to set all the initial symbol on the board.
[Loop]
Given a pair of coordinates on the board, represented by 4 integers (pos1.x pos1.y pos2.x pos2.y).
- **Output:**
The result message of each given pair. (“bad pair”or“pair matched”)
| Sample Input | Sample Output |
| -------- | -------- |
|9 2 4 8 9 7<br>6 9 1 7 1 5<br>5 3 3 7 2 2<br>3 4 7 1 9 5<br>4 6 8 8 2 6<br>6 5 1 4 3 8<br>2 1 3 3<br>3 1 3 2<br>2 1 3 3<br>5 1 5 3<br>1 1 4 3<br>0 1 5 4<br>3 0 3 4|bad pair<br>pair matched<br>pair matched<br>pair matched<br>pair matched<br>bad pair<br>pair matched|
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS0801 Design Polynomial Class
- **Description:**
Using dynamic arrays, implement a polynomial class with polynomial addition, subtraction, and multiplication. Remarks: A variable in a polynomial does nothing but act as a placeholder for the coefficients. Hence, the only interesting thing about polynomials is the array of coefficients and the corresponding exponent. Think about the polynomial
x\*x\*x + x + 1
Where is the term in x*x? One simple way to implement the polynomial class is to use an array of doubles to store the coefficients. The index of the array is the exponent of the corresponding term. If a term is missing, then it simply has a zero coefficient. There are techniques for representing polynomials of high degree with many missing terms. These use so-called sparse matrix techniques. Unless you already know these techniques, or learn very quickly, do not use these techniques.
Please
(1) provide a default constructor, a copy constructor, and a parameterized constructor that enables an arbitrary polynomial to be constructed.
(2) Supply an overloaded operator = and a destructor.
(3) Provide these operations: polynomial + polynomial, constant + polynomial, polynomial + constant, polynomial - polynomial, constant - polynomial, polynomial - constant. polynomial * polynomial, constant * polynomial, polynomial * constant,
(4) Supply functions to assign and extract coefficients, indexed by exponent. (5) Supply a function to evaluate the polynomial at a value of type double. <br>
You should decide whether to implement these functions as members, friends, or standalone functions. <br>
NOTES:
The default constructor creates an empty polynomial. A zero polynomial has degree 0, since it has only the zero degree coefficient.<br>
In the coefficient array, the index is the value of the exponent of term having this coefficient. For example, the index 0 entry is the constant coefficient, the index 1 entry is coefficient of the linear term, the index 2 entry is the coefficient of the quadratic term (term in x2), etc.<br>
The size of the coefficient array include a degree 0 entry, so the size is the degree of the polynomial + 1.
- **Sample Input**
main.in
- **Sample Output**
Polynomial q
term with degree 0 has coefficient 3
term with degree 1 has coefficient 2
term with degree 2 has coefficient 1
Polynomial c
term with degree 0 has coefficient 1
term with degree 1 has coefficient 2
term with degree 2 has coefficient 0
term with degree 3 has coefficient 3
value of q(2) is 11
value of p(2) is 11
value of r(2) is 29
value of c(2) is 29
value of (q + c)(2) is 40
value of (q - c)(2) is -18
size of q*c is 6
Polynomial r (= qc)
term with degree 0 has coefficient 3
term with degree 1 has coefficient 8
term with degree 2 has coefficient 5
term with degree 3 has coefficient 11
term with degree 4 has coefficient 6
term with degree 5 has coefficient 3
value of (q * c)(2) is 319
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types
---
---
# Subject: TS0902 Namespace
- **Description:**
This Programming Project explores how the unnamed namespace works.
Listed below are snippets from a program to perform input validation for a username and password. The code to input and validate the username is in a separate file than the code to input and validate the password.<br>
File header user.cpp:
```
namespace Authenticate
{
void inputUserName()
{
do
{
cout << "Enter your username (8 letters only)" << endl;
cin >> username;
} while (!isValid());
}
string getUserName()
{
return username;
}
}
```
Define the username variable and the isValid() function in the unnamed namespace so the code will compile. The isValid() function should return true if username contains exactly eight letters. Generate an appropriate header file for this code.
Repeat the same steps for the file password.cpp, placing the password variable and the isValid() function in the unnamed namespace. In this case, the isValid() function should return true if the input password has at least 8 characters including at least one non-letter:
File header password.cpp:
```
namespace Authenticate
{
void inputPassword()
{
do
{
cout << "Enter your password (at least 8 characters " <<
"and at least one non-letter)" << endl;
cin >> password ;
} while (!isValid());
}
string getPassword()
{
return password;
}
}
```
At this point you should have two functions named isValid(), each in different unnamed namespaces. Place the following main function in an appropriate place. The program should compile and run.
```
int main()
{
inputUserName();
inputPassword();
cout << "Your username is " << getUserName() <<
" and your password is: " <<
getPassword() << endl;
return 0;
}
```
- **Input**:
username and password
- **Output:**
username and password
| Sample Input | Sample Output |
| -------- | -------- |
|aaa<br>aaaaaa<br>abcdefghi<br>abcdefgh<br>aaaaaaaaaa1|Enter your username (8 letters only)<br>Enter your<br>username (8 letters only)<br>Enter your username (8 letters only)<br>Enter your username (8 letters only)<br>Enter your password (at least 8 characters and <br>at least one non-letter)<br>Your username is abcdefgh and your password is:<br> aaaaaaaaaa1|
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS1101 Class Inheritance
- **Description:**
Define a class named Document that contains a member variable of type string named text that stores any textual content for the document. Create a method named getText that returns the text field, a way to set this value, and an overloaded assignment operator.
Next, define a class for Email that is derived from Document and includes member variables for the sender, recipient, and title of an email message. Implement appropriate accessor and mutator methods. The body of the email message should be stored in the inherited variable text. Also overload the assignment operator for this class.
Similarly, define a class for File that is derived from Document and includes a member variable for the pathname. Implement appropriate accessor and mutator methods for the pathname and overload the assignment operator.
Finally, create several sample objects of type Email and File in your main method. Test your objects by passing them to the following subroutine that returns true if the object contains the specified keyword in the text property.
```
bool ContainsKeyword(const Document& docObject, string keyword)
{
if (docObject.getText().find(keyword) != string::npos)
return true;
return false;
}
```
For example, you might test to see if an email message contains the text "c++" with the call ContainsKeyword(emailObj, "c++");
- **Input:**
No Input for this Problem,but we will change different main function to test your Code.
- **Output:**
Depends on the output of testing main function.
| Sample Input | Sample Output |
| -------- | -------- |
|main.in |sample.out|
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS1301 Template Binary Search
- **Description:**
Please implement Binary Search using template, and provide iterative and recursive versions. The iterative version of the function should follow this format **ItrBinarySearch(const T a[], int first , int last, T key, bool &found, int &location)**, recursive version of the function please follow this format **RecBinarySearch (const T a[], int first, int last, T key, bool &found, int &location)**, both functions please support int, string and double types.
Please refer to the following main. When we score, we will use our main to replace your main, so be sure to follow the above format.
```
int main(){
const int ARRAY_SIZE = 8;
const int finalIndex = ARRAY_SIZE - 1;
int count = 0;
cin >> count;
for (; count >= 1; count--){
int i;
int a[] = { 1, 2, 3, 4, 10, 25, 29, 100 };
// Test int
cout << "\nArray contains:\n";
for (i = 0; i < ARRAY_SIZE; i++){
cout << a[i] << " ";
}
cout << endl;
int keyInt, location;
bool found;
cout << "Enter number to be located: ";
cin >> keyInt;
cout << "Testing Template Iterative Binary Search\n";
ItrBinarySearch(a, 0, finalIndex, keyInt, found, location);
if (found)
cout << keyInt << " is in index location " << location << endl;
else
cout << keyInt << " is not in the array." << endl;
cout << "Testing Template Recursive Binary Search\n";
RecBinarySearch(a, 0, finalIndex, keyInt, found, location);
if (found)
cout << keyInt << " is in index location " << location << endl;
else
cout << keyInt << " is not in the array." << endl;
// Test string
string b[] = {"aa", "ab", "ah", "bd", "be", "cc", "fe", "zk" };
string keyString;
cout << "\nArray contains:\n";
for (i = 0; i < ARRAY_SIZE; i++){
cout << b[i] << " ";
}
cout << endl;
cout << "Enter number to be located: ";
cin >> keyString;
cout << "Testing Template Iterative Binary Search\n";
ItrBinarySearch(b, 0, finalIndex, keyString, found, location);
if (found)
cout << keyString << " is in index location " << location << endl;
else
cout << keyString << " is not in the array." << endl;
cout << "Testing Template Recursive Binary Search\n";
RecBinarySearch(b, 0, finalIndex, keyString, found, location);
if (found)
cout << keyString << " is in index location " << location << endl;
else
cout << keyString << " is not in the array." << endl;
// Test double
double c[] = { 0.3 , 5.6 , 7.8 , 10.9 , 123.5 , 150.1 , 197.1 , 2019.2 };
double keyDouble;
cout << "\nArray contains:\n";
for (i = 0; i < ARRAY_SIZE; i++){
cout << c[i] << " ";
}
cout << endl;
cout << "Enter number to be located: ";
cin >> keyDouble;
cout << "Testing Template Iterative Binary Search\n";
ItrBinarySearch(c, 0, finalIndex, keyDouble, found, location);
if (found)
cout << keyDouble << " is in index location " << location << endl;
else
cout << keyDouble << " is not in the array." << endl;
cout << "Testing Template Recursive Binary Search\n";
RecBinarySearch(c, 0, finalIndex, keyDouble, found, location);
if (found)
cout << keyDouble << " is in index location " << location << endl;
else
cout << keyDouble << " is not in the array." << endl;
}
system("pause");
return 0;
}
```
- **Input:**
Please enter the number of times to be tested N, and then enter N sets of int, string, and double, respectively.
We will use our main to replace your main, so be sure to follow the above format.
- **Output:**
Please output all the elements in the array first, and then output the index value of the binary search in the iterative and recursive versions, respectively, e.g. “(value) is in index location (index)”, if the value is not in the array, then output “(value) is not in the array.”.
- **Sample Input:**
3
1
aa
0.3
100
zk
2019.2
5
gg
2018.2
- **Sample Output:**
Array contains:
1 2 3 4 10 25 29 100
Enter number to be located:
Testing Template Iterative Binary Search
1 is in index location 0
Testing Template Recursive Binary Search
1 is in index location 0<br>
Array contains:
aa ab ah bd be cc fe zk
Enter number to be located:
Testing Template Iterative Binary Search
aa is in index location 0
Testing Template Recursive Binary Search
aa is in index location 0<br>
Array contains:
0.3 5.6 7.8 10.9 123.5 150.1 197.1 2019.2
Enter number to be located:
Testing Template Iterative Binary Search
0.3 is in index location 0
Testing Template Recursive Binary Search
0.3 is in index location 0<br>
Array contains:
1 2 3 4 10 25 29 100
Enter number to be located:
Testing Template Iterative Binary Search
100 is in index location 7
Testing Template Recursive Binary Search
100 is in index location 7<br>
Array contains:
aa ab ah bd be cc fe zk
Enter number to be located:
Testing Template Iterative Binary Search
zk is in index location 7
Testing Template Recursive Binary Search
zk is in index location 7<br>
Array contains:
0.3 5.6 7.8 10.9 123.5 150.1 197.1 2019.2
Enter number to be located:
Testing Template Iterative Binary Search
2019.2 is in index location 7
Testing Template Recursive Binary Search
2019.2 is in index location 7<br>
Array contains:
1 2 3 4 10 25 29 100
Enter number to be located:
Testing Template Iterative Binary Search
5 is not in the array.
Testing Template Recursive Binary Search
5 is not in the array.<br>
Array contains:
aa ab ah bd be cc fe zk
Enter number to be located:
Testing Template Iterative Binary Search
gg is not in the array.
Testing Template Recursive Binary Search
gg is not in the array.<br>
Array contains:
0.3 5.6 7.8 10.9 123.5 150.1 197.1 2019.2
Enter number to be located:
Testing Template Iterative Binary Search
2018.2 is not in the array.
Testing Template Recursive Binary Search
2018.2 is not in the array.
- [ ] Eazy,Only basic programming syntax and structure are required.
- [x] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS1302 AbsoluteValue
- **Description:**
Please write a template-based function that calculates and returns the absolute value of the difference between two numeric values passed in in the Template.h. Note that the function should operate with any numeric data type (e.g., float, int, double, char).
Please use the code snippets in the following to test your program:
```
#include "Template.h"
#include <iostream>
using namespace std;
int main()
{
// Variable declarations
int i1, i2;
double d1, d2;
i1 = 10; i2=20;
cout << "Absolute value of 10,20 is " << absoluteValue(i1,i2) << endl;
d1 = 5.5; d2=3.1;
cout << "Absolute value of 5.5, 3.1 is " << absoluteValue(d1,d2) << endl;
return 0;
}
```
- **Input:**
Replace main function
- **Output:**
Please reference the output.txt
| Sample Input | Sample Output |
| -------- | -------- |
|sample.in |sample.out |
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---
# Subject: TS 1401 Exception Handling
- **Description:**
A function that returns a special error code is usually better accomplished throwing an exception instead. The following class maintains an account balance.
```
class Account
{
private:
double balance;
public:
Account()
{
balance = 0;
}
Account(double initialDeposit)
{
balance = initialDeposit;
}
double getBalance()
{
return balance;
}
//returns new balance or -1 if error
double deposit(double amount)
{
if (amount > 0)
balance += amount;
else
return -1;
return balance;
}
//return new balance or -1 if invalid amount
double withdraw(double amount)
{
if ((amount > balance) || (amount < 0))
return -1;
else
balance -= amount;
return balance;
}
};
```
Rewrite the class so that it throws appropriate exceptions instead of returning -1 as an error code. Write test code as shown in the following that attempts to withdraw and deposit invalid amounts and catches the exceptions that are thrown.
Note that please use this following code snippets as your main()
```
//Main
int main()
{
Account a(100);
try
{
cout << "Depositing 50" << endl;
cout << "New balance: " << a.deposit(50) << endl;
//cout << "Depositing -25" << endl;
//cout << "New balance: " << a.deposit(-25) << endl;
cout << "Withdraw 25" << endl;
cout << "New balance: " << a.withdraw(25) << endl;
cout << "Withdraw 250" << endl;
cout << "New balance: " << a.withdraw(250) << endl;
}
catch (InsufficientFunds) // InsufficientFunds: a class name
{
cout << "Not enough money to withdraw that amount." << endl;
}
catch (NegativeDeposit) // NegativeDeposit: a class name
{
cout << "You may only deposit a positive amount." << endl;
}
cout << "Enter a character to exit" << endl;
char wait;
cin >> wait;
return 0;
}
// note that
// class NegativeDeposit {…};
// class InsufficientFunds {…};
```
| Sample Input | Sample Output |
| -------- | -------- |
|main.in |sample.out |
- [x] Eazy,Only basic programming syntax and structure are required.
- [ ] Medium,Multiple programming grammars and structures are required.
- [ ] Hard,Need to use multiple program structures or complex data types.
---
---