Я пытаюсь установить посещаемость студентов на основе ввода пользователем. Там, где я запускаю его, проблема пытается принять этот вход и назначить его моим данным для каждого учащегося.Установка данных одного класса из другого класса
Все данные, которые у меня есть, считываются из файла в отдельный список. Структура этого типа данных объявлена в моем узле.h.
Так что я спрашиваю, как изменить значения, которые происходят из класса Node, в моем классе меню?
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 ©Object)
{
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;
}
list.h
#include "Node.h"
#ifndef LinkedList_H
#define LinkedList_H
using std::ostream;
class List
{
friend ostream & operator << (ostream &lhs, List &rhs);
friend ListNode;
public:
List();
List (List ©Object);
~List();
List & operator = (List &rhs);
ListNode *makeNode (data newNode);
bool insertOrder (data Node);
bool deleteNode (data Node);
data getDataL();
ListNode *nextPtr();
void setAtt(int atten);
private:
ListNode *pHead;
};
#endif
ListNode.h
#ifndef ListNode_H
#define ListNode_H
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
struct data
{
char record[8];
char ID[12];
char name[30];
char email[30];
char units[6];
char major[8];
char grade[14];
int absent;
char dateabsent[32];
};
class List;
class ListNode
{
friend class List;
friend struct data;
public:
ListNode();
ListNode(data newData);
//ListNode(char newrecord[], string newID, string newname, string newemail, string newunits, string newmajor, string newgrade);
ListNode(ListNode ©Object);
~ListNode();
data getData() const;
ListNode *getNextPtr() const;
ListNode & operator = (ListNode &rhs);
private:
data mData;
ListNode *mpNext;
};
#endif
Пожалуйста, разместите заголовки для 'List' и' ListNode', чтобы мы лучше знали, как работает ваша программа. Благодаря! –
@KevinChen сделано! – Montop20