need help with my computer science lab assignemnt this assig
need help with my computer science lab assignemnt. this assignment is in C++ language.
i have added the url needed to get to the homework assignment since you will need source files for the assignment.
http://andrewwinslow.com/2380/labDAQ/
any questions please comment me back. the files that are given are the main.cpp and the header file. we just need to fill in the missing code on the second cpp file
Solution
#include <iostream>
#include <string>
#include \"Stack.h\"
#include \"Queue.h\"
#include <stdio.h>
#include <ctype.h>
template <typename T>
void cinNbr(T&); // enter a number from keyboard
//void CheckIfP ();
using namespace Queue_ns; // Queue namespce
using namespace Stack_ns; // stack namespace
using namespace std;
int main()
{
string user_input; // raw user input
string copied_string; // this is a cleaned up version of user_input
Stack <char> s; // Make stack
Queue <char> q; // Make Queue
int menuChoice = 0; // menu choice default
bool quit = false;
while (!quit)
{
system(\"cls\"); // clears the console screen
cout << \"1. Enter New String:\ \";
cout << \"2. Test new String:\ \";
cout << \"3. Exit:\ \";
cout << \"What would you like to do? Select a number (1 - 3), then press Enter:\";
cinNbr(menuChoice);
switch (menuChoice)
{
case 1:
cout << \"Please enter a string to test if it is a Palindrone: \";
getline(cin, user_input);
copied_string = user_input;
for (int i=0; i<copied_string.size(); i++) //using length of user input for itterator
{
char currentChar = copied_string[i];
bool isAlpha = (bool)isalpha((int)currentChar); //If you delete these it works
// is the character alpha? if not, erase it
if (!isAlpha) {
copied_string.erase(i, 1);
i--;
}
// otherwise just make it uppercase
else {
copied_string[i] = toupper((int)currentChar); //Push stack at user input for itterator
}
}
cout << \"Here is the filtered string: \" << copied_string;
system(\"pause\");
break;
case 2:
{
for (int i=0; i<copied_string.size(); i++) //using length of user input for itterator
{
q.push(copied_string[i]); //Push queue at user input for itterator
s.push(copied_string[i]); //Push stack at user input for itterator
}
bool isPalindrome = true; //set local variable to true
while (isPalindrome==true && (!s.empty() && !q.empty())) //if the palidrome is true and niether case is empty
{
if (s.top() != q.top()){ //check to see if containers are unequal.
isPalindrome = false; //if unequal then not palindrome
}
else {
q.pop(); //Remove top if equal giving next marking nex letter at top
s.pop();
}
}
if (isPalindrome == false ) { //If Palindrome does not match both stacks print....
cout<< copied_string << \" is not a palindrome.\" << endl;
}
else {
cout<< copied_string <<\" is a palindrome.\" << endl;
} //If Palindrome does macht both stacks print....
system(\"pause\");
break;
}
case 3:
cout << \"Good Bye!;
system(\"pause\");
quit = true;
cout << endl;
break;
default:
cout << endl << \"Invalid menu choice. Please try again.\ \ \";
system(\"pause\"); // causes program to pause until user hits a key
}
}
cout << \"Closing...\ \";
return 0;
}
template<typename T>
void cinNbr(T& var) // enter a number from keyboard
{
cin >> var;
while (cin.fail() || cin.get() != \'\ \') // if error encountered
{
cout << \"Invalid entry! Please re-enter a value 1-3: \";
cin.clear(); // clears any error flag
cin.ignore(80, \'\ \'); // clears input buffer
cin >> var;
}
cin.clear();
}


