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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
#include <iostream>
#include <string>
#include <ctype.h>
#include <sstream>
using namespace std;
string name1 ,name2, namea, nameb;
int errorCHECKER(string name1)
{
int i=0;
do // A do-while loop to check all characters of the given name if it is valid or not
{
switch (name1[i])//A nested switch function that returns a value of 1 when the character is found illegal
{
case '1': return 1; break;
case '2': return 1; break;
case '3': return 1; break;
case '4': return 1; break;
case '5': return 1; break;
case '6': return 1; break;
case '7': return 1; break;
case '8': return 1; break;
case '9': return 1; break;
case '0': return 1; break;
case 0: return 1; break; // This means a null character and NOT a whitespace
case '*': return 1; break;
case '&': return 1; break;
case '^': return 1; break;
case '%': return 1; break;
case '$': return 1; break;
case '#': return 1; break;
case '@': return 1; break;
case '!': return 1; break;
case '`': return 1; break;
case '~': return 1; break;
case '(': return 1; break;
case ')': return 1; break;
case '_': return 1; break;
case '-': return 1; break;
case '+': return 1; break;
case '=': return 1; break;
case '{': return 1; break;
case '[': return 1; break;
case '}': return 1; break;
case ']': return 1; break;
case ':': return 1; break;
case ';': return 1; break;
case '"': return 1; break;
case '<': return 1; break;
case ',': return 1; break;
case '>': return 1; break;
case '.': return 1; break;
case '?': return 1; break;
case '/': return 1; break;
case '|': return 1; break;
}
++i;
}
while (i<name1.length()); // The loop lasts as long as the identifier i is less than the number of characters inside the string
}
void gEtName()
{
start:
cout << "Enter first person's full name" << endl << endl;
getline (cin,name1); // getline enables spaces to be read in the user's input
namea = name1; // creates a copy of name1 to be used for the display of results
int a = errorCHECKER(name1);
if (a==1)
{
cout << "You entered an invalid name" << endl;
cout << "Please enter a valid name" << endl;
goto start;
}
start2:
cout << endl << "Enter second person's full name" << endl << endl;
getline (cin,name2);
nameb = name2;
a = errorCHECKER(name2);
if (a==1)
{
cout << "You entered an invalid name" << endl;
cout << "Please enter a valid name" << endl;
goto start2;
}
}
string wHitEspAcE(string name1)
{
string final;
for(int i = 0; i < name1.length(); ++i)
{
if(name1[i] != ' ' && name1[i]!='\n')
{
final += name1[i];
}
}
return final;
}
string sMallaLph(string name1)
{
for (int i=0;i<name1.length();++i)
{
name1[i]=tolower(name1[i]);
}
return name1;
}
//Function to cancel all same characters between the two names
void cAncElsAmE(string &name1,string &name2)
{
string temp1,temp2; // create two temporary strings to be used for cancellation
temp1=name1; // temp1 is equal to the value of name1
temp2=name2; // temp2 is equal to the value of name2
for (int i=0;i<name1.length();++i) // the loop will go on as long as i<name1.length()
{
for (int s=0;s<temp2.length();++s)// the nested for loop will go on as long as s<name2.length()
{
if (name1[i]==temp2[s]) // if the element stored in name1[i] is equal to the element in temp2[s]
{
name1[i]= ' '; // the element contained in name1[i] will be a whitespace
}
}
}
for (int s=0;s<name2.length();++s)
{
for (int i=0;i<temp1.length();++i)
{
if (name2[s]==temp1[i]) // if the element stored in name2[s] is equal to the element in temp1[i]
{
name2[s]=' '; // the element contained in name2[s] will be a whitespace
}
}
}
cout << "The following are the remaining letters of their names"<< endl <<endl;
cout << wHitEspAcE(name1)<< endl; //shows the remaining letters of name1 without whitespaces
cout << wHitEspAcE(name2)<< endl; // shows the remaining letters of name2 without whitespaces
}
//Function that counts the remaining characters
int cOuNt (string name1, string name2)
{
return (name1.length()+name2.length()); // returns the sum of the length of the two strings
}
//Function that determines the result of the whole Flames program
void fLamEs(int z)
{
switch (z)
{
case 1:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Friends" <<endl;
break;
case 2:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Lovers" <<endl;
break;
case 3:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Acquaintances" <<endl;
break;
case 4:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Married" <<endl;
break;
case 5:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Enemies" <<endl;
break;
case 6:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Sweethearts" <<endl;
break;
case 0:
cout << endl << endl;
cout << namea <<" and " << nameb << " are not compatible with each other " << endl;
default:
if (z>6) // if the value of z is greater than 6
{
z%=6; // z will contain the remainder of its original value divided by 6
switch (z)
{
case 1:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Friends" <<endl;
break;
case 2:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Lovers" <<endl;
break;
case 3:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Acquaintances" <<endl;
break;
case 4:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Married" <<endl;
break;
case 5:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Enemies" <<endl;
break;
case 0:
cout << endl << endl;
cout << namea << " " << "and " << nameb << " " << "are Sweethearts" <<endl;
break;
}
}
}
}
int main ()
{
string a;
start:
gEtName();
name1=sMallaLph(wHitEspAcE(name1)); name2=sMallaLph(wHitEspAcE(name2));
cAncElsAmE(name1,name2);
name1=wHitEspAcE(name1);//name1 will contain the remaining characters without whitespaces
name2=wHitEspAcE(name2);//name2 will contain the remaining characters without whitespaces
cout << "The number of remaining letters is:" << cOuNt(name1,name2) << endl;
fLamEs(cOuNt(name1,name2));// the argument to be used is the result of the cOuNt function
restart:
cout << "Do you want to play Flames again? (Please Enter either yes or no)" << endl;
getline (cin,a);
if (a=="yes")
{
cout << endl;
goto start;
}
else if (a=="no")
{
cout << "Thanks for playing" << endl;
system ("pause");
return 0;
}
else
{
goto restart;
}
}
|