辅导CSCI 2132、讲解C/C++程序、辅导Software Development、讲解C/C++
- 首页 >> C/C++编程Fall 2018 (Sep4-Dec4)
Faculty of Computer Science
CSCI 2132 — Software Development
Assignment 6
Due: Thursday, Nov 22, 2018 by midnight
Worth: 60 marks (= 10 + 10 + 20 + 20)
Instructor: Vlado Keselj, CS bldg 432, 902-494-2893, vlado@dnlp.ca
Assignment Instructions:
Note: For students who finish practicum questions by the previous deadline (Tue Nov
20), their will receive 20 points for each accepted practicum problem, without verifying
implementation requirements. They still need to submit their program via SVN as well, and
include the head comment.
Solutions to this assignment must be submitted through SVN, in a similar way as for the
previous assignment. The solutions to practicum questions must also be submitted via the
practicum web site.
1) (10 marks) You must submit answers to this question via SVN in the file: CSID/a6/a6q1.txt
where CSID is your CSID and it is your main SVN directory for the course.
Briefly explain the purpose of the following function:
int f1(char *s) {
int cnt=0;
for ( ; *s != ’\0’; s++) {
if (*s >= ’A’ && *s <= ’Z’) cnt++;
else if (*s >= ’a’ && *s <= ’z’) {
*s -= ’a’ - ’A’; cnt++;
}
}
return cnt;
}
2) (10 marks) You must submit answers to this question via SVN in the file: CSID/a6/a6q2.txt
where CSID is your CSID and it is your main SVN directory for the course.
1
Briefly explain the purpose of the following function, and illustrate its input and output
on a small example with a string s of length 5:
int f(char *s) {
char *p = s;
int c = 1;
while (*p == ’ ’)
++p;
while (*p != ’\0’) {
if ( *p < ’0’ || *p > ’9’ ) {
printf("Error!\n"); return 0;
}
++p;
}
for (--p; p >= s; --p) {
if (*p == ’ ’) *p = ’0’;
*p += c;
if (*p > ’9’) {
*p = ’0’; c = 1;
} else
c = 0;
if (c == 0) break;
}
if (c != 0) {
printf("Error!\n");
return 0;
}
return 1;
}
3) (20 marks) Your task in this question is to write a C program named G.c according to the
specifications below. You will submit the program using SVN in the pathname CSID/a6/G.c
where CSID is your CSID and the name of your main SVN directory for the course. You
will also need to submit the program as a part of the Practicum 4. The Practicum 4 link is
available at the course web site.
Problem description: We know that in C we can very efficiently read integers and add
them as long as they can fit into one of the integer types well supported by the standard C
2
language, which are coincidentally well supported by the computer hardware. In this problem,
you need to write a program that can add very large numbers, that cannot necessarily
fit into these standard types.
Input: The input must be read from the standard input and each line of input is presented
in the following format:
a+b=
where a and b are integers of length up to 100 decimal digits.
You can assume that there are no whitespace characters in a line, other than the newline
character at the end.
The end of input is the end of standard input, which you can detect by the return value
of the scanf or getchar function, whichever you use.
Output: For each line of input, your program must print two lines of output to the standard
output. The first line must be simply the repetition of the input line, and the second line
must contan the result of adding two numbers in the input line.
You can find more details and sample input and output of the problem at the practicum
site.
a) [15 marks] Functionality: To satisfy this requirement, your program must satisfy the
program requirements as specified and pass the practicum testing.
b) [5 marks] Implementation: To receive these marks, the program must be implemented
in the following way, and it will be marked by a marker. You are required to write a
head comment that includes your name, date of the program, the course and assignment
number, and a short description of the program. The program should follow the organization
presented in the class.
The program must have a function that does addition of two integers, which are represented
as arrays of either strings or numbers, with additional argument for the result. You
may add parameters for the lenghts of the arrays, which is not necessary if you use strings.
The arrays could be in the order as read in input, or you may want to reverse them before
passing them to the function.
4) (20 marks) Your task in this question is to write a C program named H.c according to the
specifications below. You will submit the program using SVN in the pathname CSID/a6/H.c
where CSID is your CSID and the name of your main SVN directory for the course. You
will also need to submit the program as a part of the Practicum 4. The Practicum 4 link is
available at the course web site.
Problem description: The program must read standard input, collect a list of unique
words, and print them in alphabetical order with counts of occurences of each word. A word
is a sequence of letters, lowercase or uppercase (including mixed), and it must be translated
into lowercase letters only before including in the list of words.
3
Input: The standard input includes an arbitrary text. You can assume that there are no
more than 10,000 unique words and the total length of all unique words is not more than
100,000 characters. You can also assume that no word is longer than 80 characters.
Output: Your program must print words in an alphabetical order, one word per line. After
each word, there should be a space and the number of occurences of the word.
You can find more details and sample input and output of the problem at the practicum
site.
a) [15 marks] Functionality: To satisfy this requirement, your program must satisfy the
program requirements as specified and pass the practicum testing.
b) [5 marks] Implementation: To receive these marks, the program must be implemented
in the following way, and it will be marked by a marker. You are required to write a
head comment that includes your name, date of the program, the course and assignment
number, and a short description of the program. The program should follow the organization
presented in the class.
The program should use an appropriate indentation. Each block should have a consistent
indentation, which can be any number of spaces you choose, between 2 and 8. You can
choose a reasonable brace placement style (for example, see
https://en.wikipedia.org/wiki/Indentation_style). K&R style would be recommended,
but any other known style is acceptable as well. Your program lines should not be longer
than 80 characters.
You should not use more than a reasonable amount of memory. Since we know that the
total word length is 100,000, with at most 10,000 words, and the current word of at most
80 characters, it means that the total amount of used space should not be much more than
110,081. For example, if you use 81×10, 000 = 810, 000 bytes, that is too excessive, and you
would loose a point in implementation. Since you should keep words sorted, you should not
move whole words around during sorting, but only pointers to the words.