Write a C++ program that finds all the unique combinations of three numbers in a
ID: 3576409 • Letter: W
Question
Write a C++ program that finds all the unique combinations of three numbers in a sequence of numbers that add to a requested sum. In addition, the program will read in the starting list of numbers from a file, allow the user to update and change the starting sequence of numbers, use data validation for user entries, calculate and display statistics, and write out the final results to a file. The numbers are: 33, 31, 14, 37, 30, 11, 17, 27, 22, 35, 1, 19, 26, 12, 48, 10, 18, 42. Once the data is read in, it should be displayed in an easily readable fashion. The user should be allowed to add data, delete, or change data using an appropriate prompt (position for example.) After each change, the starting sequence should be redisplayed. An appropriate prompt should be used until the user is finished. Starting sequences will always have unique integer numbers greater than 0 and the count will be divisible by 3. The program should recognize if a number entered is already in the sequence and not allow duplicates. The sequence consists of unique numbers. During any prompting by the user, appropriate data validation should be used. After the starting sequence is imported and edited, the program should request an integer search sum, validating the input. This portion of the program should loop until the user is finished. For any search sum entered, the program should display the following: the search sum, the number of unique combinations and a list of each combination. The combinations must be in order from left to right as they appear in the starting sequence. After completing the Search Sum, the program then moves on to Count Statistics. The program should prompt the user for two values, Min Sum and Max Sum. The program should then produce a table. After Search Statistics, the program should produce a bar graph using ****s for the last statistics table run. Example:
Table Sun Count 21 23 24 26 27 28 30 31 33 34 36 38 39 40 Bar Graph. After Search Statistics, the program should produce a bar graph using ****s for the last statistics table run in section 11. For a count of 1 use for 2 use The bar graphs for Figure 2 is shown in Figure 3. Above 15, fix the number of s to 15. and a Column Graph display the Bar Graph in section 12 as a column graph. Figure 4 is an example but the numbers can be rotated and 20 displayed as 20 21 etc. 21 25* 26 28* 29 31** 33*** 34** 35 36** 37 38**** 39**** 40*Explanation / Answer
#include <iostream.h>
#include <fstream.h>
#include <string.h>
class Strategy;
class TestBed
;
TestBed()
void setStrategy(int sort, int width);
void doIt();
private:
Strategy *strategy_;
};
class Strategy
void format()
one > width_)
justify(line);
else
strcat(line, " ");
strcat(line, word);
}
justify(line);
}
protected:
int width_;
private:
virtual void justify(char *line) = 0;
};
class LeftStrategy: public Strategy
private:
/* virtual */void justify(char *line)
};
class RightStrategy: public Strategy
private:
/* virtual */void justify(char *line)
};
class CenterStrategy: public Strategy
private:
/* virtual */void justify(char *line)
};
void TestBed::setStrategy(int sort, int width)
void TestBed::doIt()
int main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.