C++ Design and Implement a StackADT that does the following: .h and .cpp 1) Read
ID: 652798 • Letter: C
Question
C++ Design and Implement a StackADT that does the following:
.h and .cpp
1) Reads input from a file (Download and use the file "directions.txt" above as the input file for the StackADT Programming Assignment).Use modulaity
2) Stores the data on a stack usign the StackADT you created
3) Data Retrieval and Processing
A) Retrieves the data from the stack,
B) Processes the retrieved data,
When the data item is retrieved from the stack, search and replace/change the words in the following way: (ignore the case)
WORD CHANGE TO
North South
East West
West East
South North
Left Right
Right Left
4) Displays the Processed data on the screen and also Saves the data in an output file
Explanation / Answer
void main()
{
int line1[], i = 0;
ifstream dir;
dir.open("directions.txt", ifstream::in);
while(!dir.eof())
{
getline(dir,line1[i]);
i = i+1;
}
int count = i;
void stack1() // To enter data in stack;
{
String stack[];
int top = -1;
for(int j = 0; j<count;j++)
{
stack[j] = line1[j];
top++;
}
}
//Retrieve data and process it
void data_process()
{
String new_stack[count];
for(int k =0; k<count;k++)
{
String s = pop(Stack);
if (s == "North")
{
new_stack[i] = "South";
i++;
}
else if (s == "South")
{
new_stack[i] = "North";
i++;
}
else if (s == "East")
{
new_stack[i] = "West";
i++;
}
else if (s == "West")
{
new_stack[i] = "East";
i++;
}
if (s == "Right")
{
new_stack[i] = "Left";
i++;
}
else if (s == "Left")
{
new_stack[i] = "Right";
i++;
}
top = i;
}
}
String pop(String)
{
return(stack[top]);
top--;
}
void display()
{
while(i!=-1)
{
cout<<"new_stack[top];
i--;
}
void write_file()
{
ofstream dir1("direction.txt");
int i = 0;
if(dir.isopen())
{
while(i<count)
{
dir1<<new_stack[i];
}
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.