English 中文(简体)
根据另一个Array的内容将三射线投向一个档案
原标题:Outputting Three Arrays to a File Based on the Contents of Another Array

我有一阵列,追踪三个平行阵列的调查结果。 平行阵列是名称、id#和余额。 姓名与补贴和平衡有关,因为它们都有相同的指数。 用户查询姓名和节目应将搜索结果输出到有名称、背书和平衡的文本档案中。 因此,现在每当搜索成功时(名字出现在阵列),我就把该名字的索引添加到称为成果的阵列中。 与此类似:

while(searchTerm != "done")
{
    searchResult = SearchArray(searchTerm, AR_SIZE, namesAr);

    if(searchResult == -1)
    {
        cout << searchTerm << " was not found.
";
    }
    else
    {
        cout << "Found.
";
        resultsAr[index] = searchResult;
        index++;
    }

    cout << "
Who do you want to search for (enter done to exit)? ";
    getline (cin,searchTerm);

} // End while loop

我可以说明如何做到这一点,但只有产出所找到的名字。 我现在就这样做了:

outFile << fixed << setprecision(2) << left;
outFile << setw (12) << "Id#" << setw(22) << "Name" << "Balance Due"
        << endl << endl;

for(index = 0; index < sizes; index++)
{
    outFile << left << setw (10) << idsAr[index] << setw(22) << namesAr[index] 
            << setw(3) << "$";
    outFile << right << setw(10) << balancesAr[index] << endl;
}

但显然,这只是整个阵列。 我可以做些什么,只会产生结果。 Ar.

Thanks, and this is homework, so no exact answers, that would be just terrible.

EDIT:资本化问题确实是一个问题,我只是偶然地在我这里上台时,对此表示怀疑。 成果 一部分人正在工作,因为在搜索阵列的内容之后,是我所搜寻名字的索引。 “搜索卫星”功能类似:

int SearchArray(string searchTerm,
             int size,
             string namesAr[])  
{  
// Variables  
int index;  
bool found;  

// Initialize
index = 0;
found = false;

while(index < size && !found)
{
    if(namesAr[index] == searchTerm)
    {
        found = true;
    }
    else
    {
        index++;
    }
}

if(found)
{
    return index;
}
else
{
    return -1;
}
}
最佳回答

My pleasure. Now i see what you are doing. What you have to do is use another indirection. You want to output the result only for those indices which are stored in resultsAr.
Change your for-loop to something similar to this:

int numFound = index;
for(index = 0; index < numFound; index++) {
    cout << left << "   "<<idsAr[resultsAr[index]];
}

这意味着,首先将你发现的指数(高于此指数)储存在“核心”。 之后,只有超过0 .numFound-1,在获取该要素时采用双重间接法;这意味着看结果。 包括索引编制,然后使用该指数查找实际数据。

问题回答

您的搜索阿雷拉(Array)是否恢复第一个指数,在一系列点子里找到了一种相匹配的插图以加以扼杀? 然后将其储存在只有一进入的阵列中? 即便如此,你所储存的成分是从未界定的“民主化”(资本化)。

- 设计; 请张贴完整的源码(包括搜索雷达)。

EDIT:

Ok, thanks for posting SearchArray(), but we still need more, in the first box you write:

resultsAr[index] = searchResult;

......但没有给我们一个 lo。 而且,如果你想找到与“研究术语”相对应的多份名字,那么你必须写“搜索”书,要么返回一系列指标,要么接受开端指数,要么多次回来。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签