Question: Write a program with Old fashion C + + : Deep Copies 1 . Write all programs in cross - platform C + + Optimize

Write a program with Old fashion C++ : Deep Copies
1. Write all programs in cross-platform C++
Optimize for execution speed and robustness
Working code doesnt mean full credit
2. No Containers
NO STL allowed {Vector, Lists, Sets, etc...}
o No automatic containers or arrays
o MUST to do this the old fashion way
3. Simple Old-fashion C++
No modern C++
o No Lambdas, Autos, templates, etc...
o No Boost
NO Streams
o Used fopen, fread, fwrite...
No code in MACROS
o Code needs to be in cpp files to see and debug it easy
4. Leaking Memory
If a class creates an object using new/malloc, It is responsible for its deletion
Any MEMORY dynamically allocated that isn't freed up is LEAKING.
5. No Adding files
This project will work as-is do not add files.
Fundamentals : Deep Copies
Write a double linked list
o Add to end of list
o Remove any node
o Print the contents of the list
o Deep copy
o Deep assignment
Simple double linked list
o No tail pointers
Car.h:
#ifndef CAR_H
#define CAR_H
class Car
{
public:
// add methods
//Car(const char *_pName, int a, int b);
//Car(const Car &);
//Car &operator=(const Car &) ;
//~Car();
// do not add data
Car *pNext;
Car *pPrev;
const char *pName;
int a;
int b;
};
#endif
Garage.h:
#ifndef GARAGE_H
#define GARAGE_H
#include "Car.h"
class Garage
{
public:
// implement these big 4
//Garage();
//Garage(const Garage &);
//Garage & operator =(const Garage &);
//~Garage();
// add methods
// do not add data
Car *poHead;
};
#endif
main.cpp:
#include "Car.h"
#include "Garage.h"
int main()
{
//-------------------------------------------------
// Do not change the main() function in any way
//-------------------------------------------------
Trace::out("--- G0---
");
Car *pA = new Car("A",11,14);
Car *pB = new Car("B",12,15);
Car *pC = new Car("C",13,16);
Garage *pG0= new Garage();
pG0->AddToEnd(pA);
pG0->AddToEnd(pB);
pG0->AddToEnd(pC);
pG0->Print("pG0");
Trace::out("--- Deep Copy: --- G1(G0)
");
Garage *pG1= new Garage(*pG0);
pG1->Print("pG1");
Trace::out("--- G2---
");
Car *pD = new Car("D",21,24);
Car *pE = new Car("E",22,25);
Car *pF = new Car("F",23,26);
Garage *pG2= new Garage();
pG2->AddToEnd(pD);
pG2->AddToEnd(pE);
pG2->AddToEnd(pF);
pG2->Print("pG2");
Trace::out("--- Deep Assignment --- G0= G2
");
*pG0=*pG2;
pG0->Print("*pG0=*pG1");
delete pG2;
delete pG1;
delete pG0;
Trace::out("
");
Test::RunTests();
}
!!!!!! output MATCH this sample (as close as possible ptrs will be different)!!!!!!
--------------------------------
Memory Tracking: start()
--------------------------------
--- G0---
Garage(pG0)0x005B05A0:
poHead:A
Car(A)0x005B8D20
next: B
prev: null
a: 11
b: 14
Car(B)0x005B8D60
next: C
prev: A
a: 12
b: 15
Car(C)0x005B8DA0
next: null
prev: B
a: 13
b: 16
--- Deep Copy: --- G1(G0)
Garage(pG1)0x005B8DE0:
poHead:A
Car(A)0x005B8E10
next: B
prev: null
a: 11
b: 14
Car(B)0x005B8E50
next: C
prev: A
a: 12
b: 15
Car(C)0x005B8E90
next: null
prev: B
a: 13
b: 16
--- G2---
Garage(pG2)0x005B8ED0:
poHead:D
Car(D)0x005BD510
next: E
prev: null
a: 21
b: 24
Car(E)0x005BD5D0
next: F
prev: D
a: 22
b: 25
Car(F)0x005BD4D0
next: null
prev: E
a: 23
b: 26
--- Deep Assignment --- G0= G2
Garage(*pG0=*pG1)0x005B05A0:
poHead:D
Car(D)0x005BDA10
next: E
prev: null
a: 21
b: 24
Car(E)0x005BD490
next: F
prev: D
a: 22
b: 25
Car(F)0x005BD990
next: null
prev: E
a: 23
b: 26

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!