Question

In: Computer Science

Question 1) The Following OOP Problem must be completed in C++ Consider a bubble gum dispenser.The...

Question 1)

The Following OOP Problem must be completed in C++

Consider a bubble gum dispenser.The dispenser releases one bubble gum at a time until empty. Filling of the dispenser adds a positive number of bubble gums.

A) Write an Abstract Data Type for a bubble gum dispenser

B) Draw the UML class diagram

C) Define a C++ class for a bubble gum dispenser object

D) The number of bubble gums in the dispenser is private

E) Write an implementation for the class

F) Write a simple test program to demonstrate that your class is implemented correctly

Solutions

Expert Solution

We need to create a Bubble Gum Dispenser.

There is only one value that we need to keep track of, and that's the number of bubblegum inside the dispenser.

There are only functions available for a dispenser, either we can take out a bubble gum or we can fill it up. We can only obtain a bubble gum if the dispenser is not empty.

What is Abstract Data Type ?

An abstract data type (ADT) is a mathematical model for a certain class of data structures that have similar behavior (only behavior is defined but not implementation). Real life example: book is Abstract (Telephone Book is an implementation)

Hence an abstract data type for this question can be Dispenser object which has 1 function (to dispense whatever it holds), another function that is done on it (refill) and only one value to store (quantity of whatever it holds).

UML Diagram

We can also define a user class to show how our class interactd with the world

C++ Class

class bubblegum
{
private :
  
int quantity;
  
public :
  
bubblegum(int x = 0)
  
{
  
quantity = x;
  
}
  
void refill(int x)
{
quantity += x;
}
  
void dispense()
{
if(quantity > 0)
quantity--;
}
};

Example Program :

Hope this helps!


Related Solutions

If the price elasticity of demand for bubble gum is -1, the elasticity is classified as:...
If the price elasticity of demand for bubble gum is -1, the elasticity is classified as: Group of answer choices Unitary Inelastic Elastic
1) Consider a soap bubble with radius, r. The pressure inside the bubble must be greater...
1) Consider a soap bubble with radius, r. The pressure inside the bubble must be greater than the pressure outside of the bubble. The surface tension of the bubble, y, supports the difference in pressure, delta p. Using dimensional analysis, formulate an expression for the pressure difference. 2) In 1945 the first atomic bomb was tested in New Mexico. The destructive power (Energy) of the bomb was kept classified however, following the release of *time* stamped pictures showing the bomb's...
Define a problem utilizing Stacks. Write the design, code and display output. please in c++ oop?
Define a problem utilizing Stacks. Write the design, code and display output. please in c++ oop?
Question 1 A digital SWOT must: a. Be digitally-focused b. Be credibly-sourced c. Consider all 4Ps...
Question 1 A digital SWOT must: a. Be digitally-focused b. Be credibly-sourced c. Consider all 4Ps in the marketing mix d.All of the above Question 2 Art is In Bakery is an edgy gastro-bakery built to satisfy any craving. After running the website through the Website Grader, it gave the following base information: score: 49. This site could be better. 24/30 performance: page requests slowing site speed. Which best explains what should be improved in the digital SWOT for Art...
needs to be done in C++ Q6. Coding Question (you must code this problem and submit...
needs to be done in C++ Q6. Coding Question (you must code this problem and submit via Blackboard): Keep everything as Integers. Row and Column Numbering starts at 1. Equation for each Cell :   Coll = (Row * Col * 10) Using Nested Loops display the following exactly as it is shown below:                                  Columns % Brand         1           2         3          4               A            10         20       30       40          B            20         40        60       80           C            30         60        90    ...
THE FOLLOWING MUST BE CODED IN C THE FOLLOWING MUST BE CODED IN C THE FOLLOWING...
THE FOLLOWING MUST BE CODED IN C THE FOLLOWING MUST BE CODED IN C THE FOLLOWING MUST BE CODED IN C   THE FOLLOWING MUST BE CODED IN C Write a program that demonstrates handling pointers. Create two integer variables m and n, and two pointers, pm pointing to m, and pn pointing to n. Produce the following output: Address of m: 0x7ffcc3ad291c Value of m: 29 Address of n: 0x7ffcc3ad291d Value of n: 34 Now pm is pointed to m...
The following question must be answered in the C programming language and may not be written...
The following question must be answered in the C programming language and may not be written in C++ or any other variation. Problem 5 This problem is designed to make sure you can write a program that swaps data passed into it such that the caller's data has been swapped. This is something that is done very frequently in manipulating Data Structures. The Solution / Test Requirements I want your program to demonstrate that you understand how to swap information...
Consider the following problem: You are working at the Johnson Center Cinema. The theatre must keep...
Consider the following problem: You are working at the Johnson Center Cinema. The theatre must keep track of the titles and lengths of all movies shown in the theatre. You may assume no two movies will have the same length. The theatre manager wants to know which movie is the shortest, so she can consider offering a discount for the movie. At any given time, the theatre can have up to 5 movies playing. Create an object oriented solution that...
Please use C++, linked list and Bubble Sort to slove this problem. #include <iostream> #include <time.h>...
Please use C++, linked list and Bubble Sort to slove this problem. #include <iostream> #include <time.h> using namespace std; struct ListNode { int data; ListNode *next; ListNode(int x) : data(x), next(nullptr) {} }; class LinkedList { private: ListNode *head = nullptr; public: void addNode(int x) { ListNode *p = new ListNode(x); if (head == nullptr) head = p; else { ListNode *q = head; while (q->next != nullptr) q = q->next; q->next = p; } } void display() { ListNode...
Please explain Question 1 Consider the following linear programming problem: Maximize 3.5x1 + 7x2 Subject to...
Please explain Question 1 Consider the following linear programming problem: Maximize 3.5x1 + 7x2 Subject to 4x1 + 3x2 > =12 -4x1 - 6x2 =< 12 x2 > =3 x1, x2 > 0 The above linear programming problem: exhibits unboundedness Question 2 Consider the following linear programming Minimize 6x1 + 4x2 Subject to 5x1 + 3x2 =< 15 6x1 + 8x2 > =48 x2 > =6 x1, x2 > 0 The above linear programming problem: exhibits infeasibility
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT