Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you help me figure out why my code is not working? #include #include #include #include // Structure to represent an employee struct Employee

Can you help me figure out why my code is not working?


 

#include
#include
#include
#include

// Structure to represent an employee
struct Employee {
int id;
std::string firstName;
std::string lastName;
std::string phoneNumber;
std::string emailAddress;
double salary;

// Constructor for easy initialization
Employee(int empId, const std::string& first, const std::string& last,
const std::string& phone, const std::string& email, double empSalary)
: id(empId), firstName(first), lastName(last), phoneNumber(phone),
emailAddress(email), salary(empSalary) {}
};

int main() {
// Create a list to store employee data
std::listemployeeList;

// Open the file for reading
std::ifstream inputFile("employeeDataset.txt");

if (!inputFile.is_open()) {

std::cerr<<"Error opening the file.\n";

return 1;
}

// Read data from the file and populate the list
int id;
std::string firstName, lastName, phoneNumber, emailAddress;
double salary;

while (inputFile>>id>>firstName>>lastName>>phoneNumber>>emailAddress>>salary) {
employeeList.push_back(Employee(id, firstName, lastName, phoneNumber, emailAddress, salary));
}

// Close the file
inputFile.close();

// Displaying employee data from the list
std::cout<<"Employee List:\n";
std::cout<<"=======================================================================\n";
std::cout<<"| ID | First Name | Last Name | Phone | Email | Salary |\n";
std::cout <<"=======================================================================\n";

for(const auto& emp : employeeList) {
std::cout<<"|"<<

std::cout<<"=======================================================================\n";

return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Auditing Cases An Interactive Learning Approach

Authors: Steven M Glover, Douglas F Prawitt

4th Edition

0132423502, 978-0132423502

More Books

Students also viewed these Algorithms questions