有人可以帮助我上这门课吗?

Can someone help me with this class?

本文关键字:帮助      更新时间:2023-10-16

为了确保每个人都能理解我的问题,我将在这里发布整个问题。

在编程示例选举结果中,对象候选列表 的类型 orderedArrayListType 声明为处理投票 数据。插入候选人数据并更新和 检索选票有些复杂。要更新 候选人的选票,我们从候选人列表中复制了每个候选人的数据 到候选类型的临时对象中,更新了 临时对象,然后将候选人的数据替换为 临时对象。这是因为数据成员的列表是一个 候选列表的受保护成员,列表的每个组件都是一个 私有数据成员。

在本实验中,您将修改编程示例选举 简化候选人数据访问的结果如下:

从类 orderedArrayListType 派生一个类候选 ListType。

 class candidateListType: public orderedArrayListType<candidateType> {
 public:
 candidateListType(); //default constructor candidateListType(int
 size); //constructor
 void processVotes(string fName, string lName, int region, int votes);
 //Function to update the number of votes for a //particular candidate
 for a particular region. //Postcondition: The name of the candidate,
 the region, //and the number of votes are passed as parameters.
 void addVotes(); //Function to find the total number of votes received
 by //each candidate.
 void printResult() const; //Function to output the voting data. };

因为类候选列表类型派生自类 orderedArrayListType,并且 list 是类的受保护数据成员 orderedArrayListType(继承自类 arrayListType), list 可由类候选项列表类型的成员直接访问。

编写类的成员函数的定义 候选列表类型。使用该类重写并运行程序 候选列表类型。

这就是整个问题所在。经过一些帮助,我已经完成了候选列表类型类:

candidateListType:
class candidateListType: public orderedArrayListType
{
public:
candidateListType(); //default constructor
candidateListType(int size); //constructor
void processVotes(string fName, string lName, int region, int votes);
//Function to update the number of votes for a
//particular candidate for a particular region.
//Postcondition: The name of the candidate, the region,
//and the number of votes are passed as parameters.
void addVotes();
//Function to find the total number of votes received by
//each candidate.
void printResult() const;
//Function to output the voting data.
orderedArrayListType<candidateType>& cList;
std::orderedArrayListType<candidateType>::iterator it;
//default constructor
candidateListType :: candidateListType(){
cList = new orderedArrayListType<candidateType>(100);
}
//constructor
candidateListType :: candidateListType(int size){
cList = new orderedArrayListType<candidateType>(size);
}
//processing votes...storing objects
candidateListType :: void processVotes(string fName, string lName, int region, int votes){
candidateType temp;
temp.setName(fName,lName);
temp.setVotes(region,votes);
it = orderedArrayListType.end();
orderedArrayListType.insert(it,temp);
}
//priting total votes data
candidateListType :: void addVotes(){
for (it=orderedArrayListType.begin(); it!=orderedArrayListType.end(); ++it){
cout<<*it.printData();
}
}
//printing results
candidateListType :: void printResult(){
candidateListType temp;
int largestVotes = 0;
int sumVotes = 0;
int winLoc = 0;
int NO_OF_CANDIDATES = orderedArrayListType.end();
for (int i = 0; i < NO_OF_CANDIDATES; i++)
{
orderedArrayListType.retrieveAt(i,temp);
temp.printData();
sumVotes += temp.getTotalVotes();
if (largestVotes < temp.getTotalVotes())
{
largestVotes = temp.getTotalVotes();
winLoc = i;
}
}
orderedArrayListType.retrieveAt(winLoc,temp);
cout << endl << endl << "Winner: ";
string firstN;
string lastN;
cout << temp.getFirstName() << " " << temp.getLastName();
cout << ", Votes Received: " << temp.getTotalVotes() << endl << endl;
cout << "Total votes polled: " << sumVotes << endl;
}
};

但我的主要司机仍然有问题。我试图将候选人列表类型放在我的主要驱动程序中,但我不断收到错误。这些错误是:

1>c:\users\cal11.cpp(24):错误 C2039:"orderedArrayListType":不是 "STD"成员 1>c:\用户\cal11\cal11.cpp(24):错误 C2059:语法错误 : '<'

这是我的主要驱动力:

http://www.mediafire.com/download/rcu864f0p1v3kbh/Main+Driver.zip

你们能帮我吗?谢谢!

std::orderedArrayListType<candidateType>::iterator it;

自定义代码不是标准命名空间的一部分(或者至少不应该是),因此请删除要读取的命名空间前缀

orderedArrayListType<candidateType>::iterator it;

或者,如果您有自定义命名空间,

your_namespace_here::orderedArrayListType<candidateType>::iterator it;