Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Data Abstraction & Problem Solving with C++

Rating
-
Sold
-
Pages
333
Grade
A+
Uploaded on
18-02-2026
Written in
2025/2026

Data Abstraction & Problem Solving with C++.With Solutions.A+ Assured!!!!

Institution
Data Abstraction & Problem Solving With C++
Course
Data Abstraction & Problem Solving with C++

Content preview

Solutions to Selected Exercises

(Version 7.0)



Data Abstraction & Problem Solving with C++

Seventh Edition




Frank M. Carrano
University of Rhode Island
Timothy M. Henry
New England Institute of Technology

, 2


Solution Manual & Test Bank for Data Abstraction & Problem Solving with C++: Walls and Mirrors, 7th Edition by Frank M. Carrano




Chapter 1 Data Abstraction: The Walls
1
const CENTS_PER_DOLLAR = 100;

/** Computes the change remaining from purchasing an item costing
dollarCost dollars and centsCost cents with d dollars and c cents.
Precondition: dollarCost, centsCost, d and c are all nonnegative
integers and centsCost and c are both less than CENTS_PER_DOLLAR.
Postcondition: d and c contain the computed remainder values in
dollars and cents respectively. If input value d < dollarCost, the
proper negative values for the amount owed in d dollars and/or c
cents is returned. */
void computeChange(int dollarCost, int centsCost, int& d, int& c);

2a
const MONTHS_PER_YEAR = 12;
const DAYS_PER_MONTH[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

/** Increments the input Date values (month, day, year) by one day.
Precondition: 1 <= month <= MONTHS_PER_YEAR,
1 <= day <= DAYS_PER_MONTH[month - 1], except
when month == 2, day == 29 and isLeapYear(year) is true.
Postcondition: The valid numeric values for the succeeding month, day,
and year are returned. */
void incrementDate(int& month, int& day, int& year);

/** Determines if the input year is a leap year.
Precondition: year > 0.
Postcondition: Returns true if year is a leap year; false otherwise. */
bool isLeapYear(int year);

3a
changeAppointmentPurpose(apptDate: Date, apptTime: Time, purpose: string): boolean
{
if (isAppointment(apptDate, apptTime))
cancelAppointment(apptDate, apptTime)

return makeAppointment(apptDate, apptTime, purpose)
}




© 2017 Pearson Education, Inc., Hoboken, New Jersey 07030

, 3



3b
displayAllAppointments(apptDate: Date): void
{
time = START_OF_DAY
while (time < END_OF_DAY)
if (isAppointment(apptDate, time))
displayAppointment(apptDate, time)
time = time + HALF_HOUR
}
This implementation requires the definition of a new operation
displayAppointment()
as well as definitions for the constants START_OF_DAY, END_OF_DAY and HALF_HOUR.


4
// Assume that storeBag is defined and contains your purchased items
Bag<std::string> fragileBag;
while (storeBag.contains("eggs"))
{
storeBag.remove("eggs");
fragileBag.add("eggs");
} // end while

while (storeBag.contains("bread"))
{
storeBag.remove("bread");
fragileBag.add("bread");
} // end while

// Transfer remaining items from storeBag to groceryBag;
Bag<std::string> groceryBag;
v = storeBag.toVector();
for (int i = 0; i < v.size(); i++)
groceryBag.add(v.at(i));




© 2017 Pearson Education, Inc., Hoboken, New Jersey 07030

, 4



5
/** Removes and counts all occurrences, if any, of a given string
from a given bag of strings.
@param bag A given bag of strings.
@param givenString A string.
@return The number of occurrences of givenString that occurred
and were removed from the given bag. */
int removeAndCount(ArrayBag<std::string>& bag, std::string givenString)
{
int counter = 0;
while (bag.contains(givenString))
{
counter++;
bag.remove(givenString);
} // end while
return counter;
} // end removeAndCount



6
/** Creates a new bag that combines the contents of this bag and a
second bag without affecting the contents of the original two bags.
@param anotherBag The second bag.
@return A bag that is the union of the two bags. */
public BagInterface<ItemType> union(BagInterface<ItemType> anotherBag);



7
/** Creates a new bag that contains those objects that occur in both this
bag and a second bag without affecting the contents of the original two bags.
@param anotherBag The given bag.
@return A bag that is the intersection of the two bags. */
public BagInterface<ItemType> intersection(BagInterface<ItemType> anotherBag);



8
/** Creates a new bag of objects that would be left in this bag after removing
those objects that also occur in a second bag without the contents of 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);




© 2017 Pearson Education, Inc., Hoboken, New Jersey 07030

Written for

Institution
Data Abstraction & Problem Solving with C++
Course
Data Abstraction & Problem Solving with C++

Document information

Uploaded on
February 18, 2026
Number of pages
333
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$18.89
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
Gradechaser

Get to know the seller

Seller avatar
Gradechaser Harvard University
View profile
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
10 months
Number of followers
1
Documents
12
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions