Feb 5, 2010 at 3:37pm UTC
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 Feb 5, 2010 at 5:06pm UTC
Feb 5, 2010 at 3:44pm UTC
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 Feb 5, 2010 at 3:46pm UTC
Feb 5, 2010 at 3:45pm UTC
that is not the problem
please any one help me
Feb 5, 2010 at 3:47pm UTC
then the decoder would use the opposite shift.
Feb 5, 2010 at 3:50pm UTC
the problem isn't solved
in every time the output is zero he couldn't read any of the if conditions please help
Feb 5, 2010 at 4:19pm UTC
please urgent , help please
Feb 5, 2010 at 4:28pm UTC
well "01" would return 8 since 0 count +=6 and 1 count +=2.
Feb 5, 2010 at 4:50pm UTC
but it return zero but i don't know the reason please help urgent please
Feb 5, 2010 at 5:00pm UTC
try else if for the if's that follow if and make the last one else
Last edited on Feb 5, 2010 at 5:01pm UTC
Feb 5, 2010 at 5:05pm UTC
still zero please try it on your IDE and see it and help me ....urgent
Feb 5, 2010 at 5:07pm UTC
Blah! whatever, code is a string not an array. try a const char* or a better comparison
Last edited on Feb 5, 2010 at 5:09pm UTC
Feb 5, 2010 at 5:23pm UTC
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 Feb 5, 2010 at 5:27pm UTC
Feb 6, 2010 at 1:48am UTC
why do his homework for him? it was bad enuf he was begging....