Question

In: Computer Science

Write in C++ code A system that allow users to place an order for the food,...

Write in C++ code

A system that allow users to place an order for the food, view all the food details, modify or delete the food details. Design using objected oriented programming and list/link-list.

Food order information contain : OrderID(auto assigned,unique), Food Code, flavor , weight, unit price, qty and customer information such as id, name, address and contact number.

order ID shall be automatically assigned with a unique ID when new order is added.

When viewing food details, it should also display the bill amount (unit price *qty).

Solutions

Expert Solution

In this program we are using Three classes customer ,order and food .

The Customer class is used to store the custmer details .

The order class to Store/manage food details,it will check the every order in a random manner.

The food class must store the details of the food which are entered by user or customer.so order can have mutliple food items and it is based the customer usage.

while writting a program plz maitain some standard namespace because it reduces the errors while compiling .

In the below program we have used some modifiers to obtain the program correctly.

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>


int NP, NE, *VO,*VTP, T, pop, stok,st, nonam, iter, it, nb_am;
struct et
{
   int id, s, NM, *VT, *VA, **M, cmax;
};
struct sol
{
int *VSO, **aff,ValOrd, cmax;
};
et *FSH;
sol *SL;
void init();
void gener_sol();
void Aff();
void Matrice(et);
bool exist(int, int*);
int id(int, int[]);
int som(int **);
int MAX(sol);
void aff_sol(sol);
void permut(int&, int&);
int nbrNA(sol*, int);
sol best (sol*);
void genetic(sol*);
//---------------------------------------------------------------------------
int main()
{
   int V[10], i;   
   srand(time(0));
   init();
    Aff();
    cout << "\nSol initiale avant simulation : \n";
    aff_sol(SL[0]);
    genetic(SL);
    cout << "\nSol optimale apres simulation : \n";
    aff_sol(best(SL));
    cout << "\nnombre des iterations : "<< it<<"\n";
    cout << "\nnombre de non ameliores : "<< nb_am<<"\n";
   return 0;
}
//----------------------------------------------------------------------------
void init()
{
int i,j,k,a;
cout << "Donner le NBR des Pieces : ";
cin >> NP;  
cout << "Donner le NBR des Etages : ";
cin >> NE;
cout << "Donner la position du stockage \n(1-Par Machine, 2-Par Etage, 3-Par Systeme):";
cin >> stok;
cout << "Donner la taille de pop : ";
cin >> pop;
cout << "Donner le nombre d'iterations pour Genetic :";
cin >> iter;
cout << "Donner le nombre de non ameliores pour Genetic :";
cin >> nonam;
VO = new int[NP];
VTP = new int[NP];
for(a=0;a<NP;a++)for(i=0;i<NP;i++) {VO[i]=i+1; VTP[i] = rand()%30+10;}
FSH = new et[NE];
for(i=0;i<NE;i++)
{
    FSH[i].id=i+1;
    //cout << "Donner le Stockage de l'etage "<< i+1 << " :";
   //cin >> FSH[i].s;
   if(stok==1) st = 5;
   else if(stok==2) st = 10;
   else st = 30;
   cout << "Donner le nbr des machines de l'etage "<< i+1 << " :";
   cin >> FSH[i].NM;
   FSH[i].VT = new int[FSH[i].NM];
   for(j=0;j<FSH[i].NM;j++) for(a=0;a<NP;a++)FSH[i].VT[j] = rand()%5+1;
   FSH[i].VA = new int[NP];
   for(j=0;j<NP;j++)
    for(k=0;k<3;k++) {FSH[i].VA[j] = rand()%(FSH[i].NM)+1;}
    FSH[i].M = new int*[NP];
   for(j=0;j<NP;j++)FSH[i].M[j] = new int[NP];
Matrice(FSH[i]);
   FSH[i].cmax=0;
}
gener_sol();
}

void Aff()
{
int i,j,k;
cout << "le Nbr des pieces = " << NP << ".\n";
cout << "le Nbr des etages = " << NE << ".\n";
cout << "L'Ordonnancement des pieces : {";
for(i=0;i<NP;i++) cout << VO[i] <<" ";
cout <<"}.\n";
cout << "Temps de traitement de chaque pieces : {";
for(i=0;i<NP;i++) cout << VTP[i] <<" ";
cout <<"}.\n";
for(i=0;i<NE;i++)
{
    cout << "\nL'etage "<< i+1 << " :\n";
    //cout << " Capacite de stockage: "<< FSH[i].s<<".\n";
   cout << " le nbr des machines de l'etage "<< FSH[i].NM<<".\n";
   cout << " Affectation des pieces: {";
   for(j=0;j<NP;j++) cout << FSH[i].VA[j] <<" ";
   cout << "}.\n";
   cout << " Vitesse de traitement des machines: {";
   for(j=0;j<FSH[i].NM;j++) cout << FSH[i].VT[j] <<" ";
   cout << "}.\n";
   /*cout << " La Matrice de correspondance :\n";
   for(j=0;j<NP;j++)
   {
       cout << " ";
       for(k=0;k<NP;k++) cout << setw(3) << FSH[i].M[j][k] << setw(3);
       cout << "\n";
   }*/
}
}

void Matrice(et e)
{
   int i,j;
   for(i=0;i<NP;i++)
   for(j=i;j<NP;j++)
   {  
   if(i==j)
   e.M[i][j]=0;
   else
       if(e.VA[i]==e.VA[j])
       if(id(i+1,VO)<id(j+1,VO))
           e.M[i][j]=1;
           else
           e.M[i][j]=-1;
       else
       if(id(i+1,VO)<id(j+1,VO))
           e.M[i][j]=2;
           else
           e.M[i][j]=-2;
       e.M[j][i]=-e.M[i][j];      
   }
}
int id(int v, int A[])
{
   int i=0;
   while(v!=A[i])i++;
   return i;  
}
int som(int **M)
{
   int i,j,s=0;
   for(i=0;i<NP;i++)
   for(j=i;j<NP;j++)
   s += abs(M[i][j]);
   return s*2;
}
void permut (int &a, int &b)
{
   int c = a; a = b; b = c;
}
void gener_sol()
{
   int k,i,j,k1,k2;
   SL = new sol[pop];
   for (k=0;k<pop;k++)
   {  
   SL[k].VSO= new int[NP];
   SL[k].aff= new int*[NP];
   for(j=0;j<NP;j++)
   SL[k].aff[j]= new int[NE];
       if(k==0)
       {
           for(i=0;i<NP;i++) SL[k].VSO[i] = VO[i];
           SL[k].ValOrd = (rand()%20+50)*(NP+NE/2);
           for(i=0;i<NP;i++)
           for(j=0;j<NE;j++)
           SL[k].aff[i][j]=FSH[j].VA[i];
       }
       else
       {
           for(i=0;i<NP;i++) SL[k].VSO[i] = VO[i];
           k1 = rand()%NP; k2 = rand()%NP;
           permut (SL[k].VSO[k1], SL[k].VSO[k2]);
           SL[k].ValOrd = (rand()%20+50)*(NP+NE/2);
           for(j=0;j<NE;j++)
           for(i=0;i<NP;i++)
           SL[k].aff[i][j]=rand()%(FSH[j].NM)+1;
             
       }
   SL[k].cmax = MAX(SL[k]);
   }  
}

void aff_sol(sol S)
{
int i,j;
    cout <<"\nOrdonnancement : ";
    for (i=0;i<NP;i++)cout << S.VSO[i] <<" ";
    //cout << " \nLa valeur "<< S.ValOrd<<"\n";
    cout << "\nAffectation : \n";
    for (j=0;j<NE;j++)
    {
   for (i=0;i<NP;i++)cout << S.aff[i][j] <<" ";
   cout << "\n";
   }
cout << "\nCmax = " << S.cmax <<"\n";  
}

int MAX(sol S)
{
int f=0,i,j,m=0;
for(j=0;j<NE;j++)
{  
   for(i=0;i<NP;i++)
   m += st*0,01*VTP[S.VSO[i]-1]/FSH[j].VT[S.aff[i][j]-1];   
   m += S.ValOrd;
}
for(i=0;i<NE;i++) f+=FSH[i].NM;
f = f*NP;
return m+f;      
}

int nbrNA(sol *S, int max)
{
   int i, nb=0;
   for(i=0;i<pop;i++)
   if(MAX(S[i])==max)nb++;
   return nb;   
}
sol best (sol *S)
{
   int i;
   sol B = S[0];
   for(i=1;i<pop;i++)
   if(MAX(S[i])<MAX(B))B = S[i];
   return B;
}
void genetic(sol *S)
{
it=0; nb_am=0; int i,j,k1,k2,v,t;
sol S1, S2;
while (it<iter && nb_am<nonam)
{
i = rand()%pop; j = rand()%pop;
S1 = S[i]; S2 = S[j];
k1 = rand()%NP; k2 = rand()%NP;
permut(S1.VSO[k1], S1.VSO[k2]);
permut(S2.VSO[k1], S2.VSO[k2]);
for(t=0;t<NE;t++)
{
    v = rand()%NP;
    S1.aff[v][t] = S2.aff[v][t];
    v = rand()%NP;
    S2.aff[v][t] = S1.aff[v][t];
}
if(MAX(S1)<MAX(S[i]))S[i]=S1;
if(MAX(S2)<MAX(S[j]))S[j]=S2;
it++;
nb_am = nbrNA(S, MAX(best(S)));
}  
}


Related Solutions

Use linked list and write in C++ Food ordering system 1. Place Order 2. View the...
Use linked list and write in C++ Food ordering system 1. Place Order 2. View the food details 3. Modify food details 4. Delete food details Order should let the customer to enter the food code, flavor, weight(kg), unit price, qty, customerID, name, address and contact number. It will also have an order id automatically assigned with a unique ID when new order is added. When view the food details, it should also calculate the unit price * qty as...
Use linked list and write in C++ Food ordering system 1. Place Order 2. View the...
Use linked list and write in C++ Food ordering system 1. Place Order 2. View the food details 3. Modify food details 4. Delete food details Order should let the customer to enter the food code, flavor, weight(kg), unit price, qty, customerID, name, address and contact number. It will also have an order id automatically assigned with a unique ID when new order is added. When view the food details, it should also calculate the unit price * qty as...
Use list/link list and write in C++ Food ordering system 1. Place Order 2. View the...
Use list/link list and write in C++ Food ordering system 1. Place Order 2. View the food details 3. Modify food details 4. Delete food details 5. Exit Order should let the customer to enter the food code, flavor, weight(kg), unit price, qty, customer ID, name, address and contact number. It will also have an order id automatically assigned with a unique ID when new order is added. When view the food details, it should also calculate the unit price...
Write a C++ code to print to the user a simple menu of a fast food...
Write a C++ code to print to the user a simple menu of a fast food restaurant. You should allow the user to select his/her preferred burgers and/or drinks and you should display the final bill to the user for payment. The user should be able to select more than one item. You should use the switch statement.
in C programming Write the code to traverse the binary tree using in-order, post-order and pre-order...
in C programming Write the code to traverse the binary tree using in-order, post-order and pre-order methods. Make sure to validate that your output is correct. Review the terminology for tree structures and list structures. What is the root of the tree, what’s a parent, what’s a child, what’s an ancestor, what is an external node, what is an internal node, what is the head of the list, what is the tail of the list, etc. Traverse the binary tree...
The Incident Command System is a standardized management tool designed to allow its users to adopt...
The Incident Command System is a standardized management tool designed to allow its users to adopt an integrated organizational structure flexible enough to meet the demands of small or large emergency or non-emergency situations. But the Incident Command System has been at times criticized for ignoring the importance of inter-organizational relationships, the spontaneous nature of response, the role of unorganized volunteers, and the potential for conflict between organizations. Often the challenge can be reconstituting command and control after an improvised...
Give examples of a C++ program that allow users to manipulate (adding, removing, sort, etc.) a...
Give examples of a C++ program that allow users to manipulate (adding, removing, sort, etc.) a list of items. To start, you need to propose a problem that you would like to work on and you can't use TO-DO list.
2. Explain how the mesg, write, and wall commands can be used to allow users to...
2. Explain how the mesg, write, and wall commands can be used to allow users to talk to each other on UNIX
What are the primary differences between industrial users and home users of electricity that allow the...
What are the primary differences between industrial users and home users of electricity that allow the utilities to discriminate between the two markets in terms of price? How do we compensate for these differences in order to impove the "common good" and what effects may this have on relative prices?
Write a java code that ask users to pick two of the job categories and enter...
Write a java code that ask users to pick two of the job categories and enter two working areas from each category. The users must enter the start and end time for each of the two selection and calculate the hours for each category and the total hours for all the categories. If the users total hours is more that 10 hours, they are awesome, if not, they are lazy. Shor and simple code using while or for loops. Thanks...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT