- 最后登录
- 2011-1-11
- 在线时间
- 10 小时
- 寄托币
- 17644
- 声望
- 13
- 注册时间
- 2006-5-2
- 阅读权限
- 50
- 帖子
- 54
- 精华
- 8
- 积分
- 12939
- UID
- 2210864
  
- 声望
- 13
- 寄托币
- 17644
- 注册时间
- 2006-5-2
- 精华
- 8
- 帖子
- 54
|
发表于 2006-10-31 05:22:28
|显示全部楼层
鬱悶了!!什麽程序,BT死了!陳述得很模糊,搞得Newsgroup裏都是問題……
問題描述:
[————————————————————————————————————————]
COMP104: Assignment 2
| 11 | 2222 | 3333 | 44 | 555555 | 6666 | 777777 | 8888 | 9999 | 0000 |
| 111 | 22 22 | 33 33 | 444 | 55 | 66 | 77 | 88 88 | 99 99 | 00 00 |
| 11 | 22 | 33 | 4 44 | 55555 | 66666 | 77 | 8888 | 99999 | 00 00 |
| 11 | 222 | 33 33 | 444444 | 555 | 66 66 | 77 | 88 88 | 99 | 00 00 |
| 1111 | 222222 | 3333 | 44 | 55555 | 6666 | 77 | 8888 | 9999 | 0000 |
| ++ | | xx xx | // | |
| ++ | | xxxx | | ====== |
| ++++++ | ------ | xx | ////// | |
| ++ | | xxxx | | ====== |
| ++ | | xx xx | // | |
Deadline: Nov 2 (Thursday), 11:55pm
0. Files to Download
* assignment2-main.cpp
* assignment2-function.cpp
* big fonts (shown horizontally)
* big fonts (shown vertically)
1. Task Objective
Write a C++ program to display an integer number or a binary expression of 2 integers in big fonts (as shown at the top).
The basic framework of the program is already written for you and is given in the file "assignment2-main.cpp". You need to complete the functions called by the main( ) function and write them in "assignment2-function.cpp".
2. Detailed Description
An expression can be given in 2 forms:
1. a single integer; or,
2. a binary expression consisting of 2 integers and a binary operator. Only 4 binary operators are supported:
* '+' for addition
* '-' for subtraction
* '*' for multiplication
* '/' for division
Note:
* All integer numbers do not have leading unary '-' sign or unary '+' sign in both cases.
* There can be many whitespaces around each operand and operator, but there is at least one whitespace before and after the operator.
If it is the first case with only a single number, there is no calculation to do. But if it is the second case, you will need to compute the result of the binary expression using integer arithmetic. Finally in both cases, you have to print the input(s) and the result in big fonts in different display styles.
2.1 Program Flow
1. Print a welcome message (which is fixed already)
2. Read expression
* Check for possible input errors. If there are, print the corresponding error message and exit.
3. If expression is a single integer,
* Print the corresponding display options
* Read user's choice
* Display the number with the selected display style
4. If the input expression is a binary expression,
* Calculate the result of the expression
* Print the corresponding display options
* Read user's choice
* Display the calculation with the selected display style
2.2 Examples of Legal Expressions
In the following, double quotes are used to show the whitespaces embedded in the inputs. They are NOT supposed to appear in the actual testing environment.
* "12368"
* "3"
* " 863 "
* "345 - 987643"
* " 2 * 444 "
* "34 / 9 "
* " 9 + 5"
2.3 Examples of Illegal Expressions
Example
Reason
"1 2"
there is no operator
"3+4"
there are no whitespaces between the operands and the operator
" 345 @ 567 "
the operator '@' is not supported
"abc - 124" "abc" is not an integer
"45.6 + 99.8" the operands are not integers but floating point numbers
"2E3 - 5E2" scientific notation is not supported
"- 3"
if it represents a single integer, then we don't support negative integer with unary minus sign. If it is a binary expression, then it should start with an integer, not an operator.
2.4 Display Styles
2.4.1 Display a Single Integer
If the input is a single integer number, say, 345, then there can be 4 display options:
1. horizontal print: print the numbers in big fonts horizontally as
2. vertical print: print the numbers in big fonts vertically as
3. horizontal print plus moving back and forth (animation). It is like the first display but the display will move back and forth horizontally. (I'll demonstrate that in the class next week.)
4. horizontal print plus moving up and down (animation). Again, it is like the first display but the display will move up and down. (I'll demonstrate that in the class next week.)
2.4.2 Display the Calculation of a Binary Expression
If the input is a binary integer expression, say, 54 / 3, then there can be 4 display options:
1. horizontal print: print the calculation horizontally as
2. vertical print: print the calculation vertically as
3. vertical print plus moving back and forth (animation) : similarly to vertical print but the whole "picture" moves back and forth
4. vertical print plus moving up and down (animation) : similarly to vertical print but the whole "picture" moves up and down
3. Some Specifications
3.1 Fixed Codes
Some codes are already written for you in the file assignment2-main.cpp. YOU ARE NOT ALLOWED TO MODIFY THEM. e.g.
* the welcome message
* the error messages, error codes
* the display menus
* the function prototypes of the given functions in assignment2-main.cpp
3.2 Big "Fonts" (Fixed)
The big "fonts" of the 10 digits and the 4 operators plus the "=" sign are given as shown at the top of this page. The '|' between each character is NOT part of the font; it is used to show the boundary between the characters. Each big character is 5 x 8, meaning that it consists of 5 rows and 8 columns. The first column and the 8th column are blank, so that when you want to print out two successive characters, you should not put any extra spaces between them.
3.3 Large Print
3.3.1 Large Horizontal Display of a Number/Calculation
No leading spaces, and no extra spaces between 2 characters.
3.3.2 Large Vertical Display of a Number
Put one blank line between 2 vertical characters.
3.3.3 Large Vertical Display of a Calculation
* The operator must be on the left of all operands and result.
* Put a line of "____________" (a separator of underscore symbols) between the 2nd operand and the result. The length of the separator line should be equal to the width of the longest line in the calculation.
* There should be a blank line between the 1st operand and the 2nd operand, and between the separator line and the result.
* But there is no blank line between the 2nd operand and the separator line.
3.4 Error Handling
When you read input expressions using the function
error_code read_expression(int& num_of_operands, char operand1[], char operand2[], my_operator& the_operator);
we only consider those types of errors as defined in the enumeration type
enum error_code {OKAY = 1, NOT_INTEGER, BAD_OPERATOR, TOO_MANY_DIGITS, TOO_FEW_OPERANDS, TOO_MANY_OPERANDS};
1. OKAY: no error
2. NOT_INTEGER: input operand/number is not an integer
3. BAD_OPERATOR: unsupported operator
4. TOO_MANY_DIGITS: the number of digits exceed the limit
5. TOO_FEW_OPERANDS: Too few operands. There should be exactly 1 for single number and 2 for binary expression
6. TOO_MANY_OPERANDS: more than 2 operands
Examples
123456AB NOT_INTEGER
123 + 456 * 789 TOO_MANY_OPERANDS
123 + 456 + 38 TOO_MANY_OPERANDS
123 + TOO_FEW_OPERANDS
123 ^ 456 BAD_OPERATOR
123 456 BAD_OPERATOR (take 456 as operator)
123+456 NOT_INTEGER (no space between operands and operator, take "123+456" as 1st operand)
- 3 NOT_INTEGER ( take the 1st operand as "-" which is not integer)
If the expression contains more than 1 error, return the first encountered error when the input is read from left to right.
Examples
abc + 1234567890 NOT_INTEGER (operand not integer, too many digits)
123 $ 4 5 BAD_OPERATOR (bad operator, too many operands)
123 4 + 789 BAD_OPERATOR (bad operator, too many operands)
3.5 Suggested Functions (not Mandatory but may be Helpful)
In this assignment, you are allowed to use any standard C++ library functions you like; make sure you include the right files. To handle character strings represented as 1D arrays, you may need the functions declared in string.h and stdlib.h.
Some other functions you may need:
bool is_digit(char c); // check if a character is a digit
bool is_operator(char c); // check if a character is an operator
bool is_integer(char s[]); // check if the string s is a number
bool string_to_int(char s[], int& n); // convert a char array to int
bool int_to_string(int n, char s[]); // convert an int to a char array (the number can be negative)
int get_string_size(char s[]); // get the size of a string
void large_print_char(char c, int row); // print one row of character c
4. Hint on Animation
One way to do the animation is to write a while loop and make use of the following 3 functions to repeat some actions forever (one will stop with a control-c):
1. call: system("clear"); // To clear the screen
2. call the function usleep( ); // To sleep for a number of microseconds e.g. use REFRESH_RATE
3. call the function you write to display the vertical print of the calculation
For details of the use of the usleep function, "man 3 usleep" on a lab2 Linux machine (or any Unix/Linux machine)
5. Extra Work for Bonus (+10%)
You may add up to 5 other display options (options 1-4 are reserved for the basic display modes, options 5-9 are open for your addition). The added options MUST be significantly different from the basic ones. For example, to display the calculation/number such that the calculation/number moves around the screen like a screensaver will do.
We will grade your bonus work according to its level of difficulty and complexity. Honestly speaking, how good your bonus work is can be very subjective; it is up to our judgement.
6. Assignment Submission
(A) ALL OF YOU HAVE TO DO THIS.
Complete the functions in the given assignment2-function.cpp, and submit the completed file: assignment2-function.cpp. You cannot modify the given assignment2-main.cpp file and you have to work under the limitations suggested by the codes in assignment2-main.cpp. In particular, you cannot modify the function prototypes of the functions that you are required to complete.
Your codes must be written in such a way that when we concatenate the given assignment2-main.cpp and your assignment2-function.cpp to, say, assignment2.cpp, the resulting file can be compiled and run in our lab2 Linux machines.
i.e. We will compile your codes using the following command
cat assignment2-main.cpp assignment2-function.cpp > assignment2.cpp
g++ -o assignment2 assignment2.cpp
(B) ONLY FOR THOSE WHO PLAN TO DO THE BONUS PART.
First submit the assignment2-function.cpp required by part (A). Then submit two additional files:
1. assignment2-bonus.cpp : a file similar to assignment2-function.cpp of part (A) but with additional display options. Basically it contains all the things in part (A) plus additional functions to support the additional display options.
2. assignment2-bonus.txt : an ASCII text file that we can read with the vi editor to explain
* how many additional options you have added
* what are the additional options
* a brief description of what we will see for each of the additional display option
i.e. We will compile your codes using the following command
cat assignment2-main.cpp assignment2-bonus.cpp > assignment2x.cpp
g++ -o assignment2x assignment2x.cpp
7. Miscellaneous
You have to submit the files by CASS. Here is the submission homepage of CASS:
https://course.cse.ust.hk/cass/student/submit.php
For details of submission via CASS, please visit:
http://cssystem.cse.ust.hk/home. ... s/cass/student.html
[————————————————————————————————————————]
Questions:
Case 1: '0042'
As Dr. Mak described in the Newsgroup as follows
" In general, there are 2 choices:
1. since you don't allow leading zeros, you may treat integers with
leading zeros invalid integers.
2. you skip all leading zeros just like skipping white spaces before
reading an integer."
Does it mean that either choice 1 or choice 2 will do? If it's the
second choice, do we take the leading zero(s) within the length of the
integer?
Case 2: '1 ++ 2'
What to do with the operator? Is it a bad operator or unknown error?
Case 3: '1 + 2 /'
The same goes with Case 2.
Case 4: '123456789x'
Should it be TOO_MANY_DIGITS or NOT_INTEGER?
Case 5: ' 12 '
The string length exceeds MAX_STR_LEN, what's the error message?
我快瘋了!
[ 本帖最后由 nobuts 于 2006-10-31 05:23 编辑 ] |
|