-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
82 lines (76 loc) · 3.13 KB
/
main.cpp
File metadata and controls
82 lines (76 loc) · 3.13 KB
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
/*******************************************************************************
* program name: CIS-65 Programming Assignment 3
* created date: March 6 2022
* created by: josh m dye
* purpose: practice using the stack abstract data type. One common use of a
* stack is to ReverseMore data. In this assignment we are going to allow the user
* to type in text or tell the program what input file to process to read in
* string data. While processing this data we are going to store each character
* into a stack (push). Once all of the data is stored in a stack, we are going
* to remove (pop) each character, printing each character which will be in
* ReverseMore order. We will print this to an output file and “echo” print it to
* the console.
* copyright 2022 josh m dye licensed under the educational community license,
* version 2.0 (the "license"); you may not use this file except in compliance
* with the license. you may obtain a copy of the license at
* http://www.osedu.org/licenses/ecl-2.0 unless required by applicable law or
* agreed to in writing, software distributed under the license is distributed
* on an "as is" basis, without warranties or conditions of any kind, either
* express or implied. see the license for the specific language governing
* permissions and limitations under the license.
*******************************************************************************/
//#define CPP_STANDARD_STACK // Uncomment to use std::stack,
// can also turn on with "cmake -DSTACK=ON"
#include <iostream>
#include <limits>
#include <string>
#ifdef CPP_STANDARD_STACK
#include "reverse_more.h" // Uses std::stack implementation
#else
#include "reverse.h" // Uses stack implementation from the book
#endif
using std::cin;
using std::cout;
using std::string;
/****************************************************************************
* Function Name: clearScreen()
* Parameters: None
* Return Value: void
* Purpose: Issue the correct clear command for windows or *nix
****************************************************************************/
void clearScreen() {
//https://sourceforge.net/p/predef/wiki/Compilers/
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
int main() {
#ifdef CPP_STANDARD_STACK
ReverseMore reverse; //Create instance using std::stack implementation
#else
Reverse reverse; //Create instance using stack implementation from the book
#endif
string filename; // Name of chosen file
char ans; // Holds menu answer
do {
cout << "\t(1) Enter string to reverse\n\t(2) Reverse text file\n";
cin >> ans;
cin.clear(); //Clear out the cin buffer
cin.ignore(std::numeric_limits<std::streamsize>::max(),
'\n'); //Ignore any extra characters
switch (ans) {
case '1':reverse.ReadString();
break;
case '2':filename = "LICENSE.txt"; // File to be reversed
reverse.ReadFile(filename);
break;
default:ans = 'r'; // If answered anything else, rerun prompt
clearScreen();
}
} while (ans == 'r');
reverse.PrintStack(); // print stack from end to beginning
// Paste output in www.textreverse.com to see what it was
return 0;
}