-
-
Save bemasher/ba32346393a1d112f63a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CountLT.cpp | |
//Aryelle Young | |
//Sep 23 2014 | |
//Defines the CountLT class | |
#include "CountLT.h" | |
//Default Constructor | |
//takes a value from client code to use as initial bound | |
CountLT::CountLT(double bound) : the_bound(bound), count(0) | |
{ | |
} | |
//Destructor | |
CountLT::~CountLT() | |
{ | |
} | |
//Mutators | |
//Post: entry has been added to the collection tracked by CountLT. | |
void CountLT::put(double entry) | |
{ | |
if (entry < the_bound) | |
{ | |
count++; | |
} | |
} | |
//Accessors | |
//Post: the number of items less than the_bound has been returned. | |
int CountLT::get() | |
{ | |
return count; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CountLT.h | |
//Aryelle Young | |
//Sep22 2014 | |
//An accumulator class whose objects | |
//count the number of entries in a | |
//sequence that are less than a given bound. | |
#ifndef _COUNTLT_H_ | |
#define _COUNTLT_H_ | |
class CountLT | |
{ | |
public: | |
//Default constructor | |
CountLT(double bound); | |
//Destructor | |
~CountLT(); | |
//Mutators | |
void put(double entry); | |
//Accessors | |
int get(); | |
private: | |
//Data members | |
int count; | |
double the_bound; | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// main.cpp | |
// Aryelle Young | |
// Sep 24 2014 | |
// Intended as a driver to test the functionality of class CountLT. | |
#include <iostream> | |
#include <iomanip> | |
#include "CountLT.h" | |
using namespace std; | |
int main() | |
{ | |
//Initial test of CountLT | |
CountLT testLessThan(13.13); | |
cout << "Count for new object testLessThan is " << testLessThan.get() << endl; | |
testLessThan.put(0.98); | |
testLessThan.put(-87.322); | |
testLessThan.put(14.1); | |
testLessThan.put(13.780); | |
testLessThan.put(51.00); | |
cout << endl; | |
cout << "After adding the quantities 0.98, -87.322, 14.1, 13.780, and 51.00 "; | |
cout << "to the collection tracked by the testLessThan object, the count is "; | |
cout << testLessThan.get() << endl; | |
testLessThan.put(13.109); | |
testLessThan.put(0); | |
testLessThan.put(7564.932); | |
cout << endl; | |
cout << "After adding the quantities 13.109, 0, and 7564.932 to the "; | |
cout << "collection tracked by testLessThan, the count is " << testLessThan.get(); | |
cout << endl; | |
cout << endl; | |
double sequence[] = { -54.88, 99.15, 49.821, 100.936, 1.234, 0.7562, -0.624, 8256.777, 30.826, 71 }; | |
double upper_bound = 55.00; | |
double lower_bound = 5.00; | |
cout << "Given the sequence: " << endl; | |
for (int i = 0; i < 10; i++) | |
{ | |
cout << setw(14) << sequence[i] << endl; | |
} | |
CountLT upper_tracker(upper_bound); | |
CountLT lower_tracker(lower_bound); | |
for (int i = 0; i < 10; i++) | |
{ | |
upper_tracker.put(sequence[i]); | |
lower_tracker.put(sequence[i]); | |
} | |
int countBetween = upper_tracker.get() - lower_tracker.get(); | |
cout << endl; | |
cout << "The number of entries between " << upper_bound; | |
cout << " and " << lower_bound << " is " << countBetween; | |
cout << "." << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main: main.cpp CountLT.cpp | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment