E kush tha qe Forumi eshte kot ...
Ju pershendes te gjitheve dhe shpresoj te me ndihmoni pak.
Sic e dini mire ju programistat nje nga testet me efektive eshte "black-box testing" pra testimi i nje programi qe s'ja di implementimin dhe krijon test cases ne baze te input te specifikuar dhe output qe duhet marre.
U perpoqa te gjeja dike qe te me ndihmonte dhe mendova se ndihma me e mire dhe efikase mund te gjehej ketu. Programi do te shkruhet ne C puro por kjo s'ka shume rendesi per testet.
Programi mund te marre inputet qe jane specifikuar me poshte por une megjithate do ti sqaroj edhe njehere.
insert// stringu eshte cfaredo
insertafter // string i pare eshte ai qe do insertohet, n sa vende larg, i dyti pas kujt.
insertbefore // si me siper
delete
print // do te printoje tere linked listin.
Pra programi do te implementohet ne Linked List Fashion duke perdorur pointers mbi nje "typedef struct" dhe absolutisht pa perdorur arrays. Megjithate une do ju lutesha vetem per TEST CASES. Implementimi eshte i thjeshte pasi edhe ky kurs ka per qellim me shume test cases.
FALEMINDERIT.
COSC 2031.03 Software Tools
Assignment A2, due Feb 13, 2004 at 16:00
For this assignment you are to create an ANSI-C program that maintains a list of strings. The list starts out empty. You will manipulate the list with insert and delete commands and will output the current list with a print command. You must store the strings in a doubly linked list. More precisely, you must use the following data structure
typedef struct lNode* ListNodePtr;
typedef struct lNode {
char* string;
ListNodePtr next;
ListNodePtr prev;
} ListNode;
You can find this declaration in the file a2.h, which you should include into your program.
This assignment is designed to exercise your skills with pointers and memory allocation. To that end, use of arrays is forbidden. If a submission declares an array or uses array indexing notation (like a[4] or something to replace this like studentFunction(a, 4)) then the assignment will immediately lose 3 out of its 5 marks. Just use pointer notation everywhere. Hint: the K&R textbook has quite a bit of relevant material in section 6.
Commands must be read from standard input and the output of the program must be via standard output. The program must accept the following commands:
Command
Explanation
insert
insert string at end of list
insertbefore
insert string n positions before the second string
insertafter
insert string n positions after the second string
delete
deletes the specified string from the list
prints the contents of the list to standard output
whereis any non-empty sequence of characters that does not contain white space (spaces, tabs, newlines, '\0' characters). is a positive integer, possibly with leading 0's but without a '+' sign [CHANGED Feb 9: from non-negative to positive integer]. It must fit into an unsigned int. If does not meet these conditions, then the command line is invalid and should be ignored (see below). There is only one command per line. [CLARIFIED Feb 9:] There may be arbitrary amounts of white space (spaces, tabs) on each command line before and after the command and there will be at least one white space between the elements of the command. All strings must be treated as case-sensitive, i.e. lower-case and upper-case characters are to be treated as different. Illegal commands are to be ignored, and should not result in any message. Examples of illegal commands are: ("insert hello goodbye", "insert", "insert hello 5 after goodbye print", "print .", "Insert hello", "insert hello -3 before goodbye").
insert command
For all insert commands strings must stored only once in the list, regardless of where the string occurs in the list. That means any attempt to insert a string a second time must be ignored.
* The first format of the insert command (insert) simply inserts the specified string at the end of the list.
* The second format of the insert command (insertbefore ) inserts the specified string n positions before the second string. I.e. if the list contains "apple", "banana" the command "insert cherry 1 before banana" must result in the list "apple", "cherry", "banana". If the position specified is before the start of the list (e.g. "insert pineapple 5 before apple") or if the second string cannot be found in the list, the string must be inserted at the beginning of the list.
* The third format of the insert command (insertafter ) inserts the specified string n positions after the second string. I.e. if the list contains "apple, banana" the command "insert cherry 1 after apple" must result in the list "apple", "cherry", "banana". If the position specified is beyond the end of the list or if second string cannot be found in the list, the string must be inserted at the end of the list.
delete command
If the string is in the list, remove it from the list. Otherwise ignore the command.
print command
Print out each string in the list, starting at the front and proceeding to the end of the list. After each string print a single newline character '\n'. The null character that marks the end of the string in internal storage must not be printed out.
Additional requirements:
* [ADDENDUM Feb 2, 2004] If memory allocation fails because there is not enough memory available, you must print the string "out of memory" to standard output and exit the program immediately (with exit(1).
* The program must free all memory that was allocated, as soon as it is no longer needed (i.e. after a delete command). Furthermore, all memory allocated must be freed before the program terminates.
* You must allocate only the minimum amount of memory necessary to store each string (i.e. 6 bytes for "pants"). In other words, it is not OK to allocate a buffer large enough to hold the maximum string length for every string.
* We recommend that you write yourself several functions to deal with each part of the functionality. This will make your program easier to read and will make it also easier to find problems.
* [ADDED Feb 11] Hint: The fact that strings cannot contain '\0' characters (see above) clearly does not imply that '\0' is a valid separator between the elements of the command line! As specified above only spaces or tabs are allowed between the elements. In other words, according to the above specification '\0' cannot occur in the input.
* No other output should be produced.
Sample Input & Output
To illustrate the behavior of the program, we have listed a log of a run of the program. Input is in underlined, output is in normal font.
insert hello
insert goodbye
insert hello 1 after goodbye
hello
goodbye
insert Dave 5 before goodbye
Dave
hello
goodbye
delete Goodbye
insert then 2 after Dave
Dave
hello
then
goodbye
For convenience, the corresponding input and output are here as files: a2.in, a2.out. To verify that your program works correctly with these two files use the following two commands:
cc -o a2 a2.c
a2output
diff output a2.out
If the compile fails or if there is any output from the second or third command, your program will fail this most basic test.
Temen e leviza ketu pasi eshte nje teme qe i perket programimit...take care Ardi
Krijoni Kontakt