Assignment dealing with classes...

Hey guys I need some help with an assignment I'm working on. It tells me to write classes for Author, Publisher, and Book. An Author and Publisher object has to be added to Book. I've written the Author and Publisher classes, and I'm working on Book before I start main, but I have some problems.

(my Book.cpp file isn't completed yet)
1. The strings are underlined with the error "string" is ambiguous in the cpp.
2. I'm asked to make an Author and Publisher object a private variable in Book.
I then have to make a constructor that takes a title, author, and publisher parameter. My constructor in the header isn't working, and I'm not sure why.
3. Part of the instructions for the Book class requires me to initialize the Author and Publisher objects. I don't think I'm doing it right, but I added a friend function for each of them included in my code. Is that how I should do that, and, if so, did I do it right?

The order for the code below:
Book.h
Book.cpp
Author.h
Author.cpp
Publisher.h
Publisher.cpp


Book.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef Book_H
#define Book_H
#include "Author.h"
#include "Publisher.h"
#include <cstdlib>
#include <string>
using namespace std;

class Author;
class Publisher;

class Book
{
private:
	string title;
	class Author;
	class Publisher;
	int numPages;
	string edition;
	int copyrightYear;
public:
	Book (string t, Author a, Publisher b);
	void setTitle(string t);
	string getTitle();
	void setNumPages(int n);
	int getNumPages();
	void setEdition(string e);
	string getEdition();
	void setCopyrightYear(int c);
	int getCopyrightYear();
	
	void getInfo(Author &);
	void getInfo(Publisher &);
	Author getInfo(Author &);
	Publisher getInfo(Publisher &);
}

#endif 


Book.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "Book.h"
#include "Author.h"
#include "Publisher.h"
#include <string>
#include <cstdlib>


	Book::Book(string t, Author a, Publisher b)
	{

	}




	Book (string t, Author a, Publisher b);
	void setTitle(string t);
	string getTitle();
	void setNumPages(int n);
	int getNumPages();
	void setEdition(string e);
	string getEdition();
	void setCopyrightYear(int c);
	int getCopyrightYear();

	void getInfo(Author &);
	void getInfo(Publisher &);
	Author getInfo(Author &);
	Publisher getInfo(Publisher &);



Author.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef Author_H
#define Author_H
#include <string>
using namespace std;

class Author
{
private:
	string name;
	int numWritten;
public:
	Author(string);
	string getName();
	void setBooksWritten(int b);
	int getBooksWritten();
	friend void Book::addInfo(Author &);
	friend Author Book::getInfo(Author &);

};
#endif 



Author.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "Author.h"
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

	Author::Author(string n)
	{
		name = n;
	}

	string Author::getName()
	{
		return name;
	}

	void Author::setBooksWritten(int num)
	{
		numWritten = num;
	}

	int Author::getBooksWritten()
	{
		return numWritten;
	}

	friend void Book::info(string, numWritten)



Publisher.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef Publisher_H
#define Publisher_H
#include <string>
using namespace std;

class Publisher
{
private:
	string name;
	string address;
	int phoneNum;
public:
	Publisher(string n);
	string getName();
	void setAddress(string a);
	void setPhone(int p);
	string getAddress();
	int getPhone();
	friend void Book::addInfo(Publisher &);
	friend Publisher Book::getInfo(Publisher &);
}


#endif 



Publisher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "Publisher.h"
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

	Publisher::Publisher(string n)
	{
		name = n;
	}

	string Publisher::getName()
	{
		return name;
	}

	void Publisher::setAddress(string a)
	{
		address = a;
	}

	void Publisher::setPhone(int p)
		{
			phoneNum = p;
		}
	string Publisher::getAddress()
		{
			return address;
		}

	int Publisher::getPhone()
		{
			return phoneNum;
		}
Topic archived. No new replies allowed.