I AM ASKING THIS QUESTION AGAIN AS THE q&a solutions were incomplete and didn\'t
ID: 3590033 • Letter: I
Question
I AM ASKING THIS QUESTION AGAIN AS THE q&a solutions were incomplete and didn't work. Please let me know where to put the binary file on my computer. I have my own IDE and can either use cpp.sh..... PLEASE AGAIN DO NOT SEND ME WHAT IS ALREADY PRESENT IN q&a portion
The Count3s program opens a binary file containing 32 bit integers (ints). Your program will count the number of occurrences of the value 3 in this file of numbers. Your objective is to learn about opening and accessing files and apply your knowledge of control structures. The name of the file containing data used by the program is "threesData.bin". After source code is complete please please note where to store and the threesData.bin file on my pc.
Explanation / Answer
#include<stdio.h>
#include<stdint.h>
using namespace std;
int main(){
int num = 162;
uint32_t a;
ifstream file("threesData.bin",ios::binary);
if (!file){
cout << "Error opening file ";
return 0;
}
int count = 0;
while (!file.eof()){
file.read(reinterpret_cast<char *>(&a),sizeof(a));
if (a == 3)
count++;
}
file.close();
cout << count << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.