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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
#include <iostream>
#include <iomanip>
#include <string>
#include <stdio.h>
#include <string.h>
using namespace std;
//prototypes
void printNeighbors(int neighbor);
//string array way
//void printWordLengths(char sentence1[]);
void printWordLengths(char sentence1[], char sentence2[], char sentence3[], char sentence4[], char sentence5[]);
int main ()
{
char choice;
int count;
do
{
cout << setfill ('-')
<< setw (40)
<< "-"
<< setfill (' ')
<< endl;
cout << "N[eighbors]"
<< setw (10)
<< "W[ords]"
<< setw (10)
<< "Q[quit]"
<< endl;
cout << "Enter your choice --> ";
cin >> choice;
if (choice == 'n' || choice == 'N')
{
cout << "Enter the letter of numbers to show: ";
cin >> count;
printNeighbors(count);
}
else if (choice == 'w' || choice == 'W')
{
//These classes are really, really easy!
//character array way of doing it
char These [] = "These";
char classes [] = "classes";
char are [] = "are";
char really [] = "really";
char easy [] = "easy";
printWordLengths(These, classes, are, really, easy);
//string array of doing it
//string troll[6] = {"These", "classes", "are", "really", "really", "easy"};
//printWordLengths(troll);
}
}
while (choice != 'q' && choice != 'Q');
cout << "Bye!" << endl;
system ("pause");
return 0;
}
void printNeighbors(int neighbor)
{
//for each letter between ’e’ and ’j’ (inclusive)
//print the COUNT letters before and after each letter
//char alphabet[26] = {'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'};
cout << "The " << neighbor << " neighbors of 'e' are:" << endl;
cout << "The " << neighbor << " neighbors of 'f' are:" << endl;
cout << "The " << neighbor << " neighbors of 'g' are:" << endl;
cout << "The " << neighbor << " neighbors of 'h' are:" << endl;
cout << "The " << neighbor << " neighbors of 'i' are:" << endl;
cout << "The " << neighbor << " neighbors of 'j' are:" << endl;
}
//string array
//void printWordLengths(char sentence[])
void printWordLengths(char sentence1[], char sentence2[], char sentence3[], char sentence4[], char sentence5[])
{
//string array
//for(int i = 0; i < 6; i++)
//{
// cout << "Word #"<< i+1 << " is " << sentence[i].size() << " characters." << endl;
//}
cout << "Word #1 is " << strlen(sentence1) << " characters." << endl;
cout << "Word #2 is " << strlen(sentence2) << " characters." << endl;
cout << "Word #3 is " << strlen(sentence3) << " characters." << endl;
cout << "Word #4 is " << strlen(sentence4) << " characters." << endl;
cout << "Word #5 is " << strlen(sentence5) << " characters." << endl;
return;
}
|