Hi guys
Few questions about how to pass objects around a C++ program.
Please see the following code exerts.
Code:
/* Borrower.h
James Heggs
*/
#include <string>
#include <iostream>
using namespace std;
class Borrower
{
private:
int id;
string forename;
string surname;
public:
Borrower(int, string, string);
string getName();
void setForename(string);
void toString();
};
and Borrower.cpp
Code:
/* Borrower.cpp
James Heggs
*/
#include "Borrower.h"
#include <iostream>
#include <string>
using namespace std;
Borrower::Borrower(int aID, string fName, string sName)
{
id = aID;
forename = fName;
surname = sName;
}
string Borrower::getName()
{
return forename + " " + surname;
}
void Borrower::toString()
{
cout << "ID: " << id << "\nName: " << getName() << "\n";
}
void Borrower::setForename(string fName)
{
forename = fName;
}
int main()
{
//Call Borrower
Borrower b(12345, "James", "Heggs");
b.toString();
b.setForename("Peter");
b.toString();
}
==================
The the Copy stuff
Code:
/*Copy.h
James Heggs
*/
#include <string>
#include <iostream>
using namespace std;
class Copy
{
private:
static int copyID;
string title;
public:
Copy(string);
string getTitle();
void toString();
};
and Copy.cpp
Code:
/* Copy.cpp
James Heggs
*/
#include <string>
#include <iostream>
#include "Copy.h"
using namespace std;
int Copy::copyID = 1001;
Copy::Copy(string aTitle)
{
copyID = copyID;
title = aTitle;
copyID++;
}
string Copy::getTitle()
{
return title;
}
void Copy::toString()
{
cout << "ID: " << copyID <<
"\nTitle: " << title << endl;
//"\nBorrower: " << b << endl;
}
int main()
{
Copy aCopy("Jurassic Park");
aCopy.toString();
Copy bCopy("Tomb Raider");
bCopy.toString();
}
================
Two very basic classes, as I am a big noob at C++ and from a Java background can anyone tell me what I would need to add to Copy.h and Copy.cpp so that the Copies could also include a Borrower.
For instance when creating a Copy make it take the ID, title, and Borrower (Borrower could be initially set as (0000, "none", "none");
Any help would be great
Thanks guys
Eggsy