#include<iostream>
#include <cstdlib>
#include<string>
using namespace std;
class Pieces // abstract class
{
public:
virtual bool checkvalidmove(string start,string last) = 0;//virtual
function
};
class Men: public Pieces
{
public:
bool checkvalidmove(string start,string last) // override
function
{
int a=start[0];
int b=last[0];
int aa=start[1];
int bb=last[1];
a=a-b;
a=abs(a);
aa=aa-bb;
aa=abs(aa);
if(a<=1 && aa<=1) // if row and column doesn't excedd
one block
{
if(a==0 && aa==0) // if they doesn't move than not
valid
{
return false;
}
return true;
}
return false;
}
};
class King: public Pieces
{
public:
bool checkvalidmove(string start,string last) {
int a=start[0];
int b=last[0];
int aa=start[1];
int bb=last[1];
if(a==b) // if they have same row after the move than valid
{
if(aa==bb) // if they doesn't move than not valid
{
return false;
}
return true;
}else if(aa==bb) // if they have same column after the move than
valid
{
if(a==b) // if they doesn't move than not valid
{
return false;
}
return true;
}else{
a=a-b;
a=abs(a);
aa=aa-bb;
aa=abs(aa);
if(a==aa) /* if distance between start row and last row and
distance between start column and last column same than its
diagonal move*/
{
return true;
}
}
return false;
}
};
int main(void)
{
Men ob;
King obj;
string s;
getline (cin, s);
string s1;
s1="Man";
int count=-1;
for (int i = 0; i <=s.length()-s1.length(); i++) // finding men
substring
{
int j;
for (j = 0; j <s1.length(); j++)
{ if (s[i + j] != s1[j])
{
break;
}
}
if (j==s1.length())
{
count=i;
}
}
string start;
string last;
last+=s[s.length()-2];
last+=s[s.length()-1];
start+=s[s.length()-8];
start+=s[s.length()-7];
if(count>=1) // if men exit
{
bool b=ob.checkvalidmove(start,last);// call men valid move
if(b==1)
{
cout<<"true"<<endl;
}else
{
cout<<"false"<<endl;
}
}
else
{
bool bb=obj.checkvalidmove(start,last);// call king valid
move
if(bb==1)
{
cout<<"true"<<endl;
}else
{
cout<<"false"<<endl;
}
}
return 0;
}
/*
case 1:-
Input:- call a method to check(King) can be solved from b1 to f5
Output :- true
case 2:-
Input :- call a method to check(Man) can be solved from b1 to f5
Output:- false
case 3:-
case 3:-
Input:- call a method to check(Man) can be solved from b1 to a2
Output :- true
case 4:-
Input:- call a method to check(King) can be solved from b1 to b7
Output :- true
*/
Lab 6.3.1 Polymorphism: part 2 Objectives Familiarie the student with: . polymorphism, or using o...
Using the classes from Lab 1, app and student, create a solution
for implementing some kind of random behavior for your student.
Suppose the student can be reading, surfing the web, or interacting
with other students. You will need to check now and then to see
what the student is doing. You will be asking the instance of the
student class and what it is doing at certain time intervals.
You Will Need To:
Create a method in the class...