RE: Here's a simple programming problem for you to solve
April 28, 2016 at 4:48 am
(This post was last modified: April 28, 2016 at 4:53 am by SteelCurtain.)
Code:
// *********************Pool's Homework****************
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
//initialize variables
string str;
int integ, len, iter, count;
//get the string and the length of output
cout << "Input the string: " << endl;
cin >> str;
cout << "Input an integer: " << endl;
cin >> integ;
iter = 1; //iterator for exponent
count = 0; //iterator for number of combinations
len = str.length(); // how many letters
const int COMB = pow(len, integ); //number of combinations
string solutions[COMB]; //an array of strings to concatenate the solutions into
for (int i = 0; i < integ; i++)
{
while (count <= COMB-1)
{
for(int j = 0; j < len; j++) //ab
{
for(int k = 0; k < pow(len,(integ-iter)); k++)
{
solutions[count] += str[j];
count++;
}
}
}
iter++;
count = 0;
}
//print solutions
cout << endl << endl << "There are " << COMB << " string combinations." << endl;
cout << "String Combinations:" << endl;
for (int i = 0; i < COMB; i++)
cout << solutions[i] << endl;
return 0;
}
You're welcome. You can PayPal me the $2k we agreed upon.
http://cpp.sh/2vh7d
"There remain four irreducible objections to religious faith: that it wholly misrepresents the origins of man and the cosmos, that because of this original error it manages to combine the maximum servility with the maximum of solipsism, that it is both the result and the cause of dangerous sexual repression, and that it is ultimately grounded on wish-thinking." ~Christopher Hitchens, god is not Great
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---
PM me your email address to join the Slack chat! I'll give you a taco(or five) if you join! --->There's an app and everything!<---