Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The EGR126 project #2 requires a C++ program that finds all the unique combinations of three numbers in a sequence of numbers that add to

The EGR126 project #2 requires 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. Example: List of 18 numbers to be analyzed. The list is not allowed to be sorted. Numbers: 33, 31, 14, 37, 30, 11, 17, 27, 22, 35, 1, 19, 26, 12, 48, 10, 18, 42 Example results in order from left to right. If search sum equals 20, there are 0 unique combinations. If search sum equals 33, there are 3 unique combinations. 1. 14, 1, 18 2. 11, 12, 10 3. 22, 1, 10 If search sum equals 50, there are 10 unique combinations. 1. 31, 1, 18 2. 14, 17, 19 3. 14, 35, 1 4. 14, 26, 10 5. 37, 1, 12 6. 30, 1, 19 7. 11, 17, 22 8. 11, 27, 12 9. 27, 22, 1 10. 22, 10, 18 Figure 1. Example Find the 3 for file1 input. EGR 126 C++ Course Project #2 2 The program requirements are as follows. 1. All programs must be completed by an individual. No sharing of code. 2. The cpp file must be labeled xxxPRJ.cpp where xxx are your lower-case initials. 3. The project must include 2 functions that are contained in separate cpp files. It is encouraged to code the project using more functions and keeping the main () as simple as possible. 4. The project should be well commented. 5. All files must be uploaded to Blackboard by midnight, 4/22/18. 6. The program should have a menu with items for each operation. An example is given in Figure 2. Figure 2. Options for the Find the 3 Program. 7. File inpu EGR 126 C++ Course Project #2 3 8. Starting Sequence. This portion of the program should loop until the user is finished. 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. A suggestion is to display and use the index or position of the numbers for referencing to the numbers in this section. After each alteration, 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 does not need to check if the total count is divisible by 3. The program does need to recognize if a number entered is already in the sequence because duplicates are not allowed. 9. Search Sum. 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. (You cant list item 1 below as 1, 14, 18 or 18, 14, 1.) For a search sum of 33, there are 3 unique combinations. 1. 14, 1, 18 2. 11, 12, 10 3. 22, 1, 10 Figure 4. Example search sum. To determine a search algorithm for the search sum, the programmer should use a simple number sequence, 6 numbers for example, and write out by hand each possible combination. As you move through the list of numbers, you will find that there is a looping pattern that can be coded. Make sure to code the search sum algorithm so that is doesnt assume a total count in the starting sequence as this will vary. (We could use 6, 9, 12, 39 numbers for example. Any count total divisible by 3.) 10. Count Statistics. 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 (feel free to customize) as shown in Figure 5. This table displays the count of all combinations that add to the sum displayed. So in Figure 2, for search sum = 30, there are 3 possible unique combinations. This Table is an application of item 10. EGR 126 C++ Course Project #2 4 Figure 5. Example count for Min Sum = 20 to Max Sum = 40 for file1.txt. After the table is generated, the following statement is to be displayed. For Min Sum = 20 and Max Sum = 40, the sum(s) with the lowest count is(are) 20 and 21 with a count of 0. For Min Sum = 20 and Max Sum = 40, the sum(s) with the highest count is(are) 40 with a count of 5. 11. 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 6. Above 15, fix the number of *s to 15. Figure 6. Example Bar Graph for Min Sum = 20 to Max Sum = 40 for file1.txt. EGR 126 C++ Course Project #2 5 . 12. Column Graph Extra Credit. For 20 points extra credit, display the Bar Graph in section 11 as a column graph. Figure 7 is an example but the numbers can be rotated and displayed as 20 21 etc. (To get the full extra credit, you must rotate the numbers). Figure 7. Column Graph for Min Sum = 20 to Max Sum = 40 for file1.txt. 13. Output File. After completing the graphing, the program should write the search statistics (section 10) to an output file. The program should prompt for the file and append txt. It should check to see if the file exists and ask if an existing file is allowed to be overwritten. 14. Data Validation. During any prompting by the user, appropriate data validation should be used, Chapter 9. For example, check for a non-integer during updating of the starting sequence. If requesting a yes or no, make sure the correct letters are entered, see do while examples, Chapter 5 for example

This is what i have so far as a solution but it doesn't run and is not completely finished.

#include "Header.h"

#include

#include

#include

#include

using namespace std;

void fileinput(vector&);

void fileoutput(vector&);

void startingsequence(vector&);

void isvalid;

int main()

{

int op; //menu option

vector nums(0);

vector count(0);

cout << "Welcome to find the three ";

//

//created menu

//

cout << "Enter the following operation" << endl;

cout << "1: file input " << endl;

cout << "2: Starting sequence " << endl;

cout << "3: search sum " << endl;

cout << "4: Count statistics" << endl;

cout << "5: Bar graph" << endl;

cout << "6: Column graph" << endl;

cout << "7: File output " << endl;

cout << "8: Exit ";

do

{

cout << "Please enter a menu item ";

cin >> op;

cin.ignore();

switch (op)

{

case 1:

cout << "you entered file input ";

fileinput(nums);

for (int i = 0; i < nums.size(); i++)

cout << nums.at(i) << endl;

break;

case 2:

startingsequence(nums);

case 3:

//you entered search sum

case 4:

//you entered count statistics

case 5:

//you entered bar graph

case 6:

//you entered column graph

case 7:

cout << "you entered file output ";

count.push_back(3);

count.push_back(10);

fileoutput(count);

break;

case 8:

cout << "You entered exit ";

break;

default:

cout << "incorrect entry";

}

} while (op != 8);

cout << "Thanks for playing Find the 3 ";

system("pause");

}//end main

void fileinput(vector&n)

{

// enter declarations

filename = "file1.txt";

/*cout << " Please enter a filename ";

cin.ignore();

getline(cin, filename);

filename = filename + ".txt";*/

inFile.open(filename);

if (inFile.fail())

{

cout << " The file was not sucessfully opened."

<< " Please check that the file current exists."

<< endl;

cin.ignore();

cin.get();

exit(1);

}

inFile.close();

for (int i = 0; i < n.size(); i++)

cout << n.at(i) << endl;

return;

}

void fileoutput(vector&n)

{

}

bool isvalidint(string str)

void startingsequence(vector&n)

{

int i;

//display the vector

for (i = 0; i < n.size(); i++)

cout << i << " " << n.at(i) << endl;

i = 5;

n.erase(n.begin() + 1);

for (i = 0; i < n.size(); i++)

cout << i << " " << n.at(i) << endl;

return;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 1 Lnai 9851

Authors: Paolo Frasconi ,Niels Landwehr ,Giuseppe Manco ,Jilles Vreeken

1st Edition

3319461273, 978-3319461274

More Books

Students also viewed these Databases questions

Question

understand the meaning of the terms discipline and grievance

Answered: 1 week ago