Question

Problem 1. Structures (10 points) A company keepsSimple C++. Sturctures- Please make sure it compiles.

John Harris 1000
Lisa Smith 1002
Adam Johnson 1007
Sheila Smith 1009
Tristen Major 1012
Yannic Lennart 1015
Lorena Emil 1018
Tereza Santeri 1020

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C++ code
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string> // std::string, std::to_string
#include <math.h>
#include <fstream>

using namespace std;

struct Confidential
{
int id;
int SSN;
double salary;
};

struct Employee
{
string FirstName;
string LastName;
int id;
struct Confidential conf;
};


int main()
{
Employee s[20];
int size = 0;

ifstream inFile ("file1.txt");
if (inFile.is_open())
{
while(true)
{
if(inFile.eof())
break;

inFile >> s[size].FirstName >> s[size].LastName >> s[size].id;
size++;
}
inFile.close();
}
else cout << "Unable to open file";

int readID;
ifstream inFile1 ("file2.txt");
if (inFile1.is_open())
{
while(true)
{
if(inFile1.eof())
break;

inFile1 >> readID;
for (int i = 0; i < size; ++i)
{
if(s[i].id == readID)
{
s[i].conf.id = readID;
inFile1 >> s[i].conf.SSN;
inFile1 >> s[i].conf.salary;
}
}
}
inFile1.close();
}
else cout << "Unable to open file";

cout << "Employee details\n";
for (int i = 0; i < size; ++i)
{
cout << s[i].id << "\t" << s[i].FirstName << " " << s[i].LastName << "\t" << s[i].conf.SSN << "\t" << s[i].conf.salary << endl;
}

return 0;
}


/*
file1.txt
John Harris 1000
Lisa Smith 1002
Adam Johnson 1007
Sheila Smith 1009
Tristen Major 1012
Yannic Lennart 1015
Lorena Emil 1018
Tereza Santeri 1020


file2.txt
1002 225365256 50000.00
1009 256214856 75000.00
1000 256314765 80000.00
1020 245123655 38000.00
1018 225453664 125000.00
1007 215236645 65800.00
1012 236456425 58000.00
1015 256452256 99000.00


output:
Employee details
1000 John Harris 256314765 80000
1002 Lisa Smith 225365256 50000
1007 Adam Johnson 215236645 65800
1009 Sheila Smith 256214856 75000
1012 Tristen Major 236456425 58000
1015 Yannic Lennart 256452256 99000
1018 Lorena Emil 225453664 125000
1020 Tereza Santeri 245123655 38000

*/

Add a comment
Know the answer?
Add Answer to:
Simple C++. Sturctures- Please make sure it compiles. John Harris 1000 Lisa Smith 1002 Adam Johnson...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Simple C++: Getting an input file and doing calculations. Input file to be read from should...

    Simple C++: Getting an input file and doing calculations. Input file to be read from should be named "1030Prob1.dat" it will contain the following:: John Harris 11374 50000.00 Lisa Smith 11985 75000.00 Adam Johnson 12585 68500.00 Sheila Smith 11654 150000.00 Tristen Major 11274 75800.00 Yannic Lennart 15687 58000.00 Lorena Emil 17414 43000.00 Tereza Santeri 12597 48000.00 A company keeps the record of its employees in a text file. The text file is in the following format FirstName LastName ID Salary...

  • C++ Simple Employee Tracking System

    This assignment involves creating a program to track employee information.  Keep the following information on an employee:1.     Employee ID (string, digits only, 6 characters)2.     Last name (string)3.     First Name (string)4.     Birth date (string as MM/DD/YYYY)5.     Gender (M or F, single character)6.     Start date (string as MM/DD/YYYY)7.     Salary per year (double)Thus you must create a class that has all of this, and get/set methods for each of these fields.  Note: The fields that are designated as string should use the string...

  • In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an...

    In C++ Please please help.. Assignment 5 - Payroll Version 1.0 In this assignment you must create and use a struct to hold the general employee information for one employee. Ideally, you should use an array of structs to hold the employee information for all employees. If you choose to declare a separate struct for each employee, I will not deduct any points. However, I strongly recommend that you use an array of structs. Be sure to read through Chapter...

  • Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In...

    Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In this project, we combine the concepts of Recursion and Merge Sorting. Please note that the focus of this project is on Merging and don't forget the following constraint: Programming Steps: 1) Create a class called Art that implements Comparable interface. 2) Read part of the file and use Merge Sort to sort the array of Art and then write them to a file. 3)...

  • Description: A program is needed for a third-party payroll clearinghouse that supports the following: Calculate employee...

    Description: A program is needed for a third-party payroll clearinghouse that supports the following: Calculate employee pay feature Company total pay feature The employee and company totals are stored in a text file for each individual company. 1. Create the following “input.txt” file. Each record consists of a first name, last name, employee ID, company name, hours worked, and pay rate per hour. Maria    Brown 10 Intel   42.75 39.0 Jeffrey Jackson 20 Boeing   38.0 32.5 Bernard Smith 30 Douglas   25.0...

  • Using Doubly Linked List, and Sorting methods: (In Java) (please attach your output with the answer)...

    Using Doubly Linked List, and Sorting methods: (In Java) (please attach your output with the answer) (Please answer if it is correct and working) (Have been getting many wrong and spam answers lately) Introduction: In this project, we use the same file structure of Artist and Art to extend the concepts of array and linked list and have them applied to sorting. The input files of p1arts.txt and p1artists.txt have been slightly modified. They are named p7arts.txt and p7artists.txt. Assignments:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT