dimanche 29 mars 2015

Setting data of one class from within another class


I am trying to set the attendance of students based on user input. Where I run it to the problem is trying to take that input and assign it to my data on each student.


All the data I have is read from a file in to a singly linked list. The struct for this data type is declared in my node.h.


So what I'm asking is how would I modify the values that originate from the Node class, within my menu class?


Menu.cpp



void Menu::chooseMenu(ifstream *input, List L1)
{
data temp;
//data plswork[12];
char holder[30];
char junk[30];
int i=1,j=1;

do{
system("cls");
cout<<"1. Import"<<endl;
cout<<"2. Load Master"<<endl;
cout<<"3. Store Master"<<endl;
cout<<"4. Mark Absence"<<endl;
cout<<"5. Generate Report"<<endl;
cout<<"6. Exit"<<endl;
cout<<""<<endl;
cin>>selection;

if(selection == 1)//import
{
while(!input->eof())
{
memset(holder,0,30);

if(i==3 && j != 1)
{
input->getline(holder,30,'"');
input->getline(holder,30,'"');
input->getline(junk,30,',');
}
else
{
input->getline(holder,30,',');
}

if(i==1)
{
strcpy(temp.record, holder);
//cout<<temp.record<<endl;
i++;
}
else if(i==2)
{
strcpy(temp.ID, holder);
//cout<<temp.ID<<endl;
i++;
}
else if(i==3)
{
strcpy(temp.name, holder);//read between quotes
//cout<<temp.name<<endl;
i++;
j=2;
}
else if(i==4)
{
strcpy(temp.email, holder);
//cout<<temp.email<<endl;
i++;
}
else if(i==5)
{
strcpy(temp.units, holder);
//cout<<temp.units<<endl;
i++;
}
else if(i==6)
{
strcpy(temp.major, holder);
//cout<<temp.major<<endl;
i++;
}
else if(i==7)
{
strcpy(temp.grade, holder);

//cout<<temp.grade<<endl;
L1.insertOrder(temp);
i=1;
}

}
}

else if(selection == 2)//load master
{

}

else if(selection == 3)//store master
{

}

else if(selection == 4)//mark absence
{
while(L1.nextPtr() != NULL)
{
char name;
cout<<"Bruce :"<<L1.getDataL().absent<<endl;
cout<<"Is "<<L1.getDataL().name<<" present? (Y/N)"<<endl;
cin>>name;
if(name == 'y' || name == 'Y')
{
L1.setAtt(L1.getDataL(),1); // This is where I try to set attendance to 0 or 1.
cout<<L1.getDataL().absent<<endl;
}
else
{
L1.setAtt(L1.getDataL(),0);
}

L1.nextPtr();
system("pause");
}
}

else if(selection == 5)//gen report
{

}

}while(selection != 6);

}


Node.cpp



#include "Node.h"

ListNode::ListNode (ListNode &copyObject)
{
this->mData = copyObject.mData;
this->mpNext = copyObject.mpNext;
}

ListNode::~ListNode ()
{
// does nothing
cout << "exiting listnode object - going out of scope" << endl;
}

ListNode * ListNode::getNextPtr () const
{
return mpNext;
}

data ListNode::getData() const
{
return mData;
}

ListNode::ListNode(data newData)
{
mData = newData;
this->mpNext = NULL;
}



Aucun commentaire:

Enregistrer un commentaire