Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please provide the c++ code based on the given UML, main, text file, output and

ID: 3712970 • Letter: P

Question

Please provide the c++ code based on the given UML, main, text file, output and instructions. Thank you!! Also, could you explain what i need to do with the .txt file to get it in my program (how to store it in the directory i think is what I am trying to say?)

TEXT FILE: Novemberdata.txt

Mickey 186
Minnie 274
Donald 84
Goofy 841
Daisy 178
Cinderella 387
SnowWhite 718
Aurora 2074
Ariel 478

MAIN main.cpp

const int MAX_SIZE = 100;

const double COST_PER_DOZ = 1.29;

const double COST_PER_SINGLE_EGG = .12;

int main()

{

int numCustomers;

EggOrder customers[MAX_SIZE];

string fileName;

cout << "Enter the file name: ";

cin >> fileName;

fileName = "novemberData.txt";

// Loads all of the customers into the array

numCustomers = loadArray(customers, fileName);

// Sorts all of the orders by customer name

sortOrders(customers, numCustomers);

// Prints all customer orders in the array

// Also prints the amount of each customers

// order using the constants that are

// declared

printOrder(customers, numCustomers);

}

UML is given to the right Declare this constant at the top of the header file: const int DOZEN 12 EggOrder -customerName: string -numDoz: int -numExtra: int Function Descriptions or Assigns values to the fields. Notice the one with just one formal parameter will have to do some calculations +EggOrder0 +EggOrder(name:string, numDoz:int, numExtra:int) +EggOrder(name:string, totalEggs:int) setters +setCustomerName (name:string):void Sets the attributes to the value setNumDoz(numDoz:int):void passed in. +setNumExtra(numExtra:int): void getters Return the e appropriate attributegetCustomerNameO:string getNumDozO:int getNumExtraO:int computes and returns the total number of eggs getTotalEggsO:int Once you have the class working and have tested it continue to the next part Main Function A main function has been given as well as a data file. You are to write functions that are called by the main function. Output is given on the following page

Explanation / Answer

Below is your code.

You need to keep your text file in the same directory in which you have you EggOrder.h EggOrder.cpp and main.cpp

EggOrder.h

#ifndef EGGORDER_H
#define EGGORDER_H
#include<string>
using namespace std;
const int DOZEN = 12;

class EggOrder
{
public:
EggOrder();
EggOrder(string,int,int);
EggOrder(string,int);

void setCustomerName(string);
void setNumDoz(int);
void setNumExtra(int);

string getCustomerName();
int getNumDoz();
int getNumExtra();
int getTotalEggs();

private:
string customerName;
int numDoz;
int numExtra;
};

#endif // EGGORDER_H

EggOrder.cpp

#include "EggOrder.h"

// Default constructor
EggOrder::EggOrder()
{
customerName = "";
numDoz = 0;
numExtra = 0;
}

// Constructor to initialize data members
EggOrder::EggOrder(string n,int doz,int extra){
customerName =n;
numDoz = doz;
numExtra = extra;
}

// Constructor to initialize data members
// Get dozen and extra eggs from total eggs
EggOrder::EggOrder(string n,int total){
customerName = n;
numDoz = total/DOZEN;
numExtra = total%DOZEN;
}

// Setter methods for data members
void EggOrder::setCustomerName(string name){
customerName = name;
}
void EggOrder::setNumDoz(int doz){
numDoz = doz;
}
void EggOrder::setNumExtra(int extra){
numExtra = extra;
}

// Get method for data members
string EggOrder::getCustomerName(){
return customerName;
}
int EggOrder::getNumDoz(){
return numDoz;
}
int EggOrder::getNumExtra(){
return numExtra;
}

// This method returns total eggs
int EggOrder::getTotalEggs(){
return (numDoz*DOZEN)+numExtra;
}

main.cpp

#include <iostream>
#include<fstream>
#include<sstream>
#include<iomanip>
#include "EggOrder.h"
using namespace std;

const int MAX_SIZE = 100;
const double COST_PER_DOZ = 1.29;
const double COST_PER_SINGLE_EGG = .12;

int loadArray(EggOrder customers[], string fileName){

// Open file to read
fstream fileIn;
fileIn.open(fileName);

string line = "";

// Counter variable to keep track of number of customers read from file
int i = 0;
// Iterate loop till the last line
while(getline(fileIn,line))
{
//Use string stream and read data into appropriate variable from it
stringstream ss(line);
string name;
int total;

ss>>name>>total;

// Create egg object
EggOrder egg(name,total);

// Store this object in customer array at index i
customers[i] = egg;
i+=1; // Increment index by 1
}
// Close file
fileIn.close();

// return i (indicates number of customers)
return i;
}


void sortOrders(EggOrder customers[], int numCustomers){

// Using bubble sort to sort customer array
// by customer name
for(int i = 0; i<numCustomers-1; i++)
{
for(int j = i+1; j<numCustomers; j++)
{
// If name of object at index i is > name of object at index j
// swap them
if(customers[i].getCustomerName()>customers[j].getCustomerName())
{
EggOrder temp = customers[i];
customers[i] = customers[j];
customers[j] = temp;
}
}
}

}


void printOrder(EggOrder customers[], int numCustomers){

cout<<" "<<endl;
cout<<setw(45)<<"November Report"<<endl;
cout<<right<<setw(20)<<"Name"<<setw(20)<<"Total Eggs"<<setw(20)<<"Amount Paid"<<endl;

// Iterate loop numCustomers times and print name, total eggs and amount paid
for(int i =0; i<numCustomers; i++)
{
// Calculate amount paid by each customer
double amountPaid = (customers[i].getNumDoz()*COST_PER_DOZ) + (customers[i].getNumExtra()*COST_PER_SINGLE_EGG);
cout<<right<<setw(20)<<customers[i].getCustomerName()<<setw(20)<<customers[i].getTotalEggs()<<setw(20)<<amountPaid<<endl;
}
}

int main()
{
int numCustomers;
EggOrder customers[MAX_SIZE];

string fileName;
cout << "Enter the file name: ";

cin >> fileName;

// Loads all of the customers into the array
numCustomers = loadArray(customers, fileName);

// Sorts all of the orders by customer name
sortOrders(customers, numCustomers);

// Prints all customer orders in the array
// Also prints the amount of each customers
// order using the constants that are declared
printOrder(customers, numCustomers);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote