You must read the COMMAND LINE* for the "shift" value. It will be in
argv[1]...
Example: a.out 13
(the "13" is passed into the executing program as the CString ['1''3''\0']
So "hello" becomes "uryyb'. And "uryyb' becomes "hello" when it's
queueshift 13'd.
When running, the program should keep track of whether the input char
was lower or upper case. If input is not alphabetic, don't change it,
just pass it through. Don't delete anything from the input stream such
as linefeeds, or punctuation.
Start with a waterpump:
#include <iostream>
using namespace std ;
int main()
{
int c ;
int shift = atoi(argv[1]) ; // get the command-line parm
c = cin.get() ;
while ( ! cin.eof() )
{
cout.put(c) ;
c = cin.get() ;
}
}
#include <iostream>
usingnamespace std ;
int main()
{
int c ;
int shift = atoi(argv[1]) ; // get the command-line parm
c = cin.get() ;
while ( ! cin.eof() )
{
cout.put(c) ;
c = cin.get() ;
}
}
Well, the first big question I would ask is:
Have you tried it on some sample data?
A couple of comments though:
a) c += shift, c -= shift ?
b) use modulo arithmetic ( % operator etc ) instead of all the if statements?
c) why have you got so many #includes?
d) where is the code for opening the file?
e) to print out the characters why not just have cout << c; ?
What? they only gave you such a short time for the assignment? Must be a very tough school.
Anyway, as promised:
start with cin.get() and !cin.eof
http://www.cplusplus.com/reference/istream/istream/get/?kw=cin.get
and
http://www.cplusplus.com/reference/ios/ios/eof/
#include <iostream>
#include <string>
#include <fstream>
#include <cstdio>
#include <cctype>
#include <iomanip>
usingnamespace std;
int main()//int argc, char* argv[])
{
string input;
int count=0, length, c;
cout<< " Enter your letter or phrase: \n";
input = cin.get();
//c = atoi(argv[1]);
c = 13;
length = (int)input.length();
for( count=0; count< length; count++)
if( isalpha(input[count]))
{
for (int i=0; i < c ; i++)
{
if(input[count] == 'z')
input[count] = 'a';
else
input[count]++;
}
}
cout << "Results: \n" <<input << endl;
}
I am sorry because rushing you. this is my fault, I think I finish it. but my intructor said me wrong when I using getline to modify input
However I try this data, I only get the first letter, How I get whole line with cin.get?