English 中文(简体)
基本方案
原标题:Basic Prog Prob [closed]
  • 时间:2011-10-06 14:00:48
  •  标签:
  • c++
Closed. This question needs to be more focused. It is not currently accepting answers.

我正试图自欺欺欺人,但这种做法问题是一个 to笑! 任何帮助都将受到高度赞赏。 我的法典和逻辑是正确的,但只有一点。

#include <iostream>
#include <fstream>

using namespace std;

void main()
{
    ifstream fin;
    int id, prev, score, scoree, high = 0, low = 0, total = 0, count = 1, counter = 0, counterr = 0;
    double avg = 0;
    fin.open("C:\Users\E\Desktop\Quizzes.dat");
fin >> prev;
fin >> score;
low = score;
high = score;
total = score;

while(!fin.eof())
{
        fin >> id;
        fin >> scoree; //Problem is that when the ID changes it still inputs a score which gets ignored

        if ( counter == counterr && counter != 0 ) //Could of used a BOOL here...
        {
            high = scoree;
            low = scoree;
            total = 0;
            count = 0;
        }

        if ( prev == id )
        {               
            if (scoree > high)
            {
                high = scoree;
            }
            if (scoree < low)
            {
                low = scoree;
            }

            total = total + scoree;
            count++;
            counter = 0;

        }
        else
        {
            total = total - (high+low);
            count = count - 2;

            avg = total / count;

            cout << "ID: " << prev << "   "  << "AVG: " << avg << endl;

            prev = id;
            counter++;
            counterr++;

        }
    }
}

书面档案只是一份有身份证号码和记分的文件。 这里的想法是,如果“ID”与“ID”一样,它就记分。 应取消最高和最低的分数,其余应为平均分数。 因此,我的逻辑是,它不管怎样都增加了所有分数,而且只有在国际发展法发生变化之后,你才把最高和最低分数从总数中减去,然后从计数中减去2分。 问题在于,当我输入身份证及其不同之处时。 它还投入一分,新补贴的首分数得到伸缩。 任何帮助都将受到高度赞赏。

最佳回答

改变

if ( prev == id )

为此:

if ( prev == id || count  == 0)

Btw:

问题回答

The way to do this is to create a map<int, vector<int> > repository and you read in the ID of the student. Once you have the ID, you append his score to the appropriate vector (repository[ID].push_back(score)).

The next step is to iterate over every item in the map (basically over every ID) and calculate the maximum and minimum positions in the array (trivial) and then iterate over it and sum everything that s not under those two positions, then divide by repository[ID].length (take care not to divide by 0!)

你们所描述的是《守则》。 当(prev !=id) 时,将不从与(v = id )部分有关的栏目中执行该代码,因此不更新high等变量。 我认为,无论<代码>prev是否平等>。 不管怎么说,有些法典是你总是想要执行的。 尤其是检查新的高分或低分数,但或许是那里的一切?





相关问题
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?

热门标签