Reverse_String_Extended_Project.AD
Reverse_String_Extended_Project.AD
#include <iostream>
#include <string>
#include <chrono>
#include <thread>
#include <fstream>
#include <cctype>
// ------------------------------
// Stack Class Definition
// ------------------------------
class Stack {
private:
char* arr;
int top;
int capacity;
public:
Stack(int size) {
arr = new char[size];
capacity = size;
top = -1;
}
~Stack() {
delete[] arr;
}
void push(char ch) {
if (top == capacity - 1) {
cout << "Stack Overflow\n";
return;
}
arr[++top] = ch;
}
char pop() {
if (isEmpty()) {
cout << "Stack Underflow\n";
return '\0';
}
return arr[top--];
}
bool isEmpty() {
return top == -1;
}
};
// ------------------------------
// Function Definitions
// ------------------------------
string reverseString(const string& str) {
Stack s(str.length());
for (char ch : str) {
s.push(ch);
}
string reversed;
while (!s.isEmpty()) {
reversed += s.pop();
}
return reversed;
}
void displayASCII() {
cout << "-------------------------------" << endl;
cout << "| Reverse String App |" << endl;
cout << "-------------------------------" << endl;
}
// ------------------------------
// Main Function
// ------------------------------
int main() {
string input;
displayASCII();
cout << "\nEnter a string to reverse: ";
getline(cin, input);
cout << "\nTime taken to reverse: " << duration.count() << " milliseconds\n";
cout << "\nLength of the entered string: " << input.length() << endl;
if (isPalindrome(input))
cout << "The entered string is a Palindrome!\n";
else
cout << "The entered string is NOT a Palindrome.\n";
if (isPalindrome(reversed))
cout << "The reversed string is also a Palindrome!\n";
else
cout << "The reversed string is NOT a Palindrome.\n";
cout << "\nReversed string in UPPERCASE: " << toUpperCase(reversed) << endl;
countCharacters(input);
saveToFile(reversed);
return 0;
}