Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- merav izhaki
- 322915430
- exercise 6
- question 4
- A program that receives a file named information.txt (this file must be created manually in the executable folder) data.
- 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*/
- #include<iostream>
- #include<fstream>
- using namespace std;
- int time(char num) { //A function that calculates the incidence of each number
- char a = 0, counter = 0;
- ifstream information("information.txt");
- while (!information.eof()) {
- information >> a;
- if (a == num)
- counter++;
- }
- return counter;
- }
- int main() {
- ofstream frequency1("frequencyDigits.txt");
- frequency1 << "digit" << '\t' << "frequency" << endl;
- char ch = 48;
- for (int i = 0; i < 10;i++) {
- frequency1 << i << '\t' << time(ch)<<endl;
- ch++;
- }
- system("pause");
- return 0;
- }
- /*
- output:
- digit frequency
- 0 4
- 1 3
- 2 1
- 3 0
- 4 1
- 5 2
- 6 1
- 7 0
- 8 0
- 9 2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement