ok this is for an object oriented programming class.
i have 5 files
Main.cpp (which i cant modify)
computer.cpp (implementation of computer.h)
computer.h (interface for computer.cpp)
memory.cpp(implementation of memory.h)
memory.h (interface for memory.cpp)
Code://main.cpp #include <iostream> using namespace std; #include "Computer.h" The output from the program is shown below: comp1: Computer has 256 MB memory comp1: Computer has 512 MB memory comp1: Computer has 512 MB memory comp2: Computer has 512 MB memory comp1: Computer has 512 MB memory comp2: Computer has 1024 MB memory */ int main(int argc, char* args[]) { Computer comp1(new Memory(256)); cout << "comp1: " << comp1.get() << endl; comp1.changeMemory(new Memory(512)); cout << "comp1: " << comp1.get() << endl; Computer comp2 = comp1; cout << "comp1: " << comp1.get() << endl; cout << "comp2: " << comp2.get() << endl; comp2.changeMemory(new Memory(1024)); cout << "comp1: " << comp1.get() << endl; cout << "comp2: " << comp2.get() << endl; return 0; }Code://computer.h #include "Memory.h" class Computer { public: Computer(Memory* newMem); ~Computer(); char* get(void); void changeMemory(Memory* newMem); int theMem; };Code://computer.cpp #include "Computer.h" #include <iostream> using namespace std; Computer::Computer(Memory* newMem){ } Computer::~Computer(){ } char* Computer::get(void){ } void Computer::changeMemory(Memory* newMem){ }Code://Memory.h class Memory { public: Memory(const int& newMem); ~Memory(); int& memVar; };i cant seem to implement the code. the interface is ok, it works. but i cant implement it and its driving me crazy ive tried everything and then finally deleted the implementation and tried to start over, and cant figure this out. i know i need a delete in the destructor. but i cant make it print the right information, ive gotten it to print some wierd negative number, a bunch of zeros and then finally the number... but the number was out of place.Code://Memory.cpp #include "Memory.h" #include <iostream> using namespace std; Memory::Memory(const int& newMem){ cout << newVar << endl; } Memory::~Memory(){ }
any help is apreciated.



LinkBack URL
About LinkBacks




CornedBee