Question: in c + + 1 2 . 6 6 Chapter 8 - Shoes w / Pointers In the given C + + code, there are

in c++
12.66 Chapter 8- Shoes w/ Pointers
In the given C++ code, there are three Shoes objects: shoe1, shoe2, and shoe3.
PrintShoes(shoe1) will print the brands of the shoes in the linked list.
Modify the code to link the shoe1, shoe2 and shoe3 in a linked list.
using (and do onot change) the following code:
#include
#include
using namespace std;
// Defining a class named "Shoes"
class Shoes {
public:
string brand; // Member variable to store the brand of the shoe
Shoes* nextShoesAddress; // Pointer to the next Shoes object in the list
};
// Function to print the list of shoes
void PrintShoes(Shoes startShoe){
Shoes* currentShoe; // Pointer to keep track of the current shoe
int shoeCount; // Variable to keep count of the shoes
currentShoe = &startShoe; // Set the current shoe to the start of the list
shoeCount =0;
// Loop through the list of shoes until we reach the end
while (currentShoe !=0){
shoeCount = shoeCount +1;
cout << "Shoe "<< shoeCount <<"="<<(*currentShoe).brand << endl;
currentShoe =(*currentShoe).nextShoesAddress; // Move to the next shoe in the list
}
return;
}
int main(){
Shoes shoe1, shoe2, shoe3;
// Assigning brands to each shoe
shoe1.brand = "Nike";
shoe2.brand = "Puma";
shoe3.brand = "Adidas";
/// Code here to link shoe1, shoe2 and shoe3 in a linked list
///
// Calling the function to print the list of shoes, starting from shoe1
PrintShoes(shoe1);
return 0;
}

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 Programming Questions!