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

C++ Write a program that creates a linked list of Box Records Description Create

ID: 3594973 • Letter: C

Question

C++ Write a program that creates a linked list of Box Records Description Create a linked list of Boxes. Each noce in the list is a struct Box object Define a struct Box. The struct should include the following data members ID number width of a box + Height of a box + Length of a box + A "next" pointer The program will have two function bool insert and void display The program should prompt the user to enter different types of boxes, the program shoule then ask the user if he or she wishes to see the list of boxes, and display them if the user's response is yes. The screern should clear before displaying the list. The program shoule allow the user to run it repeatedly OUTPUT… Enter the specifications of different types of boxes. Inchude the number of boxes presently in inventory Enter boxes (-1 to quit) ID number 100 ID numbe 10 ID number 102 ID number 103 width: 3.25 height: 2.50 lenghth : 3.50 lenghth : 6.5 5 width: 4.00 height : 8.50 width: 3.50 height: 5.00 lenghth : 7.75 width: 2.75 height: 3.75 lenghth: 9.00 Would you like to see the list of boxes (YN) ? y -(Screen clears) Types of boxes ID# Width Height Length 103 2.75 3.75 9.00 102 3.505.007.75 101 100 3.25 2.503.50 Would you like to enter some new records (y/n) ? n Have a nice day? Press any key to contnue.... 4.00 8.50 2

Explanation / Answer

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

using namespace std;

struct Box {
   int id;
   double width;
   double height;
   double length;
   Box *next;
};

Box *insert(Box *head, Box b){

    Box *t;
    Box *temp = new Box();
    temp->width = b.width;
    temp->height = b.height;
    temp->length = b.length;
    temp->next = NULL;

    if (head == NULL){
        head = temp;
    }
    else {
       t = head;
       while(t->next !=NULL){
          t = t->next;
       }
       t->next = temp;
    }

}
void display(Box *head){

    Box *t;
    if (head == NULL){
        cout << "List is empty ";
    }
    else {
       t = head;
       while(t!=NULL){
          cout << setw(10) << t->id << setw(10) << t->width << setw(10) << t->height << setw(10) << t->length << endl;
          t = t->next;
       }
      
    }

}


int main(){
  
   int id;
   double width, height, length;
   string ch1;
   int ch;

   while(1){

       cout << "Enter the specifications of different types of boxes.Include the number of boxes presently in inventory ";
       cout << "Enter boxes (-1 to quit or any +ve number to continue): ";
       cin >> ch;
       Box *head;
       head = NULL;
       while(ch != -1){
           int count = 0;
           while (count < ch){
             Box b;
             cout << "ID:";
             cin >> b.id;   
          
             cout << "Width:";
             cin >> b.width;   
             cout << "Height:";
             cin >> b.height;     
             cout << "Length:";
             cin >> b.length;  
             head = insert(head,b);
             count++;
           }  
           cout << "Enter boxes (-1 to quit): ";
           cin >> ch;
       }
       cout << "Would you like to see the list of boxes(Y/N)? ";
       system("clear");
       cin >> ch1;
       if (ch1[0] == 'y' or ch1[0] == 'Y'){
          cout << "--------------------------------------------- ";
          cout << setw(10) << "ID" << setw(10) << "Width" << setw(10) << "Height" << setw(10) << "Length" << endl;
          cout << "--------------------------------------------- ";
          display(head);
       }
       cout << "Would you like to enter some new records(Y/N)? ";
       cin >> ch1;
       if (ch1[0] == 'n' or ch1[0] == 'N') {
          cout << "Have a nice day?";
          break;
       }

   }
   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