Here are my instructions and I think I have it done but I justrealized I need to
ID: 3619305 • Letter: H
Question
Here are my instructions and I think I have it done but I justrealized I need to use memory mapped IO. I am reading overthe book and doing research on it but just dont know how to changeit and my deadline is Friday. Can someone take a look atthis? I will provide the instructions and what I have...(fyiif you dont want to read my instructions you don't have to justwant to make it as easy as possible to understand what I amdoing)Create a utility that transfers words that are palindromes in theinput file into the output file. Place a space between eachpalindrome written to the output file.
The input path and file name and the output path and file name mustbe gathered at runtime from the user. This can be accomplished viacommand line inputs (see argv and argc parameters in the main()function).
The program must use memory-mapped file input/output.
The contents of the input file must not be changed by your program(read only).
The definition of a palindrome, for purposes of this programmingassignment, is a word which reads the same backward or forward.Examples of palindromes are mom, pop, kayak, noon, radar, andracecar.
While there are a number of methods available to test to see if aword is a palindrome, the most common method is to use a stack.Character[0] of the original string can be compared withcharacter[n-1]. The next comparison would address character[1] withcharacter[n-2]. Comparison continues until all characters arecompared (the stack is empty) or there is an inequality (the wordis not a palindrome).
The output file should contain only those words that arepalindromes from the input file. Each word in the output fileshould be separated by a space.
Since the length of the output file is determined at runtime, andthere is no way to predict how many palindromes will be present inthe input file (without actually performing the test), there is nomeans to accurately predict the output file size required. Set theoutput file size to the input file size.
You may use the Windows Platform SDK (Win32), the Active TemplateLibrary (ATL), and the Standard Template Library (STL). You may usea managed or unmanaged project.
You should turn in a copy of your source files on floppy
Here is my code...
[CODE]
#include<iostream>
#include <fstream>
#include<string>
using namespace std;
//FUNCTIONS
bool isPalindrome(string);
//begin int main
int main(int argc, char * argv[])
{
//Declare variables
ifstream in;
ofstream out;
bool palin;
string data;
//open the file
in.open(argv[1]);
//Statement if the file does not open
if(in.fail())
{
//Coutstatement to show the error
cout<<"File not opening!" << endl;
//Make a pause
system("pause");
//Return a value
return 1;
}
//Open the file
out.open(argv[2]);
in>>data;
//Perform while statement
while(in)
{
palin=isPalindrome(data);
if(palin)
out<<data<<"";
in>>data;
}
//Close the in
in.close();
//Close the out
out.close();
}
//Function to check Palindrome
bool isPalindrome(string input)
{
//Declare variables
int i=0,j;
bool y=false;
j=input.length()-1;
//While statment to check i and j
while(input[i]==input[j]&&i<=j)
{
i++;
j--;
}
//If statement to check if i > j
if(i>j)
//Show that y is true
y=true;
//Return y
return y;
}
[/CODE]
Explanation / Answer
Can someone offer me anything? I really am not sure how to dothis.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.