forked from DanielBillette/SoftwareProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecipient.cpp
More file actions
87 lines (72 loc) · 2.05 KB
/
Recipient.cpp
File metadata and controls
87 lines (72 loc) · 2.05 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "Recipient.h"
#include <string>
#include <iostream>
#include <time.h>
using namespace std;
Recipient::Recipient()
{
responses[0] = "Not bad, you?";
responses[1] = "Terrible.";
responses[2] = "Okay, I guess.";
responses[3] = "Sure.";
responses[4] = "Fine.";
responses[5] = "Nope.";
responses[6] = "No can do.";
responses[7] = "Yo.";
responses[8] = "Hey.";
responses[9] = "Seeya.";
responses[10] = "Bye.";
responses[11] = "Goodbye."; //preset responses
}
Recipient::~Recipient()
{}
int Recipient::Randomnum(int min, int max)const
{
srand((unsigned int)time(NULL));
return (rand() % (max-min+1)+min); //generates a random number between min and max
}
void Recipient::GenResponse(stringinput euserinput) const
{
switch(euserinput)
{
case ehi:
cout << responses[Randomnum(7, 8)] << endl;
break;
case ehowareyou:
cout << responses[Randomnum(3, 0)] << endl;
break;
case erequest:
cout << responses[Randomnum(4, 3)] << endl;
break;
case ebye:
cout << responses[Randomnum(3, 9)] << endl;
break;
case error:
cout << "What?"; //generates a response based on the enum euserinput and
break;
}
}
Recipient::stringinput Recipient::CheckInput(string userinput)const
{
stringinput returnval;
string userinputcpy = " ";
for(int i = 0; i != userinput.size();i++)
userinput[i] = tolower(userinput[i]);
if(userinput.size()>6)
for(int i = 0; i != 7; i++)
userinputcpy[i] = userinput[i];
if(userinput == "hello" || (userinput == "hi" || (userinput == "hey")))
return returnval = ehi;
else if(userinput == "how are you" || (userinput == "sup" || (userinput == "whats up")))
return returnval = ehowareyou;
else if(userinputcpy == "can you" || userinputcpy == "could y")
return returnval = erequest;
else if(userinput == "bye" || (userinput == "seeya" || (userinput == "goodbye")))
return returnval = ebye;
else
return returnval = error; //generates the string to be outputted based on the string userinput
}
void Recipient::execute(string userinput) const
{
GenResponse(CheckInput(userinput)); //master function
}