Decoder

Decoder show values as
_
| |
|_|

this represent zero contain 6 dashes
my code is to take a string like "01" and return 8 , 6 dahses from zero and 2 from one
there is something wrong can anyone help me
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
# include <iostream>
# include <string>
using namespace std ;

class CheckFunction 
{
      public : 
               int newFunction(string code) ;
};

int CheckFunction::newFunction(string code)
               {
                   int count = 0 ;
                   for ( int i = 0 ; i < code.length() ; i ++ )
                   {
                       if ( code[i] == 0 )
                       {
                            count += 6 ;
                       }
                       else if ( code[i] == 1 )
                       {
                            count += 2 ;
                       }
                       else if ( code[i] == 3 )
                       {
                            count += 5 ;
                       }
                       else if ( code[i] == 4 )
                       {
                            count += 4 ;
                       }
                       else if ( code[i] == 5 )
                       {
                            count += 5 ;
                       }
                       else if ( code[i] == 6 )
                       {
                            count += 6 ;
                       }
                       else if ( code[i] == 7 )
                       {
                            count += 3 ;
                       }
                        else if ( code[i] == 8 )
                       {
                            count += 7 ;
                       }
                       else if ( code[i] == 9 )
                       {
                            count += 3 ;
                       }
                   }
                   return count ;
               }


int main ()
{
    string str ;
    cin >> str ; 
    
    CheckFunction c1 ;
    cout << c1.newFunction(str);
    
    system("pause");
    return 0 ;
}
Last edited on
closed account (j3bk4iN6)
You can place the member function outside of the class by making a constructor then

<type> <class name>::<function> outside the class. with a function that long it makes sense

a better way to make an encoder is to use ceasar cypher and shift the ascii values by a number and make the char 'a' through 'z' circular.
Last edited on
that is not the problem
please any one help me
closed account (j3bk4iN6)
then the decoder would use the opposite shift.
closed account (jLNv0pDG)
#include <string>
the problem isn't solved
in every time the output is zero he couldn't read any of the if conditions please help
please urgent , help please
closed account (j3bk4iN6)
well "01" would return 8 since 0 count +=6 and 1 count +=2.
but it return zero but i don't know the reason please help urgent please
closed account (j3bk4iN6)
try else if for the if's that follow if and make the last one else
Last edited on
still zero please try it on your IDE and see it and help me ....urgent
but it return zero but i don't know the reason please help urgent please

why is it when I read posts like this I feel the need to do the opposite and not help?

Blah! whatever, code is a string not an array. try a const char* or a better comparison
Last edited on
closed account (j3bk4iN6)
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
using namespace std ;

class CheckFunction 
{
      public : 
               int newFunction(char* str) ;
};

int CheckFunction::newFunction(char* str)
               {
                   int count = 0 ;
                   for ( int i = 0 ;  *(str).length()  ; i ++ )
                   {
                       if ( *(str)+i == 0 )
                       {
                            count += 6 ;
                       }
                       else if ( *(str)+i == 1 )
                       {
                            count += 2 ;
                       }
                       else if ( *(str)+i == 3 )
                       {
                            count += 5 ;
                       }
                       else if ( *(str)+i == 4 )
                       {
                            count += 4 ;
                       }
                       else if ( *(str)+i == 5 )
                       {
                            count += 5 ;
                       }
                       else if ( *(str)+i == 6 )
                       {
                            count += 6 ;
                       }
                       else if ( *(str)+i == 7 )
                       {
                            count += 3 ;
                       }
                        else if ( *(str)+i == 8 )
                       {
                            count += 7 ;
                       }
                       else if ( *(str)+i == 9 )
                       {
                            count += 3 ;
                       }
                   }
                   return count ;
               }


int main ()
{
    char* str = 0 ;
    cin >> str ; 
	
	
    
	CheckFunction c1;
    cout << c1.newFunction(str);
    

    return 0 ;
}


just to let you know this is what I got sofar but length() not working. I think the whole thing should be re-worked so its a function instead of a class.
Last edited on
why do his homework for him? it was bad enuf he was begging....
Topic archived. No new replies allowed.