Vcoderz Community

Vcoderz Community (http://forum.vcoderz.com/index.php)
-   Computers & Information Technologies (http://forum.vcoderz.com/forumdisplay.php?f=6)
-   -   A homework for C++ fellows :D (http://forum.vcoderz.com/showthread.php?t=4176)

General 02-03-2007 10:28 PM

A homework for C++ fellows :D
 
Write a function which returns true if the string parameter is a palindrome. A palindrome is any "word" which is the same forward and backward, eg, "radar", "noon", "20011002", ... The function should return false if the argument is not a palindrome. Assume the prototype is
bool isPalindrome(char * s1);


Write a function which shortens a string s1 to n characters and stores the result in string s2. Assume the prototype is
void truncate(char *s1, char * s2, int n);



show us:D

(not for me, for a friend who needs the answers badly - special case)

Sheriff Ice 02-03-2007 11:25 PM

Re: A homework for C++ fellows :D
 
man this is a program abt palindrom i dont know if its help u i tooke the course 2 years ago but i still have the programs so good luck.

--------------------------------------------------------------------
#include<iostream.h>

bool pal(char [],int,int);
int main()
{
const int size=11;
char a[size]="a bc ba";

cout<<pal(a,0,size-2)<<endl;
return 0;
}
bool pal(char a[],int low,int high)
{


if(a[low]==' ')
{
low++;
return pal(a,low,high);
}

if(a[high]==' ')
{
--high;
return pal(a,low,high);
}

if((low==high)||(low==high-1))
return true;

if(a[low]==a[high])
return pal(a,++low,--high);
else

return false;

}

-------------------------------------------------------------

Kingroudy 02-03-2007 11:39 PM

Re: A homework for C++ fellows :D
 
ex1:
bool ispalindrom (char *s1)
{
int length;
for (int i=0; s1[i]!='\0'; i++)
length=i+1;

for (int j=0; j<length/2; j++)
if (s1[j]!=s1[length-j-1])
return false;
return true;
}


ex2:
void truncate(char *s1, char *s2, int n=3)
{
for (int j=n; s1[j]!='\0'; j++)
s1[j]='\0';
for (int i=0;i<n; i++)
s2[i]=s1[i];
}
i'm very sure of those:D and not really sure about what crazysimo did, but believe me this is the way it is done:D

General 02-03-2007 11:47 PM

Re: A homework for C++ fellows :D
 
thank u guys, i'll update u about his grades :D

Jules3 02-03-2007 11:51 PM

Re: A homework for C++ fellows :D
 
Hehehe
Thanks guys
And thanks rami for posting the thread for me!!!

god 02-03-2007 11:56 PM

Re: A homework for C++ fellows :D
 
write your own |-( :-P yalla bassita.. thread locked.


All times are GMT +1. The time now is 08:58 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger