Help with Linked list functions....overloaded stream op and get and set functions C++ -


hey everyone, i'm kind of stuck right now, need overloading stream op in these classes. need access data in linked list creating, in throwmudat() function need find distance not know how call individual variables of node. (each node has x , y , need find distance between given node , point (x,y) passed it. thanks! missing point me in right direction please.

class linknode {   friend class schmoolist;  public:   linknode(){next=0; data =0;}   ~linknode(){if (data){delete data; data =0;}}   private:   linknode *next; //"sro"   schmoo *data;  }; #endif 

class schmoolist {  public:   schmoolist(){first=0;}   // ~schmoolist();   bool isempty(){return first==null;}   void insertfront(schmoo*);   void throwmudat(double, double);//throws mud @ given (x,y) , adds 1                              //to mud value of schmoo within 5.0 feet of given                              //within 5.0 means distance <= 5.0   void removeat(double, double); //removes schmoo within 1.0 feet   int getpopulation();   void printall();//send each schmoo stdout 1 per line in list order    private:   linknode *first;   }; #endif 

using namespace std;  void schmoolist::insertfront(schmoo *nt){   linknode *temp= new linknode();   temp -> data=nt;   temp->next=first;   first = temp;  } void schmoolist::throwmudat(double xx, double yy){   linknode *temp=first;   while(temp){     double sum = (pow(xx - temp->data.getx(), 2))+(pow(yy - temp->data.getx(), 2));     double distance = sgrt(sum);  }  /*void schmoolist::removeat(double x, double y){    linknode *temp=first       while(temp){        double xd=        double yd= temp - y;         if(xd <= 1 || yd <= 1){          temp == 0;  */  int schmoolist::getpopulation(){   int pop=0;   linknode *temp=first;   while(temp){     pop++;     temp=temp->next;   }   return pop;  }  void schmoolist::printall(){    linknode *temp=first;   while(temp){     cout << '*' << endl;      //print object      temp = temp->next;   }   cout << getpopulation();//for testing } 

class schmoo{    public:   schmoo(double, double);   void setx(double);   double getx() const;   void sety(double);   double gety() const;   void setmud(int);   int getmud() const;    private:   double x;   double y;   int mud;  }; #endif 

schmoo::schmoo(double xx, double yy){   x = xx;   y = yy;   setmud(0);  }   void schmoo::setx(double x1){   x = ( x1 >= -1000 && x1 <= 1000) ? x1 : 0;  } double schmoo::getx() const{   return x;  } void schmoo::setmud(int m){   mud = ( m >= -1000 && m <= 1000) ? m : 0; } int schmoo::getmud() const{   return mud; } /*ostream &operator<<(ostream &os, schmoo &s){   if(s->getmud() == 1){     os << "schmoo @ (" << s.x << ", " << s.y << ") hit mud " << mud << "time.";   }   os << "schmoo @ (" << s.x << ", " << s.y << ") hit mud" << mud << "times.";   return os; } */ 

you forgot go forward in list.

  void schmoolist::throwmudat(double xx, double yy){       linknode *temp=first;       while(temp){         double sum = (pow(xx - temp->data.getx(), 2))+(pow(yy - temp->data.getx(), 2));         double distance = sqrt(sum);         temp = temp->next;     } 

Comments