-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWordsToStitches.cpp
55 lines (46 loc) · 1.59 KB
/
WordsToStitches.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/***********************************************************
* WordsToStitches.cpp
* Mel Mark
*
* This program compares takes a literal string and
* converts it to binary before converting to knits/purls.
* It was made for Remy in March of 2019.
***********************************************************/
#include<iostream>
// Main method that runs the other functions.
int main()
{
std::string userInput = "";
std::string inputAsBinary = "";
std::string inputAsKPs = "";
int rowSize = 0;
// getting string input
std::cout << "Please enter the phrase to be converted:\t";
getline(std::cin, userInput);
// converting to binary
for (int i = 0; i < userInput.size(); i++)
{
std::bitset<8> b(userInput.c_str()[i]);
inputAsBinary += b.to_string();
} // end for
// converting to K/Ps
for (int z = 0; z < inputAsBinary.size(); z++)
{
if (inputAsBinary[z] == '0')
inputAsKPs += 'k';
else if (inputAsBinary[z] == '1')
inputAsKPs += 'p';
} // end for
std::cout << "How many K/Ps do you want each row to have? "
"\n(Hint, your phrase contains " << inputAsKPs.size() << " K/Ps)\t\t";
std::cin >> rowSize;
std::cout << "*************************************************\nPurl/Knit pattern:"
"\n*************************************************";
// splitting string into rows
for (int x = 0; x < inputAsKPs.size(); x++)
{
if ((x % rowSize) == 0)
std::cout << std::endl;
std::cout << inputAsKPs[x];
} // end for
} // end main