queue cypher



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() ;
}
}
closed account (48T7M4Gy)
I get the idea. How can we help you?

1
2
3
4
5
6
7
8
9
10
11
12
13
#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() ;
}
} 
Last edited on
I just thinking it. However, it not work

#include <iostream>
while(!cin.eof(c))
{
if (c >= 65 && c <= 90)
{
c = + shift;
if (c + shift > 90)
c = - 32;
else if (c + shift < 65)
c = + 32;
}
else if (c >= 97 && c <= 122)
{
c = + shift;
if (c + shift > 122)
c = - 32;
else if (c + shift < 97)
c = + 32;
}

closed account (48T7M4Gy)
What happened to main() etc?

Please put your code between ... blocking.

Instead of using a file to provide data use a test string in main so you can run your program and debug it. It can be a string or char[].
oh my god... Iam so sorry ... this is the first time I using it

how create this box ?
closed account (48T7M4Gy)
Use the <> on the right hand side when you open up a new message. Select the text and press the <> button
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
#include <iostream>
#include <string>
#include <fstream>
#include <cstdio>
#include <cctype>
#include <iomanip>
using namespace std;


int main(int argc, char* argv[])
{

    string input;
    int count=0, length, c;

        cout<< " Enter your letter or phrase: \n";
        cin.get(input);

        c = atoi(argv[1]);

        length = (int)input.length();

        while(!cin.eof(input));
        {
             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;
}





It my code. May you help me correct it please
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
#include <iostream>
#include <string>
#include <fstream>
#include <cstdio>
#include <cctype>
#include <iomanip>
using namespace std;
int main(int argc, char* argv[])
{
    char input;
    int c ;
    int shift = atoi(argv[1]) ; // get the command-line parm

    cout<< " Enter your letter or phrase: \n";

    c = cin.get(input) ;

    while ( ! cin.eof() )
    {
        if (c >= 65 && c <= 90)
    {
        c = + shift;
        if (c + shift > 90)
        c = - 32;
        else if (c + shift < 65)
        c = + 32;
        }
        else if (c >= 97 && c <= 122)
        {
        c = + shift;
        if (c + shift > 122)
        c = - 32;
        else if (c + shift < 97)
        c = + 32;
    }
        char(cout.put(c)) ;
        }
}


this is my second code... is it right?
closed account (48T7M4Gy)
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; ?
Last edited on
Yes, this is the first time I learn C++,
I get try on another sample data.
However, I dont understand clearly it yet. Can you show me ? please
closed account (48T7M4Gy)
So, you have not tried your program?
I am not clearly cin.get
cin.eof
I try it , however not work. And today I need to submit HW...
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
#include <iostream>
#include <string>
#include <fstream>
#include <cstdio>
#include <cctype>
#include <iomanip>
using namespace std;
int main()//int argc, char* argv[])
{

    int c, lent;
    //int shift = atoi(argv[1]) ; // get the command-line parm
    int shift = 13 ;
    cout<< " Enter your letter or phrase: \n";
    c = cin.get() ;
    lent= (int)c.lent();
    do
    {
        for (int i=0 ; i < lent; i++)
        {
            if     ( c[i]>= 'A' && c[i] <= 'Z')
                    c[i]= ( c[i] - 'A' + shift) % 26 + 'A';
            else if( c[i] >= 'a', && c[i] <= 'z' )
                    c[i]=( c[i] - 'a' + shift) % 26 + 'a';
            else    c[i] = c[i];
                    }
    }
    while ( ! cin.eof() );
    cout.put(c);
    cout.put('');
}


Might you help me correct it.? pleaase
closed account (48T7M4Gy)
I'll help you correct it. Where do u want to start?
I have only 1 h to complete it. I really need your help.
start with cin.get() and !cin.eof
because I am newbie in C++. I dont understand clearly it
closed account (48T7M4Gy)
I have only 1 h to complete it.

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/

Study those and let me know the next problems.
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
#include <iostream>
#include <string>
#include <fstream>
#include <cstdio>
#include <cctype>
#include <iomanip>

using namespace 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?
closed account (48T7M4Gy)
Who wrote this version?

Here's what getline does:

http://www.cplusplus.com/reference/string/string/getline/?kw=getline

Hint: you only have to change one line including modifying a single variable name and it runs.

2nd Hint: I don't necessarily believe your instructor.
Last edited on
Topic archived. No new replies allowed.