aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lab6_taormina.txt244
-rw-r--r--mod11c.cpp14
2 files changed, 256 insertions, 2 deletions
diff --git a/lab6_taormina.txt b/lab6_taormina.txt
index 05d6af5..0b8eba6 100644
--- a/lab6_taormina.txt
+++ b/lab6_taormina.txt
@@ -273,10 +273,252 @@ pg 292-293
#1 for 10pts
CODE:
+// Tyler Taormina
+// CST 116
+// Module 11c
+//
+
+#include <iostream>
+#include <cstring>
+#include <string>
+
+#define MAX 50
+
+using namespace std;
+
+void isPalindrome();
+void isAlpha();
+void countChar();
+void DisplayMenu(int&);
+void ProcessMenuChoice(int);
+
+int main() {
+ //main call to project.
+
+
+ int user_choice;
+
+ cout << "=================================================================" << endl;
+ cout << "PROGRAM RUNNING.." << endl;
+ cout << "=================================================================" << endl;
+ cout << endl;
+
+ DisplayMenu(user_choice);
+ ProcessMenuChoice(user_choice);
+
+ return 0;
+
+}
+
+
+void DisplayMenu(int& user_choice)
+{
+ // displays a selection of choices for the user to pick from.
+ // updates user_choice by reference.
+
+ cout << "Choose what you would like to check for in a word" << endl;
+ cout << "that you will enter..." << endl;
+ cout << "=================================================================" << endl;
+ //displays the menu of functions for the user to choose from
+
+ cout << "1) Check for palindrome.\n";
+ cout << "2) Check for all alpha.\n";
+ cout << "3) Count the number of times a letter is in a word.\n";
+ cout << "4) Exit Program.\n\n";
+ cout << "Enter: ";
+ cin >> user_choice;
+ if (user_choice > 4 || user_choice< 1) {
+ cout << "Invalid Entry. Please enter a number from the options list provided.\n\n\n\n" << endl;
+ DisplayMenu(user_choice);
+ }
+}
+
+
+
+void ProcessMenuChoice (int menu_choice) {
+ // Uses the user menu choice input to determine which function to call.
+ // Also controls the ending or restarting of program.
+
+ int program_rerun = 0;
+ switch(menu_choice){
+ case 1:
+ isPalindrome();
+ break;
+
+ case 2:
+ isAlpha();
+ break;
+
+ case 3:
+ countChar();
+ break;
+
+ case 4:
+ cout << "Are you sure you want to exit? Enter any number other than 1 to end program." << endl;
+ break;
+
+ default:
+ break;
+ }
+ cout << "Press 1 and enter to rerun program. Enter any other number to close program: ";
+ cin >> program_rerun;
+
+ if (program_rerun == 1)
+ main();
+ else {
+ cout << "================================================================" << endl;
+ cout << "Program Closing..." << endl;
+ cout << "================================================================\n\n\n" << endl;
+ }
+}
-RUN:
+void isPalindrome ()
+{
+ // checks a word to see if the reverse spelling is the same as the
+ // normal spelling. For example 'lol' reversed would be 'lol'. 'pop'
+ // reversed would be 'pop'.
+
+ char string1[MAX];
+ int i, length;
+ int flag = 0;
+
+ cout << "Enter a string: "; cin >> string1;
+
+ length = strlen(string1);
+
+ for(i=0;i < length ;i++){
+ if(string1[i] != string1[length-i-1]){
+ flag = 1;
+ break;
+ }
+}
+
+ if (flag) {
+ cout << string1 << " is not a palindrome" << endl;
+ }
+ else {
+ cout << string1 << " is a palindrome" << endl;
+ }
+}
+
+
+void isAlpha ()
+{
+ //checks to make sure that the only characters in the string are
+ // either numbers or letters.
+
+ char str[MAX];
+ int i;
+
+ cout << "Enter a string to test: ";
+ cin >> str;
+
+ for (int i = 0; str[i] != '\0'; i++)
+ {
+ if (!isalnum(str[i]))
+ {
+ cout << str[i] << " is not alphanumeric" << endl;
+ }
+ }
+}
+
+
+void countChar ()
+{
+ //counts the number of times that a certain character shows
+ // up in a string.
+
+ std::string string1;
+ char ch;
+ cout << "Please enter a word: "; cin >> string1;
+ cout << "Please enter a character to count: "; cin >> ch;
+
+ int count = 0;
+ for (int i = 0; (i = string1.find(ch, i)) != std::string::npos; i++) {
+ count++;
+ }
+
+ std::cout << "Character " << ch << " occurs " << count << " times" << endl << endl;
+
+}
+
+
+
+RUN:
+
+=================================================================
+PROGRAM RUNNING..
+=================================================================
+
+Choose what you would like to check for in a word
+that you will enter...
+=================================================================
+1) Check for palindrome.
+2) Check for all alpha.
+3) Count the number of times a letter is in a word.
+4) Exit Program.
+
+Enter: 1
+Enter a string: lol
+lol is a palindrome
+Press 1 and enter to rerun program. Enter any other number to close program: 1
+=================================================================
+PROGRAM RUNNING..
+=================================================================
+
+Choose what you would like to check for in a word
+that you will enter...
+=================================================================
+1) Check for palindrome.
+2) Check for all alpha.
+3) Count the number of times a letter is in a word.
+4) Exit Program.
+
+Enter: 1
+Enter a string: tyler
+tyler is not a palindrome
+Press 1 and enter to rerun program. Enter any other number to close program: 1
+=================================================================
+PROGRAM RUNNING..
+=================================================================
+
+Choose what you would like to check for in a word
+that you will enter...
+=================================================================
+1) Check for palindrome.
+2) Check for all alpha.
+3) Count the number of times a letter is in a word.
+4) Exit Program.
+
+Enter: 2
+Enter a string to test: tyler!@#
+! is not alphanumeric
+@ is not alphanumeric
+# is not alphanumeric
+Press 1 and enter to rerun program. Enter any other number to close program: 1
+=================================================================
+PROGRAM RUNNING..
+=================================================================
+
+Choose what you would like to check for in a word
+that you will enter...
+=================================================================
+1) Check for palindrome.
+2) Check for all alpha.
+3) Count the number of times a letter is in a word.
+4) Exit Program.
+
+Enter: 3
+Please enter a word: mississippi
+Please enter a character to count: i
+Character i occurs 4 times
+
+Press 1 and enter to rerun program. Enter any other number to close program: 2
+================================================================
+Program Closing...
+================================================================
_______________________________________________________________________________
diff --git a/mod11c.cpp b/mod11c.cpp
index 3e6ef18..2ce45b5 100644
--- a/mod11c.cpp
+++ b/mod11c.cpp
@@ -120,7 +120,19 @@ void isPalindrome ()
void isAlpha ()
{
- cout << " alphabet check" << endl;
+ char str[MAX];
+ int i;
+
+ cout << "Enter a string to test: ";
+ cin >> str;
+
+ for (int i = 0; str[i] != '\0'; i++)
+ {
+ if (!isalnum(str[i]))
+ {
+ cout << str[i] << " is not alphanumeric" << endl;
+ }
+ }
}