Coding Question. A Fastfood store manager wants you to create a program to keep
ID: 3751301 • Letter: C
Question
Coding Question.
A Fastfood store manager wants you to create a program to keep track of all of his inventory and workers. You are given 4 files: Food.txt, Employee.txt, Condiment.txt, and PlasticItem.txt. Create an array of structs for each file to hold the entries.
Food.txt
1. Name
2. Number Remaining
3. Expiration Date (month:day:year)
4. Cost
Employee.txt
1. Name
2. Id
3. Salary
4. Hire Date (month:day:year)
5. Rating (1-10)
Condiment.txt
1. Name
2. Ounces Remaining
3. Expiration Date (month:day:year)
4. Cost
PlasticItem.txt
1. Name
2. Number Remaining
3. Cost
Write a C++ program to help the Fast Food store manager. Create four arrays of structs named Food, Employee, Condiment, and PlasticItem. The size of the array should be read in from the file. Structs should be created to hold the variables that won’t fit a standard data type. The main() function of your program should be very simple. The main function should be a collection of variable declarations and function calls. You will need to use four different functions to read the data from the four files. You can add more functions if you want. You are to give the user the ability to print out each section’s records (Food, Employee, Condiment, and PlasticItem). Do NOT use global variables.
In the first line of each file there will be a number indicating how many entries are in the file.
Food.txt
Condiments.txt
Employee.txt
PlasticItem.txt
Sample Output:
Thank you in advance!
ZARestaurant bin DebugRestaurant.exe This is Assignment 1 (Structs estaurant Select which option you would like to see . Print all Food 2. Print all Employees 3. Print al1 Condiments 4. Print all Plastic Items 5. Exit Enter Option 1-5 ZARestaurantibinDebuglRestaurant.exe Food Nane Nunber left Sell By Date Cost Tonato Cucumber Bread Eggs Turkey Orange Lettuce HotDog Chicken Bun Burger Rib Apple Banana Carrot 20 89 07:02:2015 06:15:2014 06:25:2017 08:29:2015 05:1:2010 04:19:2011 09:05:2002 05:20:2010 03:11:2016 06:24:2013 03:29:2016 06:15:2013 08:21:2012 10:22:2013 09:22:2013 1.95 0.89 2.69 2.33 1.72 0.12 0.3 0.99 1.01 1.89 66.6 1.23 1.87 1.95 1.99 56 16 40 16 18 21Explanation / Answer
All the variables used in the code are self explainatory.
Refer the below code:
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define pb push_back
#define mp make_pair
struct food{
char name[100],expiration_date[100];
int number_remaining;
float cost;
};
struct condiments{
char name[100],expiration_date[100];
int ounces_remaining;
float cost;
};
struct employee{
char name[100],hire_date[100];
int id,rating,salary;
};
struct plastic
{
char name[100];
int number_remaining;
float cost;
};
int main()
{
FILE * Food=fopen("Food.txt","r");
int count_food;
fscanf(Food,"%d",&count_food);
// cout << count_food << endl;
food F[count_food+1];
for(int i=0;i<count_food;i++)
{
fscanf(Food,"%s",F[i].name);
fscanf(Food,"%d",&F[i].number_remaining);
fscanf(Food,"%s",F[i].expiration_date);
fscanf(Food,"%f",&F[i].cost);
}
fclose(Food);
FILE * Emp=fopen("Employee.txt","r");
int count_emp;
fscanf(Emp,"%d",&count_emp);
employee E[count_emp+1];
for(int i=0;i<count_emp;i++)
{
fscanf(Emp,"%s",E[i].name);
fscanf(Emp,"%d",&E[i].id);
fscanf(Emp,"%d",&E[i].salary);
fscanf(Emp,"%s",E[i].hire_date);
fscanf(Emp,"%d",&E[i].rating);
}
fclose(Emp);
FILE * Condiments=fopen("Condiments.txt","r");
int count_condiments;
fscanf(Condiments,"%d",&count_condiments);
condiments C[count_condiments+1];
for(int i=0;i<count_condiments;i++)
{
fscanf(Condiments,"%s",C[i].name);
fscanf(Condiments,"%d",&C[i].ounces_remaining);
fscanf(Condiments,"%s",C[i].expiration_date);
fscanf(Condiments,"%f",&C[i].cost);
}
fclose(Condiments);
FILE * Plastic=fopen("PlasticItem.txt","r");
int count_plastic;
fscanf(Plastic,"%d",&count_plastic);
plastic P[count_plastic+1];
for(int i=0;i<count_plastic;i++)
{
fscanf(Plastic,"%s",P[i].name);
fscanf(Plastic,"%d",&P[i].number_remaining);
fscanf(Plastic,"%f",&P[i].cost);
}
fclose(Plastic);
cout << "Select which option would you like to see" << endl;
int opt;
while(true)
{
cout << "1. Print all Food" << endl;
cout << "2. Print all Employees" << endl;
cout << "3. Print all Condiments" << endl;
cout << "4. Print all Plastic Items" << endl;
cout << "5. Exit" << endl;
cout << "Enter Option (1-5): ";
cin >> opt;
if(opt==1)
{
cout << " ====================" << endl;
cout << " FOOD" << endl;
cout << " ====================" << endl;
printf("%15s:%15s:%15s:%15s ","Name","Number Remaining","Expiration Date","Cost");
for(int i=0;i<count_food;i++)
{
printf("%15s %15d %15s %15f ",F[i].name,F[i].number_remaining,F[i].expiration_date,F[i].cost);
}
}
else if(opt==2)
{
cout << " ====================" << endl;
cout << " EMPLOYEE" << endl;
cout << " ====================" << endl;
printf("%15s:%15s:%15s:%15s:%15s ","Name","ID","Salary","Hire Date","Rating");
for(int i=0;i<count_emp;i++)
{
printf("%15s %15d %15d %15s %15d ",E[i].name,E[i].id,E[i].salary,E[i].hire_date,E[i].rating);
}
}
else if(opt==3)
{
cout << " ====================" << endl;
cout << " CONDIMENTS" << endl;
cout << " ====================" << endl;
printf("%15s:%15s:%15s:%15s ","Name","Ounces Remaining","Expiration Date","Cost");
for(int i=0;i<count_condiments;i++)
{
printf("%15s %15d %15s %15f ",C[i].name,C[i].ounces_remaining,C[i].expiration_date,C[i].cost);
}
}
else if(opt==4)
{
cout << " ====================" << endl;
cout << " PLASTIC ITEMS" << endl;
cout << " ====================" << endl;
printf("%15s:%15s:%15s ","Name","Number Remaining","Cost");
for(int i=0;i<count_plastic;i++)
{
printf("%15s %15d %15f ",P[i].name,P[i].number_remaining,P[i].cost);
}
}
else if(opt==5) break;
else cout << "Please Enter Valid Option" << endl;
}
return 0;
}