This is a homework assignment. I say this because i dont want someone to do it for me. However, i want to learn and at this point i am not learning anything. This is our first assignment in data structures.
Any help in easy to understand language would be great..
we were given this skeleton program to finish it.
please forgive me if the formatting is bad. Its how it paste in here.
Code:
int main()
{
char mytry;
list *wineries = new list();
winery *wPtr;
cout << "\nCS260 - Lab1 - " << endl << endl;
wineries->insert(winery("Lopez Island Vinyard", "San Juan Islands", 7, 95));
wineries->insert(winery("Gallo", "Napa Valley", 200, 25));
wineries->insert(winery("Cooper Mountain", "Willamette Valley", 100, 47));
wineries->insert(winery("Duck Pond Cellars", "Willamette Valley", 845, 70));
Code:
#ifndef _LIST_
#define _LIST_
#include <ostream>
#include "winery.h"
using namespace std;
//const int SIZE = 100;
class list
{
public:
list(void); // constructor
virtual ~list(void); // destructor
void displayByName(ostream& out) const;
void displayByRating(ostream& out) const;
void insert(const winery& winery);
winery * const find(const char * const name) const;
bool remove(const char * const name);
private:
struct node
{
node(const winery& winery); // constructor
winery item;
node * nextByName;
node * nextByRating;
};
node * headByName;
node * headByRating;
};
#endif // _LIST_
in the insert function it wont let me create memory for a link list
node * newNode = new node;
i get this error:
error C2512: 'list::node' : no appropriate default constructor available
so i make a class function:
Code:
list::node::node(const winery &winery)
{
item = winery;
nextByName = NULL;
nextByRating = NULL;
}
and i still get the same error, however i get another one..
'winery' : no appropriate default constructor available
Code:
#include "list.h"
#include "winery.h"
list::list()
{
int acres = 0;
int rating = 0;
}
list::~list()
{
}
void list::displayByName(ostream& out) const
{
}
void list::displayByRating(ostream& out) const
{
// your code here
}
void list::insert(const winery& winery)
{
//node * newNode = new node;
node * prev = NULL;
node * curr = headByName;
node *newNode = new node(winery);
//traverse to find the position to insert
//while (curr!=NULL && curr->item < winery)
//{
// prev = curr;
// curr = curr->next;
//}
//the data already exists
//if(curr && curr->item == winery)
// return false;
//insert the data here
// else
//{
//create new node to contain the data
// node * newNode = new node;
// newNode->item = winery;
// newNode->nextByName = NULL;
// link the newNode into the linked list
// newNode->nextByName = curr;
//if(prev == NULL)
// headByName = newNode;
// else
// prev->nextByName = newNode;
}
}
winery * const list::find(const char * const name) const
{
// your code here, return the appropriate value
return 0;
}
bool list::remove (const char * const name)
{
// your code here, return the appropriate value
return false;
}
Code:
#include "winery.h"
using namespace std;
winery::winery(const char * const name, const char * const location, const int acres, const int rating)
: name( new char[strlen(name)+1] ), location( new char[strlen(location)+1] ),acres(0),rating(0)
{
strcpy_s( this->name, 200, name );
strcpy_s( this->location, 200, location );
this->acres = acres;
this->rating = rating;
}
winery::~winery()
{
if(name)
delete[] name;
if(location)
delete[] location;
}
const char * const winery::getName() const
{
//strcpy(name, this->name);
return name;
}
const char * const winery::getLocation() const
{
// your code here, return the appropriate value
return location;
}
const int winery::getAcres() const
{
return acres;
}
const int winery::getRating() const
{
return rating;
}
void winery::displayHeadings(ostream& out)
{
// your code here
}
ostream& operator<<(ostream& out, winery *w)
{
// your code here
return out;
}
I hope how i laid this out its not too confusing..