• Nie Znaleziono Wyników

erase – removig the given value from the set if exists (with memory deallocation) and returning the number of items removed (0 or 1

N/A
N/A
Protected

Academic year: 2021

Share "erase – removig the given value from the set if exists (with memory deallocation) and returning the number of items removed (0 or 1"

Copied!
1
0
0

Pełen tekst

(1)

1. Write a program which implements an unbounded sorted set (using the single or double- linked list) as a template structure (aimed at storing unique values of any type and ordering them in ascending order - from the lowest to the greatest), and the methods operating on this structure:

• the default constructor,

• the destructor (with memory deallocation),

• the copy-constructor (with memory allocation),

• the assignment operator= (with memory dellocation and allocation),

• the comparison operator==,

• insert – adding a value to the set in ascending order only if it doesn't exist in the set (with memory allocation),

• erase – removig the given value from the set if exists (with memory deallocation) and returning the number of items removed (0 or 1),

• count – returning the number of occurences of a value (0 or 1),

• empty – informing whether the set is empty,

• size – returning the number of items in the set,

• clear – removing all the items from the set (with memory deallocation).

The program should use all these methods to make the operations as follows:

1) create a set of integers containing the numbers given by the user, 2) print the number of items stored in the set,

3) remove a value from the set,

4) print the number of items stored in the set, 5) check if a given value is in the set,

6) clear the set.

Compare your implementation of the container with the built-in container set delivered in the <set> library.

2. Use the Fraction structure from the 1st task of lab 2 and implement a program working on sets of fractions (use the set implemented in task 1). Create two sets of fractions and allow the user to:

- add a fraction to one of the sets (remember that fractions 1/2 and 2/4 are eqaul, so if the user wants to add them to a single set, only one of the fractions should be finally in the set), - remove a fraction from one of the sets,

- print the items stored in the sets,

- check if a fraction is in one or both sets,

- compare the sets (whether they contain the same values).

Cytaty

Powiązane dokumenty

b) Assume that k = 4 and let’s consider events A - ,,there is at least one white ball among those drawn” and B - ,,there remain at least four black balls in the box”. A smartphone

Write a program which implements an unbounded queue (a First-In-First-Out structure using sequential memory storage), aimed at storing real numbers, and a set of methods operating

Write a program which implements an unbounded vector container (using sequential memory storage) as a template structure (aimed at storing values of any type), and

Implement an unbounded queue (using non-sequential memory storage – the linked list) as a template structure (aimed at storing values of any type), and a set of methods operating

Write a program which implements an unbounded sorted list (using the single or double- linked list) as a template structure (aimed at storing values of any type and ordering them

[r]

Figure 2.2 The economic model: a linear relationship between average per person food expenditure and income... 2.2

They include examples of calculations of the relative Nielsen number using the relative Reidemeister trace, and they discuss a connection with the fixed point theory of fiber