Guten Morgen Community,
Die Methode void enqueue(prod p) -> soll eine neue Instanz "Elem" mit p als letztes Element an die Liste hängen.
Ich versteh es einfach gerade nicht, ist die Verkettung an sich richtig?
In welcher Form benötige ich den Standard Konstruktor von "Elem" um
ohne Fehler zum laufen zu bekommen.
Die Methode void enqueue(prod p) -> soll eine neue Instanz "Elem" mit p als letztes Element an die Liste hängen.
Ich versteh es einfach gerade nicht, ist die Verkettung an sich richtig?
In welcher Form benötige ich den Standard Konstruktor von "Elem" um
Code:
Elem *first = new Elem;
Code:
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <iomanip>
#include <string>
#define N 3
using namespace std ;
class prod
{
private:
string pn;
double preis;
unsigned long anz ;
public:
prod(string,double,unsigned long);
~prod();
void ein();
void out();
string getPN() {return pn;}
double getPreis() {return preis;}
unsigned long getAnz() {return anz;}
void setPN(string pn) {pn = pn ;}
void setPreis(double preis) {preis = preis;}
void setAnz (unsigned long anz) {anz = anz;}
};
prod::prod(string pn="",double preis=0.0, unsigned long anz=0ul):pn(pn),preis(preis),anz(anz)
{
cout<<"Produktname: "<<pn<<endl;
cout<<"Preis: "<<preis<<endl;
cout<<"Anzahl: "<<anz<<endl;
}
void prod::out()
{
cout<<"Produktname: "<<pn<<endl;
cout<<"Preis: "<<preis<<endl;
cout<<"Anzahl: "<<anz<<endl;
}
prod::~prod()
{
cout<<"Produktname: "<<pn<<endl;
cout<<"Preis: "<<preis<< endl;
cout<<"Anzahl: "<<anz<<endl;
}
void prod::ein()
{
cout<<"Eingabe Produktname: ";
cin>>pn;
cin.clear();cin.ignore(INT_MAX,'\n');
cout<<"Eingabe Preis: ";
cin>>preis;
cin.clear();cin.ignore(INT_MAX,'\n');
cout<<"Eingabe Anzahl : ";
cin>>anz;
cin.clear();cin.ignore(INT_MAX,'\n');
}
class Queue
{
public:
//#### Innere klasse Elem ####
class Elem
{
public:
prod p;
Elem *next;
Elem(prod p(prod), Elem *next=0){}
};
Queue(Elem *first=0,Elem *last=0){} //Konstruktor
void enqueue(prod p)
{
Elem *first = new Elem;
first->p = p.ein();
first->next=last;
last=first;
}
private:
Elem *first;
Elem *last;
};
int main()
{
system("PAUSE");
return 0;
}