So here is the question and it is really stumping me because I can print the alphabet once but cant figure out how to repeat it.
First create a character array that contains the 26 letters as shown here. //Easy I can copy and paste ha.
char cAlphabet[] = {'a','b','c','d','e','f',
'g','h','i','j','k','l','m','n','o','p',
'q','r','s','t','u','v','w','x','y','z'};
Then create a vector of strings where the first string is 'a' and the second is 'bc', the third, 'def', etc. Create the number of strings requested by the user. Once you reach the letter z, start again with first letter in the alphabet. When you are done, print each vector to the screen.
How many strings would you like to create?
8
a
bc
def
ghij
klmno
pqrstu
vwxyzab
cdefghij
Here is what I have so far it works up until 6 or 7 strings but I dont know how to fix it so that it will continue to print strings with the alphabet starting over. Anything helps, Thanks.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void printVector( vector<string> v )
{
for(unsigned int i = 0; i < v.size(); i++)
{
cout << v[i] << "\t";
}
cout << endl;
return;
}
int main()
{
int nStrings=0;
string str1=" ";
vector<string> myVector;
char cAlphabet[] = {'a','b','c','d','e','f',
'g','h','i','j','k','l','m','n','o','p',
'q','r','s','t','u','v','w','x','y','z'};
str1=cAlphabet;
string str=" ";
str= str1.substr(0,26);
cout<<str<<endl;
cout<<"How many strings would you like?"<<endl;
cin>>nStrings;
for(int i=0; i < nStrings; i++)
{
static int j=0;
j= j + i;
myVector.push_back(str.substr( j, (i+1) ));
printVector(myVector);
myVector.clear();
}
return 1;
}