SHARE
TWEET

Untitled

a guest Dec 9th, 2019 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. merav izhaki
  3. 322915430
  4. exercise 6
  5. question 4
  6. A program that receives a file named information.txt (this file must be created manually in the executable folder) data.
  7. The program must create a new file called frequencyDigits.txt and print in this file only the incidence of digits that appear in the input file*/
  8. #include<iostream>
  9. #include<fstream>
  10. using namespace std;
  11.  
  12. int time(char num) {       //A function that calculates the incidence of each number
  13.     char a = 0, counter = 0;
  14.     ifstream information("information.txt");
  15.     while (!information.eof()) {
  16.         information >> a;
  17.         if (a == num)
  18.             counter++;
  19.     }
  20.  
  21.     return counter;
  22. }
  23. int main() {
  24.     ofstream frequency1("frequencyDigits.txt");
  25.     frequency1 << "digit" << '\t' << "frequency" << endl;
  26.     char ch = 48;
  27.     for (int i = 0; i < 10;i++) {
  28.         frequency1 << i << '\t' << time(ch)<<endl;
  29.         ch++;
  30.     }
  31.     system("pause");
  32.     return 0;
  33. }
  34. /*
  35. output:
  36. digit frequency
  37. 0     4
  38. 1     3
  39. 2     1
  40. 3     0
  41. 4     1
  42. 5     2
  43. 6     1
  44. 7     0
  45. 8     0
  46. 9     2
  47.  
  48. */
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top