help solve with c++ Define a structure called Employee with four member variable
ID: 3838218 • Letter: H
Question
help solve with c++
Explanation / Answer
#include<iostream>
#include <fstream>
struct Employee {
string firstName;
string lastName;
double salary;
int ID;
}
void read() {
ifstream myfile;
Employee emp;
double tot = 0;
int count = 0;
myfile.open ("10Prob1.dat");
while (!myfile.eof) {
myfile >> emp.firstName;
myfile >> emp.lastName;
myfile >> emp.salary;
myfile >> emp.id;
tot += emp.salary;
count ++;
cout << emp.firstName << " " << emp.lastName << " " << emp.salary << " " << emp.id << endl;
}
double avg = tot/count;
cout << "Average: " << avg << endl;
}
This code will help you. Let me know if you face any problem with the code. I shall try my best to resolve all your queries.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.