Solution Manual for Data Structures and Abstractions with Java, 5th Edition Frank M. Carrano, Timothy M. Henry download
Solution Manual for Data Structures and Abstractions with Java, 5th Edition Frank M. Carrano, Timothy M. Henry download
http://testbankbell.com/product/solution-manual-for-data-
structures-and-abstractions-with-java-5th-edition-frank-m-
carrano-timothy-m-henry/
https://testbankbell.com/product/test-bank-for-data-structures-
and-abstractions-with-java-5th-edition-frank-m-carrano-timothy-m-
henry/
https://testbankbell.com/product/solution-manual-for-data-
abstraction-problem-solving-with-c-walls-and-mirrors-6-e-frank-m-
carrano-timothy-henry/
https://testbankbell.com/product/solution-manual-for-data-
abstraction-problem-solving-with-c-walls-and-mirrors-6-e-6th-
edition-frank-m-carrano-timothy-henry/
https://testbankbell.com/product/test-bank-for-data-abstraction-
problem-solving-with-c-walls-and-mirrors-6-e-frank-m-carrano-
timothy-henry/
Test Bank for Data Abstraction & Problem Solving with
C++: Walls and Mirrors, 6/E 6th Edition Frank M.
Carrano, Timothy Henry
https://testbankbell.com/product/test-bank-for-data-abstraction-
problem-solving-with-c-walls-and-mirrors-6-e-6th-edition-frank-m-
carrano-timothy-henry/
https://testbankbell.com/product/solution-manual-for-data-
structures-and-abstractions-with-java-3-e-3rd-edition-0136100910/
https://testbankbell.com/product/solution-manual-for-data-
structures-and-algorithms-in-java-1st-edition-peter-drake/
https://testbankbell.com/product/solution-manual-for-data-
structures-and-problem-solving-using-java-4-e-4th-
edition-0321541405/
https://testbankbell.com/product/solution-manual-for-java-
foundations-introduction-to-program-design-and-data-
structures-5th-edition-john-lewis-peter-depasquale-joe-chase/
Solution Manual for Data Structures and
Abstractions with Java, 5th Edition Frank M.
Carrano, Timothy M. Henry
Full chapter at:
https://testbankbell.com/product/solution-manual-for-
data-structures-and-abstractions-with-java-5th-edition-
frank-m-carrano-timothy-m-henry/
Solutions for Selected Exercises
Frank M. Carrano
University of Rhode Island
Timothy M. Henry
New England Institute of Technology
Charles Hoot
Oklahoma City University
2
Prelude: Designing Classes
1. Consider the interface NameInterface defined in Segment P.13. We provided comments for only two of the
methods. Write comments in javadoc style for each of the other methods.
/** Sets the first and last names.
@param firstName A string that is the desired first name.
@param lastName A string that is the desired last name. */
public void setName(String firstName, String lastName);
/** Changes the last name of the given Name object to the last name of this Name object.
@param aName A given Name object whose last name is to be changed. */
public void giveLastNameTo(NameInterface aName);
/** Gets the full name.
@return A string containing the first and last names. */
public String toString();
2. Consider the class Circle and the interface Circular, as given in Segments P.16 and P17.
a. Is the client or the method setRadius responsible for ensuring that the circle’s radius is positive?
b. Write a precondition and a postcondition for the method setRadius.
c. Write comments for the method setRadius in a style suitable for javadoc.
d. Revise the method setRadius and its precondition and postcondition to change the responsibility mentioned
in your answer to Part a.
a. The client is responsible for guaranteeing that the argument to the setRadius method is positive.
b. Precondition: newRadius >= 0. Postcondition: The radius has been set to newRadius.
c. /** Sets the radius.
@param newRadius A non-negative real number. */
d. Precondition: newRadius is the radius. Postcondition: The radius has been set to newRadius if newRadius
>= 0.
/** Sets the radius.
@param newRadius A real number.
@throws ArithmeticException if newRadius < 0. */
public void setRadius(double newRadius) throws ArithmeticException
{
if (newRadius < 0)
throw new ArithmeticException("Radius was negative");
else
radius = newRadius;
} // end setRadius
3
3. Write a CRC card and a class diagram for a proposed class called Counter. An object of this class will be used
to count things, so it will record a count that is a nonnegative whole number. Include methods to set the counter
to a given integer, to increase the count by 1, and to decrease the count by 1. Also include a method that returns
the current count as an integer, a method toString that returns the current count as a string suitable for display
on the screen, and a method that tests whether the current count is zero.
Counter
Counter
Responsibilities
4. Suppose you want to design software for a restaurant. Give use cases for placing an order and settling the
bill. Identify a list of possible classes. Pick two of these classes, and write CRC cards for them.
System: Orders
Use case: Place an Order
Actor: Waitress
Steps:
1.Waitress starts a new order.
2.The waitress enters a table number.
3.Waitress chooses a menu item and adds it to the order.
a. If there are more items, return to step 3.
4. The order is forwarded to the kitchen.
System: Orders
Use case: Settle Bill
Actor: Cashier
Steps:
1. The cashier enters the order id.
2. The system displays the total.
3. The customer makes a payment to the cashier.
4. The system computes any change due.
5. The cashier gives the customer a receipt.
Possible classes for this system are: Restaurant, Waitress, Cashier, Menu, MenuItem, Order, OrderItem, and
Payment.
4
Chapter 1: Bags
1. Specify each method of the class PiggyBank, as given in Listing 1-3, by stating the method’s purpose; by
describing its parameters; and by writing preconditions, postconditions, and a pseudocode version of its
header. Then write a Java interface for these methods that includes javadoc-style comments.
/**
An interface that describes the operations of a piggy bank.
@author Frank M. Carrano
@version 4.0
*/
2. Suppose that groceryBag is a bag filled to its capacity with 10 strings that name various groceries. Write Java
statements that remove and count all occurrences of "soup" in groceryBag. Do not remove any other strings from
the bag. Report the number of times that "soup" occurred in the bag. Accommodate the possibility that
groceryBag does not contain any occurrence of "soup".
int soupCount = 0;
while (bag.remove("soup"))
soupCount++;
System.out.println("Removed " + soupCount + " cans of soup.");
5
3. Given groceryBag, as described in Exercise 2, what effect does the operation groceryBag.toArray() have on
groceryBag?
4. Given groceryBag, as described in Exercise 2, write some Java statements that create an array of the distinct
strings that are in this bag. That is, if "soup" occurs three times in groceryBag, it should only appear once in
your array. After you have finished creating this array, the contents of groceryBag should be unchanged.
Object[] items = groceryBag.toArray();
BagInterface<String> tempBag = new Bag<>(items.length);
for (Object anItem: items)
{
String aString = anItem.toString();
if (!tempBag.contains(aString))
tempBag.add(aString);
} // end for
items = tempBag.toArray();
5. The union of two collections consists of their contents combined into a new collection. Add a method union to
the interface BagInterface for the ADT bag that returns as a new bag the union of the bag receiving the call to
the method and the bag that is the method’s one argument. Include sufficient comments to fully specify the
method.
Note that the union of two bags might contain duplicate items. For example, if object x occurs five times in one
bag and twice in another, the union of these bags contains x seven times. Specifically, suppose that bag1 and bag2 are
Bag objects, where Bag implements BagInterface; bag1 contains the String objects a, b, and c; and bag2 contains
the String objects b, b, d, and e. After the statement
executes, the bag everything contains the strings a, b, b, b, c, d, and e. Note that union does not affect the contents of
bag1 and bag2.
/** Creates a new bag that combines the contents of this bag and a
second given bag without affecting the original two bags.
@param anotherBag The given bag.
@return A bag that is the union of the two bags. */
public BagInterface<T> union(BagInterface<T> anotherBag);
6. The intersection of two collections is a new collection of the entries that occur in both collections. That is, it
contains the overlapping entries. Add a method intersection to the interface BagInterface for the ADT bag
that returns as a new bag the intersection of the bag receiving the call to the method and the bag that is the
method’s one argument. Include sufficient comments to fully specify the method.
Note that the intersection of two bags might contain duplicate items. For example, if object x occurs five times in
one bag and twice in another, the intersection of these bags contains x twice. Specifically, suppose that bag1 and bag2
are Bag objects, where Bag implements BagInterface; bag1 contains the String objects a, b, and c; and bag2
contains the String objects b, b, d, and e. After the statement
executes, the bag commonItems contains only the string b. If b had occurred in bag1 twice, commonItems would have
contained two occurrences of b, since bag2 also contains two occurrences of b. Note that intersection does not
affect the contents of bag1 and bag2.
/** Creates a new bag that contains those objects that occur in both this
bag and a second given bag without affecting the original two bags.
@param anotherBag The given bag.
@return A bag that is the intersection of the two bags. */
public BagInterface<T> intersection(BagInterface<T> anotherBag);
6
7. The difference of two collections is a new collection of the entries that would be left in one collection after
removing those that also occur in the second. Add a method difference to the interface BagInterface for the
ADT bag that returns as a new bag the difference of the bag receiving the call to the method and the bag that is
the method’s one argument. Include sufficient comments to fully specify the method.
Note that the difference of two bags might contain duplicate items. For example, if object x occurs five times in
one bag and twice in another, the difference of these bags contains x three times. Specifically, suppose that bag1 and
bag2 are Bag objects, where Bag implements BagInterface; bag1 contains the String objects a, b, and c; and bag2
contains the String objects b, b, d, and e. After the statement
BagInterface leftOver1 = bag1.difference(bag2);
executes, the bag leftOver1 contains the strings a and c. After the statement
BagInterface leftOver2 = bag2.difference(bag1);
executes, the bag leftOver2 contains the strings b, d, and e. Note that difference does not affect the contents of
bag1 and bag2.
/** Creates a new bag of objects that would be left in this bag
after removing those that also occur in a second given bag
without affecting the original two bags.
@param anotherBag The given bag.
@return A bag that is the difference of the two bags. */
public BagInterface<T> difference(BagInterface<T> anotherBag);
8. Write code that accomplishes the following tasks: Consider two bags that can hold strings. One bag is named
letters and contains several one-letter strings. The other bag is empty and is named vowels. One at a time,
remove a string from letters. If the string contains a vowel, place it into the bag vowels; otherwise, discard the
string. After you have checked all of the strings in letters, report the number of vowels in the bag vowels and the
number of times each vowel appears in the bag.
while (!letters.isEmpty())
{
String aLetter = letters.remove();
if (allVowels.contains(aLetter))
vowels.add(aLetter);
} // end while
7
9. Write code that accomplishes the following tasks: Consider three bags that can hold strings. One bag is named
letters and contains several one-letter strings. Another bag is named vowels and contains five strings, one for
each vowel. The third bag is empty and is named consonants. One at a time, remove a string from letters.
Check whether the string is in the bag vowels. If it is, discard the string. Otherwise, place it into the bag
consonants. After you have checked all of the strings in letters, report the number of consonants in the bag
consonants and the number of times each consonant appears in the bag.
while (!letters.isEmpty())
{
String aLetter = letters.remove();
if (!vowels.contains(aLetter))
consonants.add(aLetter);
} // end while
8
Another Random Document on
Scribd Without Any Related Topics
V.
LA MARCHESA MARIA TROTTI-BELGIOJOSO.
*
Nel 1849, durante l'assedio di Roma, noi vediamo la principessa
Belgiojoso dirigere l'ospedale dei feriti ai “Pellegrini„. È lei che chiude
gli occhi di Goffredo Mameli; è lei che, a sue spese, cura tanti
valorosi; — e le viene talvolta accanto una taciturna fanciulla, Maria,
che impara al letto del dolore, del sacrificio, della morte, il dovere
della compassione, della carità, dell'ammirazione per gli olocausti
della vita a un'idea.
Roma cade in mano dei francesi assedianti. L'inferno della mitraglia è
cessato; ma comincia un altro inferno. Gli ufficiali francesi irrompono
nelle corsie dell'ospedale, dove pure tanti loro fratelli d'armi sono
curati con eguale premura dei nostri: insolentiscono contro la
principessa Belgiojoso, e contro le altre magnanime dame
infermiere: le accusano di sobillare i francesi infermi: e la Belgiojoso
allora si rizza nella sua figura di principessa alterissima, e con tragica
veemenza, respinge l'accusa, inveisce contro l'ingratitudine e
l'insulto. Quali lampi terribili avranno lanciato quei grandi, neri occhi
fatali? Con quali gesti d'impero si saranno levate quelle pallide mani
nervose?... La principessa, fra non lievi pericoli, potè fuggire da
Roma, e condusse seco la figlia Maria in Oriente; la figlia che, molti
anni dopo, ricordava a qualche famigliare quella fuga e quei pericoli.
*
In Oriente, la vita è una nuova fantasmagoria. Viaggi lunghi penosi,
turbe di popoli semi-barbari, notti passate sotto una tenda, o sotto le
stelle, a cavallo. La madre veglia sulla figliuola, ne trema per la
salute, di tutto si priverebbe per lei; le emozioni sono forti e le
impressioni incancellabili. V'è del fantastico e del grandioso in quei
viaggi lungo l'Egeo, sulle spiagge risonanti dell'Asia Minore, e in
Terrasanta. Sul cielo azzurro immenso, ecco si disegna
Gerusalemme....
La marchesa Maria Trotti era un'alta credente. Nella religione,
trovava sublimi conforti, ma chi può dire che quella fede non le fosse
sorta, come forza sovrumana, della contemplazione della terra del
più grande evento?
Nell'Asia Minore, la principessa Belgiojoso, acquistò un possedimento
agricolo: un ciflik. Si era condotto seco uomini di fiducia,
amministratori; si era circondata di servi turchi e cristiani. E uno di
costoro, italiano, che si diceva reduce delle patrie battaglie, e
vivamente raccomandato alla principessa dal marchese Antinori
allora a Costantinopoli, pugnalò per vendetta una sera la principessa
ferendola in più parti del corpo, e voleva uccidere anche la Maria.
Furono salvate dagli altri servi, accorsi alle loro grida di soccorso. Il
servo, che voleva vendicarsi del licenziamento minacciatogli dalla
principessa perchè ubbriacone, fu disarmato, fu arrestato, cacciato in
una prigione e condannato dalle autorità turche. E la principessa,
che volle curarsi da sè stessa le ferite, una delle quali grave la
ridusse curva per tutto il resto della vita, potè da allora con più
calma lavorare per mantenere sè e la figlia e sostenere le spese del
suo possedimento, che certo non fruttava quanto la illustre profuga
s'era immaginato. Il sequestro dei beni, perpetrato dal Governo
austriaco ritornato a dominare in Lombardia, dove la principessa
Belgiojoso nel 1848, era apparsa, quasi nuova Giovanna d'Arco, alla
testa del suo battaglione di militi crociati; le enormi spese sostenute
per il mantenimento dell'ospedale dei “Pellegrini„ a Roma; quelle del
viaggio, dell'impianto agricolo e via via.... avevano ridotto a mal
partito la fortuna dell'ardimentosa signora; perciò scriveva articoli
per le riviste, e pei giornali d'America, dove propugnava la causa
d'Italia; e con la figliuola Maria ricamava stoffe che si vendevano nei
mercati di Costantinopoli. La famiglia, benchè colpita anch'essa dalle
gravissime multe dell'Austria, non mancava di spedir denaro alle due
esuli; ma quel denaro, per via, passando di mano in mano, si
assottigliava, spariva.
*
Nel 24 giugno del 1861, Maria dei principi Barbiano di Belgiojoso
andò sposa al marchese Lodovico Trotti-Bentivoglio, patrizio
milanese, ch'era vedovo della contessa Elisa Lucini Passalacqua, con
tre figlie. Così, ella di soli ventitre aprili, quando le giovani della sua
età sognano l'amore senza sùbiti sacrificii, senza gravi pensosi
doveri, assumeva nello stesso giorno delle nozze il duplice sacro
ufficio di sposa e di madre tutrice. Ebbe poi il conforto di esser
madre di due figlie proprie.
Nella primavera del 1893, moriva la contessa Adriana Marcello Zon di
Venezia, signora di bella cultura, dama di Corte della Regina
Margherita e la marchesa, già dama di palazzo, veniva eletta da Sua
Maestà a quella carica di particolare, delicata fiducia. La prima
Regina d'Italia, col suo spirito penetrante avea scoperte le rare
qualità della gentildonna milanese, qualità velate dal consueto
riserbo; e potè farsene ben presto un'amica; un'amica
profondamente devota, che, in una notte spaventevole, in una notte
atroce, in quella dell'assassinio di Re Umberto I, doveva unire le
proprie lagrime a quelle della Sovrana.
La vita di Margherita, vita di idealità e di atti eccelsi, si svolse per
vent'anni accanto alla devozione di Maria Trotti; e nessuna
meraviglia se Sua Maestà venne più volte a Milano per trovarla nel
suo letto di pene, con quella trepidazione che la grave malattia non
lasciava pur troppo dileguare.
Maria Trotti si spense a Milano, nella notte del 25 novembre 1913,
nella stessa casa dove morì la madre sua; e i funerali — a cui
parteciparono l'aristocrazia e il popolo — dicevano quanto la voce
d'una povera cieca espresse poi, al Cimitero Monumentale di Milano,
davanti alla bara, con accenti che strappavano il pianto.
Anche nella morte, la figlia si mostrò diversa dalla madre. La
principessa Cristina Belgiojoso aveva terrore della morte; benchè
vecchia, quasi mummificata, non voleva morire e lo diceva ad alta
voce; tanto, dopo una vita sì avventurosa, ell'era avvinta ancora alla
vita! La figlia Maria accolse la morte con un sorriso celeste.
Raffaello Barbiera.
INDICE.
I.
In casa Trivulzio e in casa Visconti d'Aragona
(pag. 1 a 18).
5. Archivio Trivulzio-Belgiojoso.
16. Ivi.
17. Atti Processuali della “Giovine Italia„, negli Archivii Lombardi: pezza n.
401, vol. XIV, anno 1832.
23. Questo, e tutto quanto segue, è desunto dagli Atti Segreti della
Presidenza del Governo Lombardo-Veneto e dai Processi della “Giovine
Italia„, custoditi nel R. Archivio di Milano (busta cix e seguenti).
31. Atti Segreti, vol. clxi, 1832. Vedi anche Figure e figurine di Raffaello
Barbiera pag. 226-227 (Milano, Treves).
45. R. Archivio di Stato Lombardo: Atti Segreti, busta ccxli (22 maggio
1840).
49. Atti Segreti della Presid. del Governo Lombardo: anno 1837.
55. Cantù, Alessandro Manzoni, vol. II, pag. 41 (Milano, Treves, 1882).
56. Essai sur Vico, par M.me la princesse B*** (Milan, Turati), senza data. —
La Science Nouvelle, Vico et ses œuvres, trad. par M.me C. Belgiojoso
(Milano, 1844). — La Science Nouvelle par Vico, traduite par l'auteur de
l'Essai sur la formation du dogme catholique (Paris, Renouard, 1844).
60. Le caricature (son due!) di A. de Musset furono pubblicate nel libro della
De Janzé, Étude sur A. De Musset (Paris, 1891),e riportate nell'Art di
Parigi (anno 1892, p. 193).
69. Monsieur Augustin Thierry, son système historique et ses erreurs, par L.
Aubineau, 1879.
82. Diario inedito del conte di Cavour, pubblicato per cura di Domenico Berti
(Roma, Voghera, 1888), p. 309.
91. Les Lionnes de Paris, par feu le Prince de *** (Paris, Amyot, 1843, II
vol.).
94. Di Carlo Bellerio parlo distesamente nell'viii capitolo del libro Figure e
figurine del secolo XIX con notizie inedite d'Archivii segreti di Stato
(Milano, Treves), 7ª edizione.
97. Ivi.
100.
La lettera-circolare è conservata nel Museo del Risorgimento di Milano
(N. 1353).
101.
Numero del 2 aprile 1845.
102.
Biblioteca Nazionale di Parigi. Manoscritti N. 1301 (Collection
d'autographes Lefevre).
103.
Milano, 1868. (Questo rarissimo opuscolo si trova nella Biblioteca
Nazionale di Roma.)
104.
Milano, tip. Manini, 1869.
105.
Immortali e dimenticati, di Raffaello Barbiera (Milano Cogliàti), 3ª
edizione. Capitolo: “Un'amica del Parini„.
106.
V. alla pag. 12 del I volume degli Scritti postumi di A. Manzoni (Milano,
1900).
108.
Carlo Pepoli, saggio storico di Cesare Albicini (Bologna, 1888), p. 86.
109.
Archivii di Stato di Vienna. V. A. Sandonà. (Rivista d'Italia, Giugno 1909).
110.
Archivio Casati.
111.
Brofferio, Storia del Parlamento Subalpino (Milano, Belzini, 1865), pag.
447-449.
112.
Nella stessa opera, p. 104.
113.
p. 455.
114.
Lettere di Gino Capponi e di altri a lui (Firenze, 1883), vol. II, p. 358.
115.
Le Comte de Hübner, Une année de ma vie (Paris, 1891), pag. 160.
116.
Milano, Fr. Lucca, 1848.
118.
Mémoires, documents et écrits divers laissés par le prince de Metternich,
publiés par son fils le Prince Richard de Metternich (Paris, Plon, 1883),
vol. VII, pag. 408.
119.
Opera citata, vol. VII, pag. 442.