Dr Mirna always gives True/False tests to her class. Her tests have always 10 questions. The maximum class size is 5. She needs a program that will calculate the students’ grades based on the best grade.

Grade

A will range from the best score, to the best score minus 2.

B will range from the best score minus 3, to the best score minus 5.

C will range from the best score minus 6, to the best score minus 8.

F will be anything below the best score minus 8.

Each student’s ID and test answers will be entered. The output will be each student’s ID, number of correct answers, and grade, along the single highest score for the class.

Develop a C++ program for the above problem.

· Use four one-dimensional arrays – one for the correct scores and the other three for the needed output.

· Test if a student’ ID number has been entered previously before storing it in the array: each ID number cannot appear more than one time in the array.

· Check if the answer given for each question is a value equal to 0 or 1. If it is not the case, the user must re-enter the value again.

· Use functions in writing your code.

i don't understand the question its bonus question

What part don't you understand? You're supposed to write a program that accomplishes the stated goal, and the question even tells you how to implement it. Since this is a homework/classwork question, I'm not going to do it for you, but I'll be happy to help you understand any specific problems with the question itself, or any specific problems you have with your code.

......????

......!!!!

Reread deceptikon's first sentence in the previous post. Answer that question.

int readMarks (int ID [5], INT TAB[5])
{
int i, idnum,mark;
boolean stop=false;
i=0;
while(stop==false&&i<5)
{
Cout<<”enter an ID number to stop give negative value”<<endl;
Cin>>idnum;
If (idnum<0)
Stop=true;
Else
{
Do
{
Cout<<”enter number of correct answers”<<endl;
Cin>>mark;
}
While(mark<0||10);
ID [i]=idnum;
TAB[i]=mark;
I=i+1;
}
If (int grade)
{
Int highest - 2
Cout<<”the grade is A”<<wndl;
Cin>>mark;
Else
Int highest - 2
Cout<<”the grade is B”<<wndl;
Cin>>mark;
Else
Int highest - 5
Cout<<”the grade is C”<<wndl;
Cin>>mark;
Else
Int highest - 8
Cout<<”the grade is F”<<wndl;
Cin>>mark;
}
}
System(“pause”);
}

i tried it as you said to do and then you will help. therefore i only have this idea of solving it. i dont know how to make it so plz help

i have to give this assigment tomrw. so u can help in making the program?

We can help you debug the program, certainly. We won't 'help' you by doing it for you.

The code as given is far from a working program; the most obvious problem with is the inconsistent use of capitalization, which in a case-sensitive language is an error. That is to say, the identifier cin is not the same as Cin, which is not the same as CIN or CiN or CIn. This is especially important with keywords in the language such as int, none of which should ever be capitalized.

As an aside, it is generally not a good idea to write code in a conventional word processor such as MS Word; they not only use a file format that is significantly different from the plain ASCII that the compiler needs, they tend to use some non-standard character such as the so-called 'smart quotes', which will not be recognized by the compiler.

Furthermore, your code isn't formatted. While this won't prevent the code from working, it will make it damn-near unreadable to the majority of C++ programmers. Thus, to fix these issues, you would want to re-write you code thusly:

int readMarks (int ID [5], int TAB[5])
{
    int i, idnum, mark;
    bool stop=false;
    i=0;
    while(!stop && i < 5)
    {
        cout << "enter an ID number to stop give negative value"<<endl;
        cin  >> idnum;
        if (idnum<0)
            stop=true;
        else
        {
            do
            {
                cout<<"enter number of correct answers"<<endl;
                cin>>mark;
            } 
            while(mark<0||10);
            ID [i]=idnum;
            TAB[i]=mark;
            i++;
        }
        if (int grade)
        {
            int highest = 2;
            cout<<"the grade is A"<<endl;
            cin>>mark;
        }
        else
        {
            int highest = 2;
            cout<<"the grade is B" << endl;
            cin>>mark;
        }
        else
        {
            int highest = 5; 
            cout<<"the grade is C" << endl;
            cin>>mark;
        } 
        else
        {
            int highest = 8;
            cout<<"the grade is F" << endl;
            cin>>mark;
        }    
    }
    system(“pause”);
}

Note that I've only corrected the most outstanding syntax errors; the majority of the problems with the code aren't fixed, as it isn't entirely clear how the function is meant to work.

Edited 4 Years Ago by Schol-R-LEA

A will range from the best score, to the best score minus 2.

how can we write this code?

how can i know which is the best score at first to say that the grade is A

I probably shouldn't do this, but I feel you could benefit from having some guidance in how to write this program effectively. Therefore, I'll provide you with a pair of functions which should help you in finishing the coding:

int getScores(int* student_ids, int* scores, int max_students)
{
    int id, score, head_count;
    bool duplicate = false;

    for (head_count = 0; head_count < max_students; head_count++)
    {
        do
        {
            duplicate = false;
            cout << "Enter a Student ID number (or zero to finish): ";
            cin >> id;
            cin.ignore();

            if (isDuplicate(student_ids, head_count, id))
            {
                duplicate = true;
                cout << "You cannot have duplicate Student IDs" << endl;
            }
        } while (duplicate);


        if (!id)    // student ID == 0
        {
            break;
        }

        do
        {
           cout << "Enter the Student's raw score (max. of 10): ";
           cin >> score;
           cin.ignore();
           if (score > 10)
           {
               cout << "You cannot have a score higher than 10." << endl;
           }
        } while (score > 10);


        student_ids[head_count] = id;
        scores[head_count] = score;
    }

    return head_count;
}

bool isDuplicate(int* student_ids, int head_count, int id)
{
    for (int i = 0; i < head_count; i++)
    {
        if (student_ids[i] == id)
        {
            return true;
        }
    }
    return false;
}

I deliberately covered the part you actually had working, but re-wrote it somewhat to make it a better design. Note the use of pointers instead of fixed arrays for the integer arrays.

I hope this helps you see how to write the code better. I do not guarantee that this works, but it should; hopefully, it will give you some idea of how to finish the rest of it. If you have any questions, ask.

Edited 4 Years Ago by Schol-R-LEA: quick spelling error correction

Shouldn't the boolean "isDuplicate" go before the integer "getScores", so there aren't initialization errors?

Shouldn't the boolean "isDuplicate" go before the integer "getScores", so there aren't initialization errors?

The only requirement is that it's declared before use. The given code was only a snippet, which suggests that something along the lines of the following was assumed:

bool isDuplicate(int* student_ids, int head_count, int id);
int getScores(int* student_ids, int* scores, int max_students);

...

int getScores(int* student_ids, int* scores, int max_students)
{
    ...
}

bool isDuplicate(int* student_ids, int head_count, int id)
{
    ...
}

"isDuplicate" is declared in "getScores", so it should be defined first.

I think you're confused. Can you point out exactly what you're referring to?

This question has already been answered. Start a new discussion instead.