I have looked at classes and kinda get some what of it well and I have looked at the class tutorial but still confused but its the linear linked list that I am confused about because I have a huge assignment to do and not sure where to start..
But to sum up my program assignment I need to create a program that keeps track of of wineries profit. More specifically keep track of name, location, number of acres, and success rating. All the directions are below for this assignment and need major help its due soon really want to do well. I have been given the files from our teacher and I will post it below with a comments annd its alot of files but I will post them below. any major help will be awesome
CS260 Lab 1
Instructions
You have noticed a large number of wineries appearing around the country side, and you are interested in finding out how profitable they are becoming. You have decided to write a program to begin tracking their progress. You want to keep track of at least:
the name of the winery
the general location (e.g. in Banks)
the number of acres of vineyards associated with the winery
overall success rating
You have decided to create a linear linked list of this information, sorted by the winery's name. But, since you are interested in determining how successful they are, you also want the information organized by rating (from best to worst!). Therefore, you have decided to create a doubly threaded linear linked list. Unlike what we did in CS162, every node will have two pointers (one is a next pointer sorted by name, and another is a next pointer for the rating).
In other words, you will have only one set of nodes, with two threads going through those nodes. One thread goes through them by name, the other goes through them by rating.
Do not make two separate lists (i.e. two separate sets of nodes), one ordered by name and the other by rating. Doing this will result in a serious loss of points.
Implementation Requirements
Create a Winery class to model the winery object.
Make sure you encapsulate the the data, i.e. put data members in the private section of the class.
Use char * to model strings instead of string.
Create a List class to manage the wineries. The List class needs to be implemented using a “doubly threaded” linear linked list:
struct Node
{
Node(const Winery& winery); // constructor
Winery item;
Node *nextByName;
Node *nextByRating;
};
class List
{
...
private:
Node *headByName;
Node *headByRating;
};
The List class needs to provide operations to:
add a winery
remove a winery
display all the wineries sorted by their ratings
display all the wineries sorted by their names
search for a winery by name
Strings
For storing and printing strings, you should use C strings. Your code should #include <cstring> and use the functions defined in that header, such as:
int strlen(char *str)
// given a string pointer, returns the length of that string,
// which does not include the terminating '\0' character
void strcpy(char *dst, char *src)
// copies the characters in src to dst,
// including the terminating '\0' character
Using strcpy will cause a compiler warning. You will need to get rid of this warning by adding one of the following as the first line of .cpp files that use strcpy:
Your code’s printed output should be identical to the contents of lab1output.txt, a file that’s provided as part of this lab. “Identical” means the Linux utility diff will find no differences between your code’s output and lab1output.txt, when called with flags: -w -B. This means that the sequence of non-whitespace characters in your output has to be identical, but that differences in whitespace will be ignored. You are still required to produce output that lines up with itself properly, as lab1output.txt does.
Memory Leaks
Your code is required to run in Microsoft Visual C++ 2010 Express without memory leaks. The starter code for this project includes support for memory leak detection in VC++ 2010.
Initialization Lists
The constructors in your code should use initialization lists to the maximum extent possible. Points will be deducted where this is not done.
Here is a class definition:
class SomeClass
{
...
private:
int dataMember1;
int dataMember2;
}
Here is a constructor for this class that does not use initialization lists:
SomeClass::SomeClass(int dataMember1, int dataMember2)
{
this->dataMember1 = dataMember1;
this->dataMember2 = dataMember2;
}
And here is one that does use initialization lists:
SomeClass::SomeClass(int dataMember1, int dataMember2) :
dataMember1(dataMember1),
dataMember2(dataMember2)
{
}
An initialization list consists of comma-separated items between the : and the {. Each of these items is of the form:
dataMemberName(value)
Each item sets the named data member to the value in the parentheses. In the SomeClass constructor above, each of the two initialization list items sets its data member to the constructor argument named inside the parentheses. This is weird-looking syntax, but it is standard usage in the culture of C++.
#pragma warning(disable:4996) // disable warnings about use of strcpy()
#include "memoryleakdetect.h" // this must be the first #include in each of your .cpp files
#include <iostream>
#include "winery.h"
#include "list.h"
using namespace std;
static List *wineries;
// Ask list to insert a winery into the doubly-threaded linked list.
// Note what this function does with memory, which has implications for
// how you will (and will not) be able to use the winery instance that's
// passed to wineries->insert.
static void insertWinery(char *name, char *location, int acres, int rating)
{
Winery *w;
char *nm = new char[strlen(name) + 1];
char *loc = new char[strlen(location) + 1];
strcpy(nm, name);
strcpy(loc, location);
w = new Winery(nm, loc, acres, rating);
wineries->insert(*w);
delete[] nm;
delete[] loc;
delete w;
}
// Display all wineries in the list,
// first in order by name, then in order by rating.
static void displayWineries(ostream& out)
{
out << "+++ list by name" << endl;
wineries->displayByName(out);
out << endl << "+++ list by rating" << endl;
wineries->displayByRating(out);
}
#pragma once // include this .h file file only once
#include <ostream>
#include "winery.h"
using namespace std;
class List
{
public:
List(void); // constructor
virtual ~List(void); // destructor
// Print out the wineries in alphabetical order by name,
// by calling winery's operator<< for each winery.
void displayByName(ostream& out) const;
// Print out the wineries from highest to lowest rating,
// by calling winery's operator<< for each winery.
void displayByRating(ostream& out) const;
// Insert a winery into both the names and ratings threads.
// The names thread should be in alphabetical order by name.
// The ratings thread should be in order from highest rating
// to lowest rating.
void insert(const Winery& winery);
// Return a const pointer to the winery instance it finds in
// the list, or 0 if it didn't find a winery with that name.
// Because the pointer is declared const, there is no danger
// that find's caller will be able to use the returned pointer
// to change the instance of winery.
Winery * const find(const char * const name) const;
// Remove the winery with the specified name from both the name
// thread and the ratings thread. Returns true if it found and
// removed the winery, false if it did not find the winery.
bool remove(const char * const name);
private:
// defines each node in the doubly-threaded linked list.
struct Node
{
Node(const Winery& winery); // constructor
Winery item; // an instance of winery
// (NOT a pointer to an instance)
Node *nextByName; // next node in the name thread
Node *nextByRating; // next node in the rating thread
};
Node *headByName; // first node in the name thread
Node *headByRating; // first node in the rating thread
};
#include "memoryleakdetect.h" // this must be the first #include in each of your .cpp files
#include "winery.h"
using namespace std;
// change the value of this variable to be your own name instead of "I. Forgot"
const char Winery::YOUR_NAME[] = "I. Forgot";
Winery::Winery(const char * const name, const char * const location, const int acres, const int rating)
{
// your code here, or in this constructor's initialization list
}
Winery::~Winery()
{
// your code here
}
void Winery::displayColumnHeadings(ostream& out)
{
// print out column headings for lists of wineries, as specified by lab1output.txt
}
ostream& operator<<(ostream& out, Winery *w)
{
// print out a winery, as specified by lab1output.txt
return out;
}
You really expect us to read all of that? Not only do you not post it in [code] tags, but you don't even tell us what you're having trouble with. We're not here to do your homework for you... work on it yourself and come to us when you run into an error.
Hey packet pirate no no I wasn't meaning for you guys to do the homework I just need help on understanding classes and linear linked list from your guys view for me I understand concepts when it I hear from someone who understands it rather then reading from the book it sometimes confuses me. I just put all of these information cuz that's just the directions and files for this assignment. I thought I better post all I could so I can get better input not just. answers just help. I am sorry if it seemed like that I just need a direction. Hmm a starting point could be based from the files above there's already the constructor in the .h file for winery but what I just don't know how to go about what to put in there considering the parameters that's in the winery.cop file for winery. Again I am sorry I just need help not for you to do my homework
I understand that, but what have you done to try and solve the problem yourself? Maybe if you tell us what you're having trouble understanding, exactly, we can help you better.