Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am having difficulty getting my winery code to compile....I know it has do to

ID: 3637664 • Letter: I

Question

I am having difficulty getting my winery code to compile....I know it has do to with my list.cpp file not integrating with my list.h correctly....but I have no idea how to fix it.
Any advice would be greatly appreciated.
Thanks!
############################################################################
//driver.cpp

#include <stdlib.h>
#include <crtdbg.h>
#include "list.h"
#include <iostream>
using namespace std;

void displayMenu();
char getCommand();
void executeCmd(char command, list& aList);

//void getWinery(data & winery);
void getWinery(winery* data)
int getInt(char * prompt);
float getFloat(char * prompt);
void getString(char * prompt, char * input);

void display(const list & aList);

const int MAX_LEN = 100;

int main()
{
//use memory leak detection tool in Visual Studio .Net.
//comment it out if you are not using Visual Studio .Net
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

char command = 'a';
char fileName[] = "data.dat";
list wineries(fileName);

displayMenu();
command = getCommand();
while(command != 'q')
{
executeCmd(command, wineries);
displayMenu();
command = getCommand();
}

wineries.writeOut (fileName);
cout << " Thank you for using CWMS!" << endl << endl;
return 0;
}

void displayMenu()
{
cout << " Implemented by: Li Liang" << endl;
cout << " Welcome to CS Winery Management System! "<< endl;
cout << " a> add a winery" << endl
<< " r> remove a winery" << endl
<< " s> search for a winery" << endl
<< " l> list all the wineries" << endl
<< " q> quit the application" << endl << endl;
}

char getCommand()
{
char cmd;
cout << "Please enter your choice (a, r, s, l or q):";
cin >> cmd;
cin.ignore(100, ' ');
return tolower(cmd);
}

void executeCmd(char command, list & aList)
{
//data winery;
winery data;
char key[MAX_LEN];

switch(command)
{
case 'a': getWinery(data);
aList.insert (data);
cout << endl << "the winery has been saved in the database. " << endl;
break;
case 'r': getString(" Please enter the name of the winery you want to remove: ", key);
aList.remove(key);
cout << endl << key << " has been removed from the database. " << endl;
break;
case 's': getString(" Please enter the name of the winery you want to search: ", key);
//aList.retrieve (key, winery);
aList.retrieve (key, data);
//cout << endl << "Information about " << key << ": " << endl << ' ' << winery << endl;
cout << endl << "Information about " << key << ": " << endl << ' ' << data << endl;
break;
case 'l': display(aList);
break;
default: cout << "illegal command!" << endl;
break;
}
}

void display(const list & aList)
{
char choice;

cout << " n: list ordered by name" << endl
<< " r: list ordered by rating" << endl << endl;

choice = getCommand();
switch (choice)
{
case 'n': aList.displayByName (cout);
break;
case 'r': aList.displayByRating (cout);
break;
default:
cout << "illegal command!" << endl;
break;
}
}

//void getWinery(data & winery)
void getWinery(winery& data)
{
char name[MAX_LEN];
char loc[MAX_LEN];
int yr;
float acres;
float rat;

cout << " Please enter information about the winery: " << endl;
getString(" name: ", name);
getString(" location: ", loc);
yr = getInt(" year: ");
acres = getFloat(" acres: ");
rat = getFloat(" rating: ");

data.setAcres (acres);
data.setLoc (loc);
data.setName (name);
data.setRat (rat);
data.setYr (yr);
}
int getInt(char * prompt)
{
int temp;
cout << prompt;
cin >> temp;
while(!cin)
{
cin.clear ();
cin.ignore(100, ' ');
cout << "Illegal input -- try again: ";
cin >> temp;
}
cin.ignore(100, ' ');
return temp;
}
float getFloat(char * prompt)
{
float temp;
cout << prompt;
cin >> temp;
while(!cin)
{
cin.clear ();
cin.ignore(100, ' ');
cout << "Illegal input -- try again: ";
cin >> temp;
}
cin.ignore(100, ' ');
return temp;
}
void getString(char * prompt, char * input)
{
cout << prompt;
cin.get(input, MAX_LEN, ' ');
cin.ignore (100, ' ');
}
###########################################################################
//winery.cpp

#include <iostream>
#include <iomanip>
#include "winery.h"

using namespace std;

winery::winery()
{
strcpy_s(name, "");
strcpy_s(loc, "");
acres = 0;
rat = 0;
yr = 0;
}

winery::winery(const winery& winery_)
{
strcpy_s(name, winery_.name);
strcpy_s(loc, winery_.loc);
acres = winery_.acres);
rat = winery_.rat;
yr = winery_.yr;
}

winery::winery(const char * const name_, const char * const loc_, const int acres_, const int rat_, const int yr_) :
acres(acres_),
rat(rat_),
yr(yr_)
{
strcpy_s(name, name_);
strcpy_s(loc, loc_);
}

winery::winery::~winery()
{
}

const char * const winery::getName() const
{
return name;
}

const char * const winery::getLoc() const
{
return loc;
}

const int winery::getAcres() const
{
return acres;
}

const int winery::getRat() const
{
return rat;
}

const int winery::getYr() const
{
return yr;
}

void winery::setName(const char* name_) // Copy the name from the parameter variable to the member veriable. name = (char*)name_;
{
strcpy(name, name_);
}

void winery::setLoc(const char* loc_) // copy the location from the parameter variable to the member vaiable. location = (char*)location_;
{
strcpy(loc, loc_);
}

void winery::setAcres(const int& acresIn) //set acres equal to the passed in value
{
acres = acresIn;
}

void winery::setRat(const int& ratIn) // set rating equal to the value passed in
{
rat = ratIn;
}

void winery::setYr(const int& yrIn) // set the year of the winery equal to the value passed in
{
yr = yrIn;
}

void winery::displayHeadings(ostream& out)
{
out << setw(24) << left
<< "Name"
<< setw(22) << left
<< "Location"
<< setw(7) << left
<< "Acres"
<< setw (8) << left
<< "Year"
<< setw(3) << left
<< "Rating" << endl;

out << setw(24) << left
<<"----"
<< setw(22) << left
<< "-------"
<< setw(7) << left
<< "-----"
<< setw(8) << left
<<"----"
<< setw(3) << left
<< "-----" << endl;
}

ostream& operator<<(ostream& out, const winery& w)
{
out << setw (24) << left
<< w.getName()
<< setw (22) << left
<< w.getLoc()
<< setw (7) << left
<< w.getAcres()
<< setw (8) << left
<< w.getYr() << left
<< setw (3) << left
<< w.getRat() << endl;
return out;
}
###########################################################################
//winery.h
#ifndef _WINERY_
#define _WINERY_

#include <ostream>

class winery
{
public:
winery(void); // default constructor
winery( const winery& winery_ ); // copy constructor
winery(const char * const name, const char * const loc, const int acres, const int rat, const int yr);
virtual ~winery(void);

const char * const getName() const; // accessor functions
const char * const getLoc() const; // accessor functions
const int getAcres() const; // accessor functions
const int getRat() const; // accessor functions
const int getYr() const; // accessor functions

void setName(const char* name_ ); // modifier functions
void setLoc(const char* loc_); // modifier functions
void setAcres(const int& acresIn); // modifier functions
void setRat( const int& ratIn); // modifier functions
void setYr(const int& yrIn); // modifier functions

//headings for winerys
//static void displayHeadings(std::ostream out);
static void winery::displayHeadings(std::ostream out);
friend std::ostream& operator<<(std::ostream& out, const winery &w);

private:
static const int MAX_LEN = 100;

char name[MAX_LEN];
char loc[MAX_LEN];
int yr;
int acres;
int rat;
};

#endif
###########################################################################
//list.h
#ifndef _LIST_
#define _LIST_

#include <iostream>
#include "winery.h"

using namespace std;

class list
{
public:
list(void); // default constructor
list(const char *filename); //
virtual ~list(void); // destructor
void displayByName(ostream& out) const
void displayByRat(ostream& out) const;
void insert(const winery& winery);
winery * const find(const char * const name) const;
bool remove(const char * const name);
void writeOut(const char *filename); // write out to the filename passed in
void retrieve(const char *key, winery& wineryOut); // look up the winery by its name (key)and return the data in the winery out variable

private:
static const int MAX_LEN = 100;

struct node
{
node(const winery& winery) //constructor
winery item;
node *nextByName;
node * nextByRating;
}

node * headByName;
node * headByRating;
};

#endif
###########################################################################
//list.cpp
#include <iostream>
#include "list.h"

using namespace std;


list::list()
{
headByName = 0;
headByRating = 0;
}

list::~list()
{
node *ptr = headByName;
node *temp;

while (ptr) {
temp = ptr;
ptr = temp->nextByName;
delete temp;
}

headByName = 0;
headByRating = 0;
}

list::node::node (const winery& winery) :
item (winery),
nextByName (0),
nextByRating (0)
{
}

void list::displayByName(ostream& out) const
{
node* ptr = headByName;
winery* w;

ptr->item.displayHeadings (out);
while (ptr) {
w = &ptr->item;
out << w << endl;
ptr = ptr->nextByName;
}
}

void list::displayByRat(ostream& out) const
{
node* ptr = headByRating;
node* ptr1 = headByName;
winery *w;

ptr->item.displayHeadings (out);
while (ptr) {
w = &ptr->item;
out << w << endl;
ptr = ptr->nextByRating;
}
}

void list::insert(const winery& winery)
{
node* ptr = headByName;
node* current= headByName;
node* m_address = 0;
node* previous = 0;
node* next = 0;

if (!headByName) {
headByName = new node (winery);
headByRating = headByName;
}
else {
// Sort By Name
current = headByName;
while (current){
if (strcmp (current->item.getName (), winery.getName ()) > 0) {
next = current;
break;
}
current = current->nextByName;
}
node* temp = headByName;
while (temp!= next) {
previous = temp;
temp = temp->nextByName;
}
if (!previous) {
previous = new node (winery);
previous->nextByName = next;
headByName = previous;
}
else {
previous->nextByName = new node (winery);
previous->nextByName->nextByName = next;
}

// Sort By Rating
// Getting the pointer before the target
current = headByRating;
while (current) {
if (current->item.getRating () > winery.getRating ()) {
previous = current;
next = current->nextByRating;
}
else if (current->item.getRating () < winery.getRating ()) {
node* temp = headByRating;
previous = headByRating;
while (temp != current) {
previous = temp;
next = temp->nextByRating;
temp = temp->nextByRating;
}
break;
}
else {
if (current->item.getRating () == winery.getRating ()) {
if (current->item.getAcres () > winery.getAcres ()) {
previous = headByRating;
node* temp = headByRating;
while (temp != current) {
previous = temp;
next = temp->nextByRating;
temp = temp->nextByRating;
}
break;
}
else {
previous = current;
next = current->nextByRating;
}
}
}
current = current->nextByRating;
}

// Obtain memory address of the target
current = headByName;
while (current){
if (current->item.getName () == winery.getName ())
m_address = current;
current = current->nextByName;
}

// Insert target into ordered list
if (previous == headByRating) {
if (previous->item.getRating () < winery.getRating ()) {
headByRating = m_address;
headByRating->nextByRating = previous;
}
else if (previous->item.getRating () == winery.getRating ()) {
if (previous->item.getAcres () > winery.getAcres ()) {
headByRating = m_address;
headByRating->nextByRating = previous;
}
else {
previous->nextByRating = m_address;
previous->nextByRating->nextByRating = next;
}
}
else
{
previous->nextByRating = m_address;
previous->nextByRating->nextByRating = next;
}
}
else {
previous->nextByRating = m_address;
previous->nextByRating->nextByRating = next;
}
}
}

winery * const list::find(const char * const name) const
{
node* ptr = headByName;

while (ptr) {
if (ptr->item.getName () == name)
return &(ptr->item);
ptr = ptr->nextByName;
}
return 0;
}

bool list::remove (const char * const name)
{
node* ptr = headByName;

while (ptr) {
if (ptr->item.getName () == name) {
node* temp = headByName;
node* previous = headByName;
node* next = 0;

// Link node by Name
while (temp != ptr) {
previous = temp;
temp = temp->nextByName;
}

if (previous == headByName)
headByName = previous->nextByName;
else {
next = ptr->nextByName;
previous->nextByName = next;
}

// Link node by rating
temp = headByRating;
previous = headByRating;
while (temp != ptr) {
previous =temp;
temp = temp->nextByRating;
}

if (previous == headByRating)
headByRating = previous->nextByRating;
else {
next = ptr->nextByRating;
previous->nextByRating = next;
}

delete ptr;
return true;
}
ptr = ptr->nextByName;
}
return false;
}

Explanation / Answer

main() { open_port(); } int open_port(void) { int fd; /* File descriptor for the port */ int res; char buf[255]; fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { /* * Could not open the port. */ perror("open_port: Unable to open /dev/ttyS0 - "); } else fcntl(fd, F_SETFL, 0); /* fcntl(fd, F_SETFL, FNDELAY); */ res = read(fd,buf,255); printf("res=%d ",res); buf[res]=0; /* set end of string, so we can printf */ printf(":%s:%d ", buf, res); return (fd); }