Write a class, named "TwoOrLess" with a header file (two_or_less.hpp) and an implementation file (two_or_less.cpp).

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In C++

Write a class, named "TwoOrLess" with a header file (two_or_less.hpp) and an implementation file (two_or_less.cpp).

This is a class that acts much like a set, except it can hold 0, 1, or 2 duplicates of an int. You need to support the insert, count, and size methods with the same parameters and return types as the set<int> class (see test cases).

 

 

#include "two or_less.hpp"
%3D
1
3
TwoOrLess thing;
ASSERT_EQ(thing.size(), 0);
thing.insert(0);
4
6.
ASSERT_EQ(thing.size(), 1);
7
YOUR CODE'S OUTPUT
IIOM
from /usr/include/gmock/gmock-actions.h:51,
from /usr/include/gmock/gmock.h:59,
29
30
31
from cpp_unit_test:0:
cpp_unit_test:3:11: error: 'thing' was not declared in this scope
ASSERT_EQ(thing.size(), 0);
32
33
34
35
cpp unit test:3:11: note: suggested alternative:
cpp unit test:4:1: error: 'thing' was not declared in this scope
'this'
36
37
thing.insert(0);
38
cpp_unit_test:4:1: note: suggested alternative:
thing.insert(0);
39
'this'
40
41
42
this
CMakeFiles/runTests.dir/tests.cpp.o' failed
CMakeFiles/runTests.dir/build.make:62: recipe for target
make[2]: *** [CMakeFiles/runTests.dir/tests.cpp.o] Error 1
43
44
Transcribed Image Text:#include "two or_less.hpp" %3D 1 3 TwoOrLess thing; ASSERT_EQ(thing.size(), 0); thing.insert(0); 4 6. ASSERT_EQ(thing.size(), 1); 7 YOUR CODE'S OUTPUT IIOM from /usr/include/gmock/gmock-actions.h:51, from /usr/include/gmock/gmock.h:59, 29 30 31 from cpp_unit_test:0: cpp_unit_test:3:11: error: 'thing' was not declared in this scope ASSERT_EQ(thing.size(), 0); 32 33 34 35 cpp unit test:3:11: note: suggested alternative: cpp unit test:4:1: error: 'thing' was not declared in this scope 'this' 36 37 thing.insert(0); 38 cpp_unit_test:4:1: note: suggested alternative: thing.insert(0); 39 'this' 40 41 42 this CMakeFiles/runTests.dir/tests.cpp.o' failed CMakeFiles/runTests.dir/build.make:62: recipe for target make[2]: *** [CMakeFiles/runTests.dir/tests.cpp.o] Error 1 43 44
1
#include "two_or_less.hpp"
3
TwoOrLess thing;
ASSERT_EQ(thing.size(), 0);
ASSERT_EQ(thing.count(0), 0);
4
thing.insert(0);
ASSERT_EQ(thing.size(), 1);
ASSERT_EQ(thing.count(0), 1);
7
8.
9.
10
11
thing.insert(1);
ASSERT_EQ(thing.size(), 2);
ASSERT_EQ(thing.count(1), 1);
ASSERT_EQ(thing.count(0), 1);
12
13
14
15
16
thing.insert(0);
YOUR CODE'S OUTPUT
cpp unit test:3:11: error: ' thing' was not declared in this scope
ASSERT_EQ(thing.size(), 0);
32
33
34
35
cpp_unit_test:3:11: note: suggested alternative: 'this'
cpp unit test:4:11: error: ' thing' was not declared in this scope
36
37
ASSERT_EQ(thing.count( 0 ), 0);
38
cpp_unit_test:4:11: note: suggested alternative: 'this'
cpp_unit_test:6:1: error: 'thing' was not declared in this scope
thing.insert(0);
39
40
41
42
cpp_unit_test:6:1: note: suggested alternative: 'this'
thing.insert(0);
43
44
45
46
this
Transcribed Image Text:1 #include "two_or_less.hpp" 3 TwoOrLess thing; ASSERT_EQ(thing.size(), 0); ASSERT_EQ(thing.count(0), 0); 4 thing.insert(0); ASSERT_EQ(thing.size(), 1); ASSERT_EQ(thing.count(0), 1); 7 8. 9. 10 11 thing.insert(1); ASSERT_EQ(thing.size(), 2); ASSERT_EQ(thing.count(1), 1); ASSERT_EQ(thing.count(0), 1); 12 13 14 15 16 thing.insert(0); YOUR CODE'S OUTPUT cpp unit test:3:11: error: ' thing' was not declared in this scope ASSERT_EQ(thing.size(), 0); 32 33 34 35 cpp_unit_test:3:11: note: suggested alternative: 'this' cpp unit test:4:11: error: ' thing' was not declared in this scope 36 37 ASSERT_EQ(thing.count( 0 ), 0); 38 cpp_unit_test:4:11: note: suggested alternative: 'this' cpp_unit_test:6:1: error: 'thing' was not declared in this scope thing.insert(0); 39 40 41 42 cpp_unit_test:6:1: note: suggested alternative: 'this' thing.insert(0); 43 44 45 46 this
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Development strategies
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education