-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSC201-palindrome(shell).cpp
137 lines (97 loc) · 3.63 KB
/
CSC201-palindrome(shell).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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <fstream>
using namespace std;
void GetFileInfo(ifstream &inData);
// Reads a string from a file and returns it
// Pre: inData is linked to a valid input file
// Post: Returns next line read from a file
string GetString(ifstream &inData);
// Takes a string and removes all spaces and special characters, and converts
// to upper case, returning the result
// Pre: inString contains a string
// Post: Returns a string with all spaces and special characters removed and
// converted to upper case
string NormalizeString(string inString);
// Takes a string and reverses its order
// Pre: inString contains a string
// Post: Returns inString in reversed order
string ReverseString(string inString);
// Test to see if a passed string is a palindrome
// Pre: normalString has all spaces and special characters removed and is in
// upper case
// Post: Rerturns true if normalString is a palindrome, false otherwise.
bool isPalindrome(string normalString);
int main()
{
ifstream inData; // Hold link to file
string inString; // Hold string read from file
string normalString; // Hold normalized string
// Get filename and open file
GetFileInfo(inData);
// Priming read
inString = GetString(inData);
// Loop as long as there's data in file
while (inData) {
// Echo string read from file
cout << inString;
// Reverse string and echo to string as specified
cout << ReverseString(inString);
// Normalize the string
normalString = NormalizeString(inString);
// Test normalized string
if (isPalindrome(normalString))
cout << "Yay!\n";
else
cout << "Boo!\n";
// Get next string from file
inString = GetString(inData);
}
// Close input file
inData.close();
}
string GetString(ifstream &inData){
cout << "GetString\n";
// declare string to hold data from file
// get string from file
// return string
return ""; // Placeholder to make shell run
}
string NormalizeString(string inString){
cout << "NormalizeString\n";
// Declare local variable to hold normalized string
// Loop through each character of inString
// If character is a letter
// Convert to uppercase
// Keep in string
// Return normalized string
return ""; // Placeholder to make shell run
}
string ReverseString(string inString){
cout << "ReverseString\n";
// Declare local variable to hold reversed string
// Loop through each character of inString from last to first
// Add character to reversed string
// Return reversed string
return ""; // Placeholder to make shell run
}
bool isPalindrome(string normalString){
cout << "isPalindrome\n";
// Loop through each character in normalString from first to last (ch1) and last to first (ch2)
// If ch1 != ch2 then not a Palindrome (return false)
// If full string tested then must be a palindrome (return true)
return true;
}
// Prompt user for file name and return ifstream
// Pre: inData declared
// Post: inData contains valid ifstream for data file
void GetFileInfo(ifstream& inData){
string filename;
do {
// Prompt user for file name and open file
cout << "Enter file containing input values: ";
cin >> filename;
inData.open(filename.c_str());
if (!inData)
cout << "Invalid file!\n\n";
} while (!inData); // Loop until valid file name provided
}