数组排序功能需要帮助请 [英] Array Sorting function Need Help Please

查看:59
本文介绍了数组排序功能需要帮助请的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入文本文件:

input text file:

<br />
Lincoln 120 300 400<br />
Parks 100 500 250<br />
Shakespeare 0 30 50<br />
Ghandi 250 100 40<br />
Ashe 300 50 175<br />
Rodriguez 87 118 320<br />
Curie 284 0 112<br />



进入此功能



goes into this function

<br />
void displayResults(int list[][COL_SIZE],string nameList[])<br />
{<br />
<br />
	// this will be a function to calcualte percentage of all the calculations<br />
	double percenttotal = 0;<br />
	int num = 0,votenum = 0;<br />
	double perc = 0;<br />
	string n;<br />
	cout << "Results in sorted order" << endl;<br />
	cout << "Name            Votes % Total  " << endl;<br />
	cout << "-----------     ------  ------" << endl;<br />
	for (int c = 0; c < COL_SIZE;c++)<br />
	{<br />
		cout << nameList[c] << ''\t'' << ''\t'';<br />
		votenum = 0;<br />
		//this will display the names to the left <br />
		for (int r = 0; r < ROW_SIZE - 1; r++)<br />
		{<br />
			//this adds the precinct to the right ROW totals<br />
			votenum = votenum + list[r][c];<br />
		}<br />
		percenttotal = votenum / 100.0;<br />
		cout << votenum <<"\t"<< percenttotal <<"%"<< endl;<br />
	}<br />
	cout << "----------------------------------------------" << endl;<br />
}



这应该是输出:



and this should be the OutPut:

<br />
Results in sorted order<br />
Name               Votes % of Total<br />
-----------        ----- ----------<br />
Parks               850    23.7%<br />
Lincoln             820    22.9%<br />
Ashe                525    14.6%<br />
Rodriguez           525    14.6%<br />
Curie               396    11.0%<br />
Ghandi              390    10.9%<br />
Shakespeare          80     2.2%<br />



但是我也不知道如何对名称进行排序并将其链接到数组中已经按降序排序的总数中.



But its not i have no idea how to sort the names and link them to the totals that are already sorted in descending order in the array

推荐答案

您的目标很简单地实现了如果您在同一函数中同时对结果数组(即list)和名称一(nameList)进行排序.
更好的设计可以将名称和结果绑定到一个结构(或类)中.
:)
Your goal is simply accomplished if you sort both the results array (i.e. list) and the names one (nameList) in the same function.
A better design would tie name and results together in a struct (or class).
:)


我在编程课上并不怎么知道
我问了我的老师,他告诉我要问我是否有问题的大声笑
I am not that far in my programming class to know how to do that
i asked my teacher and he told me to ask the web forums if i had questions lol


这篇关于数组排序功能需要帮助请的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆