Question:
You are required to write an interactive C program that prompts the user for commands accepts those commands?
anonymous
2009-09-30 08:57:52 UTC
You are required to write an interactive C program that prompts the user for commands, accepts
commands from the keyboard (stdin) and executes those commands. The program must continue
to accept and process commands until the user types the end command.
The program maintains a linked list. Each node of the list contains an integer value and a
pointer to the next node of the list. Note that the same integer value may appear several times
in the list. At all times, the values in the list must be in non-decreasing order. Some commands
require your program to modify the list while others involve traversing the list to gather information.
Initially, the list is empty. The commands and their meanings are as follows. (You should bear in
mind that different parts of a command are separated by one or more spaces or tabs.)
(a) Insert Command: The syntax for this command is as follows:
ins value
In the above, ins represents the name of the command and value represents an integer value (which
may be positive, negative or zero). In response to this command, your program should create a
new node containing the specified value and insert the node into the list in such a way that the
values in the list continue to be in non-decreasing order even after the insert operation.
(b) Delete Command: The syntax for this command is as follows:
del value
As in the insert command, value represents an integer value (which may be positive, negative or
zero). In response to this command, your program should delete a node containing the specified
value from the list, if the list contains such a node. Otherwise, the program should print a short
message such as “The given value is not in the list”. The same message should be produced even
when the list is empty. Note that if there are two or more nodes that contain the specified value,
the delete command should only delete one of the nodes.
1
(c) Print List Command: The syntax for this command is as follows:
pri
In response to this command, your program should traverse the list and print the value stored in
each node. (Thus, the number of values printed is equal to the number of nodes in the list.) If the
list is empty, the output should be a short message such as “The list is empty”.
(d) Count Command: The syntax for this command is as follows:
cnt
In response to this command, your program should output the number of nodes in the list. (If the
list is empty, the output must be 0.)
(e) Count Distinct Values Command: The syntax for this command is as follows:
cdv
Recall that values may occur multiple times in the list. In response to the cdv command, your
program should compute and output the number of distinct values in the list. (If the list is empty,
the output must be 0.)
Example: To see the difference between the cnt and cdv commands, consider the following list.
head
1 5 5 5 7 7 /
Figure 1: An example of a linked list
For the above list, the cnt command must output the value 6 (since there are six nodes in the list)
while the cdv command must output the value 3 (since there are only three distinct values in the
list, namely 1, 5 and 7).
(f) Count Occurrences Command: The syntax for this command is as follows:
occ value
As in the insert command, value represents an integer value (which may be positive, negative or
zero). In response to this command, your program should print the number of times the specified
value occurs in the list (i.e., the number of nodes that contain the specified value). If the value
does not appear in the list (this also covers the case of an empty list), the answer produced must
be 0. (For example, in the list shown in Figure 1, the value 5 appears three times while the value
−7 appears zero times.)
2
(g) Count Range Command: The syntax for this command is as follows:
ran value1 value2
Here, value1 and value2 represent integer values (which may be positive, negative or zero). Your
program should first check and make sure that the first value is less than or equal to the second
value. If this condition is not satisfied, your program should simply print a message of the form
“Invalid range” and prompt the user for the next command. If the condition is satisfied, then
your program should compute and print the number of nodes in the list which contain values in
the range [value1 .. value2]. Note that the range includes both the end points. If none of the
the values in the range appears in the list (this also covers the case of an empty list), the answer
produced must be 0. (For example, in the list shown in Figure 1, there are six nodes with values
in the range [−1 .. 10], five nodes with values in the range [5 .. 7] and zero nodes with values in the
range [−3 .. 0].)
(h) End Command: The syntax for this command is as follows:
end
In response to this command, your program should stop.
Note: In writing this program, you may assume the following.
(a) The command given by the user will be one of ins
Three answers:
CatNip
2009-09-30 09:34:47 UTC
The question is?
?
2016-09-19 04:16:43 UTC
Heres a couple of instructions so that they can aid you fully grasp find out how to use the instructions line dir - exhibits a record of folders and records within the present listing cd - difference listing, use this with the listing you wish to difference to, for illustration while within the C:/ listing you'll use 'cd Program Files' to difference into the application records listing. To difference to the C listing variety cd C:/ and hit input. cd .. - this will likely take you down one listing, ie if you're in application records listing and variety cd .. you are going to go back to the C:/ listing. Also a useful characteristic is the tab crowning glory, in case you open a terminal and cd to the C:/ listing you'll then variety cd Pr and hit tab, it is going to difference the road to cd "Program Files" and in case you hit input will take you in which you wish to move. If you press the up and down arrows you are going to transfer by way of a historical past of the instructions you may have typed, so that you dont must preserve typing lengthy instructions again and again
?
2009-09-30 09:18:15 UTC
OK. And your question is what?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...