[Solved] LSOLVED:aboratory Exercise Week 9 solution

$25

File Name: LSOLVED:aboratory_Exercise_Week_9_solution.zip
File Size: 395.64 KB

SKU: [Solved] LSOLVED:aboratory Exercise Week 9 solution Category: Tag:
5/5 - (1 vote)

Task One: A singletonImplement a singleton class in Single.cpp. In a singleton we are only allowed one instance of the class to exist at a time. Your class should record how many attempts to create instances have occurred. Your class should request from the user whether to create an instance (2), destroy an instance (1) or exit (0).Sample input and output are provided in Input_Single.txt and Single.txt, respectively.Task Two: Namespace and a template class BagDefine a template class Bag in a file Bag.h that belongs to a namespace MYLIB. A Bag is a collection of zero or more elements, in no particular order that may have duplicates. The public interface consists of methods to: Create a template class Bag. A function add() which can add an element to a Bag. A function remove() which can remove a given element from a Bag. If the element is duplicated, only remove the first one. Implement the union of two Bag objects in an overloaded + operator. The union of two Bag objects, b1 and b2, should be a Bag object containing elements that belong to b1 or b2. Remember that duplication is fine. An insertion operator (<<) that print all the elements in the Bag.Implement member functions and insertion operator for the Bag in a file Bag.cpp.Download the file testBag.cpp in which instantiates and initialize two integer Bag objects and two double Bag objects to test your Bag class.Compile the program asCC testBag.cpp Bag.cppand run the program.Number of integers for an integer bag 1: 5Input an integer: 1Input an integer: 3Input an integer: 4Input an integer: 6Input an integer: 9The first integer bag contains: 1 3 4 6 9Number of integers for an integer bag 2: 3Input an integer: 1Input an integer: 6Input an integer: 8The second integer bag contains: 1 6 8Combine two integer bags: 1 3 4 6 9 1 6 8Input the element that needs to be removed: 1After the element 1 has been removed, the bag contains 3 4 6 9 1 6 8Input the element that needs to be removed: 6After the element 6 has been removed, the bag contains 3 4 9 1 6 8Number of doubles for a double bag 1: 6Input a double: 1.5Input a double: 2.2Input a double: 3.2Input a double: 1.5Input a double: 2.4Input a double: 2.2The first double bag contains: 1.5 2.2 3.2 1.5 2.4 2.2Number of doubles for a double bag 2: 4Input a double: 2.2Input a double: 3.3Input a double: 4.1Input a double: 3.2The second double bag contains: 2.2 3.3 4.1 3.2Combine two double bags: 1.5 2.2 3.2 1.5 2.4 2.2 2.2 3.3 4.1 3.2Input the element that needs to be removed: 1.5After the element 1.5 has been removed, the bag contains 2.2 3.2 1.5 2.4 2.2 2.2 3.3 4.1 3.2Input the element that needs to be removed: 4.1After the element 4.1 has been removed, the bag contains 2.2 3.2 1.5 2.4 2.2 2.2 3.3 3.2You can download input_bag.txt to test your program by

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] LSOLVED:aboratory Exercise Week 9 solution
$25