Sabtu, 16 April 2016

kasus 6.6

asslamualaikum wr.wb

c++ :
#include <iostream>
#include <string.h>
#include <conio.h>

using namespace std;

class Palindrom {
friend ostream& operator<<(ostream&, Palindrom&);
friend istream& operator>>(istream&, Palindrom&);
public:
int cek_palindrom();
private:
char *s;
};

ostream& operator<<(ostream& out, Palindrom& a) {
if (a.cek_palindrom())
cout << a.s << " adalah palindrom";
else out << a.s << " bukan palindrom";
return out;
};


istream& operator>>(istream& in, Palindrom& a) {
cout << "Masukkan sebuah kalimat : ";
cin >> a.s;
return in;
};

int Palindrom::cek_palindrom()
{ int i, pj;
pj = strlen(s);
for (i=0; i<=pj/2 ;i++)
if (s[i] != s[pj-i-1]) return 0;
return 1;
}

main() {
Palindrom kata;
cin >> kata;
cout << kata;
getch();
return 0;
}

0 komentar:

Posting Komentar