2016-04-22 78 views
-4

爲了確保每個人都瞭解我的問題,我會在這裏發佈整個問題。有人可以幫助我這個班嗎?

在編程實例選舉結果,類型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行。 –

回答

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

您的自定義代碼是不標準的命名空間的一部分(或至少不應該是),所以刪除命名空間前綴讀

orderedArrayListType<candidateType>::iterator it; 

,或者如果你有一個自定義命名空間,

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

嗨,感謝您的幫助,但刪除「std ::」後,仍然有錯誤。 – edwardit

相關問題