In: Computer Science
Problem #1: A sequence of inquiry
ELIZA:How are you feeling? USER:I am angry. ELIZA:Why are you angry? USER:I am angry because I am tired. ELIZA:Why are you tired? USER:I am tired because I am staying up late looking at facebook. ELIZA:Are you angry because you are staying up late looking at facebook?
Write an ELIZA-type program.
Include asking three questions and make a deduction based on user input.
Use a series of nested if statements to create this program.
You do not need to duplicate the example below exactly, you just need to make three exchanges between the user and ELIZA using "If" statements and other techniques covered in class such as the Regex library and string recognition.
For Example:
Include a response for not understanding the user's input.
Eliza is an AI Program that simulates the behavior of a therapist. ELIZA worked by applying pattern-matching rules. It looked for a rule whose left side matched the last sentence entered by the user, then used the right side of that rule to generate a response.
It's easy to start Eliza! Just type "./eliza.pl" or "perl eliza.pl" in the command line and you can enjoy chatting with Eliza.
If you want to quit Eliza, type "goodbye/done/exit/quit/bye"
For example
Eliza : Hello, I'm Eliza.
User : hello, I’m Mr X.
Eliza: What's your name?
User : I’m Mr X
Eliza: Nice to meet you, How are you?
User:I’m fine dear.
Eliza: Goodbye.
User: Bye.
The program in C++
#include<iostream.h>
#include<conio.h>
void resp :: display_resp(int num)
{
cout<<"ELIZA > ";
for(int i=0;i<strlen(replys[num]);i++)
{
// for deliberate typing errors
// (for simulating the human behavoir ;-)
if(RanNum(6)==0)
{
char c=RanNum(100);
if(c=='\n' || c=='\b' || c==13)
cout<<"w";
else
cout<<c;
delay(RanNum(DELAY));
// correcting the deliberate typing error
cout<<"\b";
}
// * is used to write anything after the // keyword
// as it is, but with some transformatio // ns like
// converting MY to YOUR.< // br> if(replys[num][i]=='*')
{
char * s1=ip.userip+strlen(ip.keyword);
short int flag=0;
for(int m=0;m<TRANSPOSE;m++)
{
char * s2=wordin[m];
char *ptr=NULL;
ptr=strstr(s1,s2);
if(ptr!=NULL)
{
// transposition word found in the
// user input
flag=1;
// printing text before wordin[m]
int times=ptr-s1;
for(int i=0;i<times;i++)
{
delay(DELAY);
cout<<ip.userip[strlen(ip.keyword)+i];
}
// printing the wordout
cout<<wordout[m];
// printing the left overs
char c;
c=*(ptr+strlen(wordin[m]));
int t=0;
while(c!='\0')
{
cout<<*(ptr+strlen(wordin[m])+t);
t++;
c=*(ptr+strlen(wordin[m])+t);
}
}
} // end of for
// if flag is still zero , this means no need for
// transposing any word.
if(0==flag)
{
char c;
c=*(s1+strlen(ip.keyword));
int t=0;
while(c!='\0')
{
cout<<*(s1+t);
t++;
c=*(s1+t);
}
} // end of if
break;
}
else
{
cout<<replys[num][i];
delay(RanNum(DELAY));
}
} // end of for
// giving the prompt back to user
cout<<"\n"<<user<<" > ";
}