Guest User

Untitled

a guest
May 21st, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. /*Richard-David Simmons
  2. Assignment 2-#2*/
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <fstream>
  7. using namespace std;
  8.  
  9. void absVal (int &x);
  10. bool isEven(int x);
  11. bool isMult3(int x);
  12. bool eWff(string doi, bool(*P)(int) );
  13.  
  14. int main(){
  15. string files[2] = {"data1.txt", "data2.txt"};
  16. cout << boolalpha;
  17. for(int i=0; i<2; i++){
  18. cout <<"Predicate wff evaluates to "<< eWff(files[i], isEven) <<" for DOI "<< (i + 1)<< " and predicate isEven()\n";
  19. cout <<"Predicate wff evaluates to "<<eWff(files[i],isMult3) <<" for DOI " << (i + 1) <<" and predicate isMult3()\n\n";
  20. }
  21. return 0;
  22. }
  23.  
  24. void absVal (int &x){
  25. if(x < 0) x *= -1;
  26. }
  27.  
  28. bool isEven(int x){
  29. absVal(x);
  30. return x % 2 == 0;
  31. }
  32.  
  33. bool isMult3(int x){
  34. absVal(x);
  35. return x % 3 == 0;
  36. }
  37.  
  38. bool eWff(string doi, bool(*P)(int) ){
  39. int num=0;
  40. bool value = false;
  41.  
  42. ifstream ifile;
  43. ifile.open(doi);
  44. if(ifile.is_open()){
  45. while(!ifile.eof()){
  46. ifile>>num;
  47. value = P(num);
  48.  
  49. if(value) return value;
  50. }
  51. }
  52. ifile.close();
  53. return value;
  54. }
Add Comment
Please, Sign In to add comment