有人可以帮助我这个班吗?

问题描述:

为了确保每个人都了解我的问题,我会在这里发布整个问题。有人可以帮助我这个班吗?

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

在这个实验中,你是修改编程示例选举 结果,以简化的候选的数据的访问如下:

派生从类orderedArrayListType类candidateListType。

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. }; 

由于类candidateListType从类 orderedArrayListType导出,并且列表是类 orderedArrayListType(从类arrayListType继承)的受保护的数据成员,列表 可以直接通过访问类candidateListType的成员。

编写类别 candidateListType的成员函数的定义。使用类 candidateListType重写并运行程序。

这就是整个问题。一些帮助后,我已经与candidateListType类完成:

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; 
} 

}; 

但我仍然有问题,我的主要驱动力。我试图将candidateListType添加到我的主驱动程序,但是我一直在收到错误。 这些错误是:

1> C:\用户\ cal11.cpp(24):错误C2039: 'orderedArrayListType':不是 'STD' 的构件 1> C:\用户\ cal11 \ cal11.cpp(24):错误C2059:语法错误 : '<'

这是我的主要驱动力:

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

你们能帮我解决吗? 谢谢!

+1

欢迎来到SO。公平的信息,没有人会打扰下载文件。还要注意,如果没有缩进,你的代码是不可读的。 –

+1

如何定义'orderedArrayListType'?无论它是如何定义的,它绝对不存在于'std'命名空间中。因此错误。 – CinCout

+0

仔细看看cal11.cpp源文件的第24行。 –

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

您的自定义代码是不标准的命名空间的一部分(或至少不应该是),所以删除命名空间前缀读

orderedArrayListType<candidateType>::iterator it; 

,或者如果你有一个自定义命名空间,

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

嗨,感谢您的帮助,但删除“std ::”后,仍然有错误。 – edwardit