有人可以帮助我上这门课吗?
Can someone help me with this class?
为了确保每个人都能理解我的问题,我将在这里发布整个问题。
在编程示例选举结果中,对象候选列表 的类型 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;
- 需要帮助设置在C++中使用的Potrace
- 在指针的帮助下,文本文件中单词的频率
- 计算每个节点的树高,帮助我解释这个代码解决方案
- 如何在Qbutton的帮助下更改Q对话框的宽度
- 需要帮助将结构数组传递给函数
- C++需要帮助从用户那里获得一个整数,并确保它在另外两个整数之间
- 需要帮助在 c++ 中将字符串转换为字符 ----错误 "const char *" 类型的值不能用于初始化 "char" 类型的实体
- 有人可以帮助我处理正则表达式吗?
- C++调用具有 *this 属性的单个帮助程序函数
- C++:需要帮助了解运算符重载错误
- 需要以下代码的帮助,下面的代码有什么问题
- CS1 项目帮助C++
- 用于检查值是否为其任何参数的帮助程序函数
- 需要有关此 if 语句的帮助
- 类型限定宏帮助程序
- CoreCLR 中的检测探查器 - 将帮助程序程序集加载到 dotnet 进程的方法
- NS3 插槽混淆(需要帮助理解)
- 设计帮助 - 为不同类型的消息处理通用接口的设计模式
- 需要帮助查找内存泄漏
- 有人可以帮助我理解这些参数/参数吗?