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
|
void operations (ofstream &outFile, int num1, int num2, char opChoice)
{
int result;
switch (opChoice){
case '&': outFile << "Applying the AND operator & to:\n" << num1 << " = ";
printBinary(outFile, num1);
outFile << num2 << " = ";
printBinary(outFile, num2);
outFile << "\n";
result = (num1 & num2);
outFile << "Produces \n";
outFile << result << " = ";
printBinary(outFile, result);
break;
case '|': outFile << "Applying the OR operator | to:\n" << num1 << " = ";
printBinary(outFile, num1)
; outFile << num2 << " = ";
printBinary(outFile,num2);
outFile << "\n";
result = (num1 | num2);
outFile << "Produces \n";
outFile << result << " = ";
printBinary(outFile, result);
break;
case '^': outFile << "Applying the XOR operator ^ to:\n" << num1 << " = ";
printBinary(outFile, num1);
outFile << num2 << " = ";
printBinary(outFile, num2);
outFile << "\n";
result = (num1 ^ num2);
outFile << "Produces \n";
outFile << result << " = ";
printBinary(outFile, result);
break;
case '~': outFile << "Applying the Inverting operator ~ to:\n" << num1 << " = ";
printBinary(outFile,num1);
outFile << "\n";
result = ~num1;
outFile << "Produces \n";
outFile << result << " = ";
printBinary(outFile, result);
break;
case '<': outFile << "Applying the Shift Left operator << to:\n" << num1 << " = ";
printBinary(outFile,num1);
outFile << num2 << " = ";
printBinary(outFile,num2);
outFile << "\n";
result = (num1 << num2);
outFile << "Produces \n";
outFile << result << " = ";
printBinary(outFile, result);
break;
case '>': outFile << "Applying the Shift Right operator >> to:\n" << num1 << " = ";
printBinary(outFile,num1);
outFile << num2 << " = ";
printBinary(outFile,num2);
outFile << "\n";
result = (num1 >> num2);
outFile << "Produces \n";
outFile << result << " = ";
printBinary(outFile, result);
break;
}
}
|