dusktreader 137 Posting Whiz in Training

i guess all you need is to place each input in an array and then do a bubble sort on that array, then output the first and last values.

There are two huge problems with your approach. First, your solution is doing way more than is necessary. If I was a professor giving this assignment, and you implemented your proposed solution, I would give you B even if the program worked flawlessly. You need to solve the problem without adding extra complexity. If all you need to do is find the min and max values, why would you sort?

Secondly, you are suggesting a bubble sort! Bubble sort is among the most inefficient of sorting methods. It's time complexity is O(n^2). Finding the max and min of a problem set is only O(n). So, basically, your solution would require however much time it would take to simply pass over the loop squared. That is a huge waste of time! Imagine you had a file with 1 billion integer entries. Do you really want to use a bubble sort on this list? Do you really want to save this list in memory?

I didn't mean to go on the offensive so much, but you need to understand the magnitude of such an error. Computer Scientists search for the simplest and most efficient correct solution. The solution you are suggesting is correct, in a way. However, it terribly inefficient and tremendously over complicated.

john jr commented: Find the maximum number of entries in the three-digit number, javacipt and html +0
dusktreader 137 Posting Whiz in Training

google "c++ srand"

dusktreader 137 Posting Whiz in Training

Here's a compileable solution. It will grade a test of any length with any sort of single letters as answers. It should be somewhat fault tolerant, though I'll leave it to you to add in extra protection. Hope this helps:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

double gradeTest( const string& key, const string& studentTest ){
    double score = 0.0;
    for( unsigned int i=0; i<key.size(); i++ )
        score += key[i] == studentTest[i];
    score /= key.size();
    return score;
}

bool readTest( const string& fileName, string& answers ){
    char answer;
    ifstream fin( fileName.c_str() );
    if( !fin.good() )
        return false;
    fin >> answer;
    while( !fin.eof() ){
        answers.push_back( answer );
        fin >> answer;
    }
    return true;
}

int main()
{
    string key, test0;
    readTest( "key.txt", key );
    readTest( "test0.txt", test0 );
    double grade = gradeTest( key, test0 );
    cout << "grade: " << grade << endl;
    return 0;
}
WaltP commented: DT, PLEASE stop doing homework for others. Give them code that POINTS to an answer, not THE answer -2