Question: Hello, can someone help me with my C++ code? Here is the task and code. I need a alternatively code to this code(and with comments

Hello, can someone help me with my C++ code? Here is the task and code. I need a alternatively code to this code(and with comments of full program).

Task: Write a program that realizes the processing of orders. To do this, use the Order class and the supporting classes Customer and Product (see class diagrams): Hello, can someone help me with my C++ code? Here is the Special features of the data elements and element functions are: -Each order contains an association (i.e. a pointer) to exactly one customer who initiated this order and any number of associations (i.e. here a vector with pointers) to products that are part of this order. - The constructor of Product sets the data elements product number, name (name) and price (price) to externally adopted values. - toString returns all data elements of an object (ie number, name and price) in clear formatting as a string. -The constructor of Customer sets the data elements customer number, name and address to externally adopted values. - toString returns number, name and address in clear formatting as a string. - The constructor of Order sets customer to the memory address of a customer object taken from outside. In addition, it sets the data element order Untertitel number (number) for each new order object as follows: The (static) class variable numberCounter is initially initialized to the value 1001. Every time an Order object is created, the current value of numberCounter is transferred to the object variable number; then numberCounter is increased by one. - addProduct adds the memory address of a product in the application program to the products data element. - computeOrderPrice calculates the total price of all products contained in the order object and returns it. - sort sorts the products in products in ascending order according to their product number. The sorting process direct insertion (insertion sort) should be used here. - toString returns the values of all data elements of the Order object in clear formatting as a string; In addition, the string should contain the total price of all products contained in the order object. The application program (main) should test the classes and their interactions. To do this, the following actions should be carried out in sequence (no menu, no user input!): - Create an array object that contains at least two different Customer objects and an array object that contains at least eight different Product objects. -Create two suitable order objects and add at least three of the existing products to both orders (initially unsorted with regard to the product number). - Sort the two jobs and output them.

My code:

Main.cpp

Order.cpp

Product.cpp

Customer.cpp

Order.h

Product.h

Customer.h

#include

#include"Customer.h"

#include"Order.h"

#include"Product.h"

int Order::numberCounter=1001;

void main()

{

// create customer

Customer C[2]={Customer(41,"Jan","CA"),Customer(22,"Joye","US")};

Product Ps[9]={Product(25,"P1",30),Product(85,"P2",40),Product(524,"P3",50),

Product(8,"P4",20),Product(66,"P5",88),Product(333,"P6",99),

Product(44,"P7",40),Product(77,"P8",77),Product(66,"P9",100)};

Order O1(&C[0]);

O1.addproduct(&Ps[0]);

O1.addproduct(&Ps[1]);

O1.addproduct(&Ps[2]);

Order O2(&C[1]);

O2.addproduct(&Ps[3]);

O2.addproduct(&Ps[4]);

O2.addproduct(&Ps[5]);

cout

cout

//////////////

O1.sort();

O2.sort();

cout

cout

}

#include "Order.h"

Order::Order(Customer* C)

{

Cust=C;

number=numberCounter++;

Pronumber=0;

}

void Order::addproduct(Product * Pr)

{

Products[Pronumber++]=Pr;

}

double Order::computeOrderPrice()

{

double Total=0;

if(Pronumber!=0)

{

for(int i=0;i

{

Total+=Products[i]->price;

}

}

return Total;

}

void Order::sort()

{

for(int i=1; i

{

Product *key = Products[i];

for(int j=i-1; j>-1; j--)

{

if (key->number number)

{

Products[j+1] = Products[j];

Products[j] = key;

}

else break;

}

}

}

string Order::Tostring()

{

string Temp="Order Number: "+to_string(number)+", Customer: "+Cust->name+",";

for(int i=0;i

{

Temp+=Products[i]->name+", ";

}

return(Temp);

}

#include "Product.h"

Product::Product(int T,string N, double P)

{

number=T;

name=N;

price=P;

}

string Product::ToString()

{

return("Product number: "+to_string(number)+", Product Name: "+name+", Price: "+to_string(price));

}

#include "Customer.h"

Customer::Customer(int a, string N, string Add)

{

number=a;

name=N;

address=Add;

}

string Customer::Tostring()

{

return("Customer number: "+to_string(number)+", Name: "+name+", address: "+address);

}

#pragma once

#include

#include"Customer.h"

#include"Product.h"

using namespace std;

class Order

{

public:

static int numberCounter;

int number;

Customer * Cust;

Product *Products[100];

int Pronumber;

Order(Customer *);

void addproduct(Product *);

double computeOrderPrice();

void sort();

string Tostring();

};

#pragma once

#include

using namespace std;

class Product

{

public:

int number;

string name;

double price;

Product(int,string,double);

string ToString();

};

#pragma once

#include

using namespace std;

class Customer

{

public:

int number; // CustomerNumber

string name;

string address;

Customer(int,string,string);

string Tostring();

};

Order numberCounter: int number: int customer: Customer* - products: vector + Order (Customer*) + addProduct (Product*): void + computeOrderPrice(): double + sort(): void + toString(): string Customer Product number: int name: string address: string + Customer (int, string, string) + toString(): string + number: int name: string price: double + Product (int, string, double) + toString(): string + Order numberCounter: int number: int customer: Customer* - products: vector + Order (Customer*) + addProduct (Product*): void + computeOrderPrice(): double + sort(): void + toString(): string Customer Product number: int name: string address: string + Customer (int, string, string) + toString(): string + number: int name: string price: double + Product (int, string, double) + toString(): string +

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!