Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Track {
- public:
- Track(int initial);
- void Submit(int enter);
- bool Find(int wanted_number);
- void print(void);
- private:
- int array[100];
- int count;
- };
- Track::Track(int initial) {
- for (int i = 0; i < 100; i++)
- {
- array[i] = 0;
- }
- array[0] = initial;
- count = 1;
- }
- void Track::Submit(int enter) {
- if (count > 100)
- {
- cout << "Error, array is full (Max is 101 entries)";
- }
- else
- {
- array[count] = enter;
- count++;
- }
- }
- bool Track::Find(int wanted_number) {
- for (int i = 0; i < count; i++) {
- if (array[i] = wanted_number) {
- return true;
- }
- }
- return false;
- }
- void Track::print(void)
- {
- for (int i = 0; i < count; i++) {
- cout << array[i] << " ";
- }
- }
- int main()
- {
- Track first(7);
- int x1, x2, x3, x4, x5;
- cout << "Enter 5 numbers, press enter between each one.";
- cin >> x1;
- cin >> x2;
- cin >> x3;
- cin >> x4;
- cin >> x5;
- first.Submit(x1);
- first.Submit(x2);
- first.Submit(x3);
- first.Submit(x4);
- first.Submit(x5);
- first.print();
- if (first.Find(20)) {
- cout << "20 is within the dataset.";
- }
- else {
- cout << "20 is not within the dataset";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement