#include <iostream>

#include <string>

using namespace std;

struct Donut {

string flavor;

int age;

double price;

Donut* prev = NULL;

Donut* next = NULL;


Donut(string flavor, int age, double price){

this->flavor = flavor;

this->age = age;

this->price = price;


// implement the copy constructors

Donut(const Donut &otherDonut);

Donut(const Donut *otherDonut);

void display() {

cout << flavor << "\t$" << price << "\t" << age << endl;



struct DonutTray


Donut* head = NULL; // head of the list of donuts

Donut* tail = NULL; // tail of the list of donuts

int length = 0; // number of donuts in the tray


// implement the copy constructor

// copies a another tray into this tray

DonutTray(const DonutTray &otherTray);

// implement the appendDonut method

// appends a donut at the end of the tray

// feel free to reuse implementations

// from labs or other past assignments

void appendDonut(Donut* donut);

// removes the donut from the list

void removeDonut(Donut* donut);

// implement the display() method

// iterates over this tray

// displaying each of the elements

void display();

// implement the concatenate() method

// concatenates another tray

// at the end of this tray

void concatenate(const DonutTray* otherTray);

// implement the removeStaleDonuts() method

// iterates over the tray removing stale donuts

// donuts are stale if their age is grater than

// maxAge

void removeStaleDonuts(int maxAge);


// here's an implementation of copy that

// doesn't quite work. The new tray does

// display as the original tray, but since

// it refers to the original elements, your

// can't manipulate the elements without

// also manipulating the original elements

DonutTray* badCopy(const DonutTray* other)


DonutTray* newTray = new DonutTray();

newTray->head = other->head;

newTray->tail = other->tail;

newTray->length = other->length;

return newTray;


// a better implementation of copy would

// create an exact replica of the original

// tray, but the elements would be brand

// new instances that have the same values

// as the original tray, but they can be

// manipulated independently from the original

// tray

DonutTray* goodCopy(const DonutTray* otherTray);

int main()


Donut* chocolate = new Donut("Chocola", 12, 0.99);

Donut* vanilla = new Donut("Vanilla", 13, 1.99);

Donut* strawberry = new Donut("Strawbe", 14, 2.99);

Donut* glazed = new Donut("Glazed", 15, 0.99);

Donut* boston = new Donut("Boston", 12, 1.99);

Donut* cream = new Donut("Cream", 13, 2.99);

// test display method

cout << "Display Donut" << endl;


// test the copy constructor

// make sure each has its own

// member variables

cout << endl << "Donut Copy Constructor" << endl;

Donut crispy("Crispy", 11, 0.59);

Donut copy = crispy;

[url removed, login to view]();

[url removed, login to view]();

[url removed, login to view] += 1.00;

[url removed, login to view] += 2.00;

[url removed, login to view]();

[url removed, login to view]();

// create a tray

cout << endl << "Create tray1" << endl;

DonutTray* tray1 = new DonutTray();





// create another tray

cout << endl << "Create tray2" << endl;

DonutTray* tray2 = new DonutTray();





// test concatenate tray2 into tray1

cout << endl << "Concatenate tray2 to tray1" << endl;



// make sure tray2 was not affected


// but if we append to tray2,

// tray1 will change too

// but that's ok for now




cout << endl << "Bad Copy" << endl;

/* test badCopy. realize that changing one

* tray changes the other


DonutTray* badCopyTray = badCopy(tray2);

// display both trays verifying the look the same



// change one of th

Evner: C++ Programmering

Se mere: string is not a member of std, std list c, std list, endl, donuts, Concatenate, append display, stale, number append, display test, void labs, struct, head tail, free data entry work copy past work, copy past number list, data entry online submit assignments program free sign, earn 1000 free past paypal, information feel free contact vertaal nederlands, free web look feel, feel free contact italian, vanilla brand, copy price list, free flash assignments done students, free past school proxy, please feel free contact translation spanish

Om arbejdsgiveren:
( 22 bedømmelser ) Cambridge, United States

Projekt ID: #6044318

Tildelt til:


Hired by the Employer

$15 USD på 1 dag
(6 bedømmelser)