Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1)Suppose txt file data.dat contains name and salary for all employees of a comp

ID: 3625310 • Letter: 1

Question

1)Suppose txt file data.dat contains name and salary for all employees of a company, as seen:
John 23567.99
Susan 56234.76
...
Write a short program asking for some salary and then printing how many people make salary within a $5k range from the one entered.

2) Assume
int x;
struct Pair {
int x, y;
} p1, p2;
Suppose a binary file data.bin was created by writing x followed by p1 and p2. Write all code fragments needed to read the data and print the total of the lone integer and the integer from the second structure.

Explanation / Answer

please rate - thanks

sorry

CRAMSTER rule, only 1 question per post

#include <iostream>
#include <fstream>
using namespace std;
   int main()
   {string name;
   double salary, pick,max,min,count=0;
   ifstream input;
   input.open("data.dat");        
   if(input.fail())           
       { cout<<"file did not open please check it ";
        system("pause");
        return 1;
        }
       cout<<"what salary are you looking for: ";
       cin>>pick;
       max=pick+5000;
       min=pick-5000;
      
      
      input>>name;
      while(input)
          {input>>salary;
          if(salary>=min&&salary<=max)
                count++;
          input>>name;        
          }
      cout<<"There are "<<count<<" salaries between $"<<min<<" and $"<<max<<endl;
       input.close();
         system("pause");
         return 0;
     }

question 2 would be something like this--it's not debugged, but I figured I'd give you an idea where to start

#include <iostream>
#include <fstream>
int x;
struct Pair {
int x, y;
} p1, p2;
using namespace std;

int main()
{fstream in;
char input;

in.open("data.bin", ios::in|ios::binary);
in.read(reinterpret_cast<int *>x,sizeof(x));      
in.read(reinterpret_cast<Pair *>(p1),sizeof(pair));  
in.read(reinterpret_cast<Pair *>(p2),sizeof(pair));
cout<<"total = "<<x+p2.x+p2.y<<endl;
in.close();
return 0;
}