Category Archives: Computer Science

Create a recursive function that converts a Roman numeral to an integer.

As the name implies, Roman numerals were developed in ancient Rome. Even after the Roman

empire fell, its numerals continued to be widely used in Europe until the late middle ages, and its numerals are still used in limited circumstances today. Roman numerals are constructed from the letters M, D, C, L, X, V and I which represent 1000, 500, 100, 50, 10, 5 and 1 respectively. The numerals are generally written from largest value to smallest value. When this occurs the value of the number is the sum of the values of all of its numerals. If a smaller value precedes a larger value then the smaller value is subtracted from the larger value that it immediately precedes, and that difference is added to the value of….

Write a main program that reads a string from the user and uses your recursive function to determine whether or not it is a palindrome.

The notion of a palindrome was introduced previously in Exercise 75. In this exercise you will write a recursive function that determines whether or not a string is a palindrome. The empty string is a palindrome, as is any string containing only one character. Any longer string is a palindrome if its first and last characters match, and if the string formed by removing the first and last characters is also a palindrome.

Write a main program that reads a string from the user and uses your recursive function to determine whether or not it is a palindrome. Then your program should display an appropriate message for the user.

Create a program that determines whether or not it is possible to construct a particular total using a specific number of coins.

Create a program that determines whether or not it is possible to construct a particular total using a specific number of coins. For example, it is possible to have a total of $1.00 using four coins if they are all quarters. However, there is no way to have a total of $1.00 using 5 coins. Yet it is possible to have $1.00 using 6 coins by using 3 quarters, 2 dimes and a nickel. Similarly, a total of $1.25 can be formed using 5 coins or 8 coins, but a total of $1.25 cannot be formed using 4, 6 or 7 coins. Your program should read both the dollar amount and the number of coins from the user. Then it should display a clear message indicating whether or….

Write a recursive function that determines whether or not a word can be spelled using only element symbols.

Each chemical element has a standard symbol that is one, two or three letters long. One game that some people like to play is to determine whether or not a word can be spelled using only element symbols. For example, silicon can be spelled using the symbols Si, Li, C, O and N. However, hydrogen cannot be spelled with any combination of element symbols.

Write a recursive function that determines whether or not a word can be spelled using only element symbols. Your function will require two parameters: the word that you are trying to spell and a list of the symbols that can be used. It will return a string containing the symbols used to achieve the spelling as its result, or an empty string if no….

Write a recursive function that determines whether or not a word can be spelled using only element symbols.

Each chemical element has a standard symbol that is one, two or three letters long. One game that some people like to play is to determine whether or not a word can be spelled using only element symbols. For example, silicon can be spelled using the symbols Si, Li, C, O and N. However, hydrogen cannot be spelled with any combination of element symbols.

Write a recursive function that determines whether or not a word can be spelled using only element symbols. Your function will require two parameters: the word that you are trying to spell and a list of the symbols that can be used. It will return a string containing the symbols used to achieve the spelling as its result, or an empty string if no….

Write a recursive function that decompresses a run-length encoded list.

Run-length encoding is a simple data compression technique that can be effective when repeated values occur at adjacent positions within a list. Compression is achieved by replacing groups of repeated values with one copy of the value, followed by the number of times that it should be repeated. For example, the list [“A”,

“A”, “A”, “A”, “A”, “A”, “A”, “A”, “A”, “A”, “A”, “A”, “B”, “B”,

“B”, “B”, “A”, “A”, “A”, “A”, “A”, “A”, “B”] would be compressed as

[“A”, 12, “B”, 4, “A”, 6, “B”, 1]. Decompression is performed by replicating each value in the list the number of times indicated. Write a recursive function that decompresses a run-length encoded list. Your recursive function will take a run-length compressed list as its only argument. It will return….

Has inflation increased or decreased since the end of 2002?

1. Figure 8 reports the inflation rate from 1960 to 2002. As this chapter states, inflation continues to be a major a factor in economic policy. Go to ftp://ftp.bls .gov/pub/special.requests/cpi/cpiai.txt. Move data into Excel using the method described at the end of Chapter2. Delete all but the first and last column (date and annual CPI). Graph this data and compare it to Figure 8.

 

a. Has inflation increased or decreased since the end of 2002?

b. When was inflation at its highest?

c. When was inflation at its lowest?

d. Have we ever had a period of deflation? If so, when?

e. Have we ever had a period of hyperinflation? If so,

when?

Draw a new diagram that reflects this arrangement and describe the hypothetical phone conversation.

1. What is the major function of the network access layer? 2. What tasks are performed by the transport layer? 3. What is a protocol? 4. What is a protocol architecture? 5. What is TCP/IP? 6. What is the purpose of the Sockets interface? 7. a. The French and Chinese prime ministers need to come to an agreement by telephone, but neither speaks the other’s language. Further, neither has on hand a

 

translator that can translate to the language of the other. However, both prime

ministers have English translators on their staffs. Draw a diagram similar to

Figure 17.8 to depict the situation, and describe the interaction at each layer.

b. Now suppose that the Chinese prime minister’s translator can translate only into

Japanese and that the….

Discuss the advantages and the disadvantages of using a fixed value for the retransmission timer.

1. In order to be able retransmit lost packets, TFTP must keep a copy of the data it sends. How many packets of data must TFTP keep at a time to implement this retransmission mechanism?

 

2. TFTP, like most protocols, will never send an error packet in response to an error packet it receives.Why?

3. We have seen that in order to deal with lost packets,TFTP implements a timeout-andretransmit scheme, by setting a retransmission timer when it transmits a packet to the remote host. Most TFTP implementations set this timer to a fixed value of about 5 seconds. Discuss the advantages and the disadvantages of using a fixed value for the retransmission timer.

o complete the coding for the client and then run the server program in one command window and the client program in each of two further command windows (so that there are two clients communicating with the server at the same time).

This exercise converts the above files into a simple email server and email

 

client respectively. The server conversion has been done for you and is

contained in file EmailServer.java, a printed version of which appears on the

following pages for ease of reference. Some of the code for the client has also

been provided for you and is held in file EmailClient.java, a printed version

of which is also provided. You are to complete the coding for the client and

then run the server program in one command window and the client program

in each of two further command windows (so that there are two clients

communicating with the server at the same time). The details of this

simplified client-server application are given below.

• The server recognises only….