Il T-Mobile 86% 7:53 PM a blackboard.odu.edu Past- Write a C+program to gencrate
ID: 3909267 • Letter: I
Question
Il T-Mobile 86% 7:53 PM a blackboard.odu.edu Past- Write a C+program to gencrate the data file "data.txt" Each line in this file represents an employe record, with cach element separatod by a comma which includes the: empID, firstnane,lastnane, storel, salary, daysworked As shown below for one employee 100002, ezyonolentpise tpverdteowjnfur, 354944442. 225. The record above is just an example of one employee, remember there are 5000 employees. The text file should be soetod with the lowest emplD first Use an array of struct foe the creation of the emplayoes. Please nole that the emplD is a unique 6 digit number. You should use a random nuber generalor to gencrale a unique ID for each employee. This should be accomplished within a stand alone function called genlDO which also checks to make sure the ID is unique within the array of 5000 employees. The fact that this function accesses the entire array is part of why it is a standalone function and not a member function of the struct employee. For cach employee you must randomly generate A unique emplD of 6 digits .A first name and a last name, (not uniquc) of random length between 8 and 16 characters, madk spof random chars. This can be stored in separate variables oe within its own stract . A store ID (not uniquc) of 4 digits . A salary between 20,000 and 100,000 iclusive). Days Worked, 0-21 (inclusive) days for each month, for 12 months out of the year. The sum of days worked for all months will be stoeed in the file . Sales total for each day weeked in a month are added to the monthly Sales Total. Moethly sotals are separated by spaces This can be stored in a single string Sales should be higher for employees with higher salaries: o o "Salariesc60000, daily sales should be from 1000-15000 a day Soe each day weeked) Salaries60000, daily sales should be fros 3000-20000 a daylfior each day worked) o A line of output, including Monthly Sales Totals, should look like this 100001, wtfxitngbkviye, zhajstwyxcaptn 9572, 52173, 123, 25908 0 92106 7831 41707 109114 26283 5399 149521 139501 108583 57303 All on ene line in a text file. The total sales for each of the 12 months should be separated by a space, while the other items in the row should be separated by commas Other Functions for Part A: .A Boolean member function which compares the emplD of this instance of employee with another .A print member function which prints the conments of this instance of employee in the format given . A standalone function which sorts the areay by ID, using the member comparison function. Places the .A standalone function which prints out the employee aray so file, calling the employee peinto instance of employse passed as a parameter. Returns truc if this emplD another omplD above to an outstream. lowest ID number at the top of the Armay (should be printed first in the file) function for cach array member The resulting text file should contain $000 employees, each on its own line, and all of their data The employces should be sorted with lowest LD at the sop of the fille. ALL DATA SHOULD BE RANDOMLY GENERATED. Be sure that srand is only being called once, so that the random number sequence doesn't restart over and over. . Zip the Code: Blocks project containing l the epp. h ebp files and name the ripped file AsspóA cslogis.zip". where the cslopin is your lopin ID for the computers at the Department of Computer Science at ODLI. You can exclude the bin and debug Solders . You dosot have to subenit the txt file (data.txt)wh your peogram foe Part-A. This file will be deleted when the graders test your program Submit the zipped filkk wsing the appropriate Blackboard linkExplanation / Answer
ScreenShot
---------------------------------------
Program
//Header files
#include<iostream>
#include<string>
#include<algorithm>
#include<fstream>
using namespace std;
//Employee structure
struct Employee {
int empId;
string fName;
string lName;
int storeId;
int salary;
int daysWorked;
int salesTotal[12];
};
//For employee sort check
bool compareTwoEmployees(Employee e1, Employee e2)
{
// If total marks are not same then
// returns true for higher total
if (e1.empId!=e2.empId)
return e1.empId < e2.empId;
else
{
return e1.empId > e2.empId;
}
}
// Sort employee
void sortAsc(Employee e[])
{
sort(e, e+5000, compareTwoEmployees);
}
//Main method
int main()
{
//Output file object creation and path setting
ofstream out;
out.open("C:/Users/deept/Desktop/data.txt");
Employee details[5000];
int total = 0, mSales = 0;
string name1,name2;
//FIrstName and lastName generation
int len = rand() % 16+8;
while (!(len >=8 && len < 16)) {
len = rand() % 16+8 ;
}
char alpha[] = "abcdefghijklmnopqrstuvwxyz";
//Employee Id generation
for (int i = 0; i < 5000; i++) {
do {
details[i].empId = rand() % 999999 + 100000;
for (int j = 0; j < i; j++) {
if (details[i].empId == details[j].empId) {
details[i].empId = 0;
break;
}
}
} while (details[i].empId == 0);
//First and last name set
for (int j = 0; j <len ; j++) {
name1+= alpha[rand() % (sizeof(alpha) - 1)];
}
details[i].fName = name1;
name1 = "";
for (int j = 0; j < len; j++) {
name2+= alpha[rand() % (sizeof(alpha) - 1)];
}
details[i].lName = name2;
name2 = "";
//storeid creation
details[i].storeId = rand() % 9999 + 1000;
//Salary creation
details[i].salary= rand() % 100001 + 20000;
//Work days and total sales calculation and store
for (int k = 0; k < 12; k++) {
int monthWork = rand() % 21;
for (int l = 0; l < monthWork; l++) {
if (details[i].salary < 60000) {
int daySales = rand() % 15000 + 1000;
mSales += daySales;
}
if (details[i].salary > 60000) {
int daySales = rand() % 20000 + 3000;
mSales += daySales;
}
}
total += monthWork;
details[i].salesTotal[k] = mSales;
}
details[i].daysWorked = total;
}
//Call sort function
sortAsc(details);
//Check print
for (int i = 0; i < 2; i++) {
cout << details[i].empId<< "," << details[i].fName << "," << details[i].lName << "," << details[i].storeId << "," << details[i].salary << "," << details[i].daysWorked<<",";
for (int j = 0; j < 12; j++) {
cout << details[i].salesTotal[j] << " ";
}
cout << endl;
}
//Write into file
if (!out) {
cout << "File not open" << endl;
exit(0);
}
else {
for (int i = 0; i < 5000; i++) {
out << details[i].empId << "," << details[i].fName << "," << details[i].lName << "," << details[i].storeId << "," << details[i].salary << "," << details[i].daysWorked << ",";
for (int j = 0; j < 12; j++) {
out << details[i].salesTotal[j] << " ";
}
out << endl;
}
}
return 0;
}