This is the last questions I have about arrays. I have no idea of where to go with any of them except writing the header of the functions with the parameters. Again this is just questions from a study guide for my final exam so I am not asking you to do my homework but just need some insight on how to do array problems for my exam. Thanks


Use the declarations in the 3 following exercises.

const int MAXSTUD = 100;
bool passing [MAXSTUD];
int grade, length = MAXSTUD, score[MAXSTUD];

-Write a void function called init that initializes all components of passing to true. Use passing and length as parameters.

-Write a void function called grader that has passing, score and length as parameters. Set the components of passing to false whenever the parallel value of score is less than 60.

-Write a value-returning function PassTally that takes passing and length as parameters and returns the count of components in passing that are true.

Don't think too much about parts 2 and 3 when working on part 1. The instructor has it set up so if you can do earlier parts as instucted it they will flow nicely into latter parts. Once you have more experience you can think of the whole program in general terms like this before you do each part one at a time. For now, someone else is telling what to do, when, and all you have to do is follow directions.

So here is what I have for part 1.

void init(bool passing[], int length)
{
     while (passing[MAXSTUD])
         passing[] = true;
}

and part 2

void grader(bool passing[], int score[], int length)
{
     while (score[] < 60)
          passing[] = false;
}

and part 3.

int PassTally(bool passing[], int length)
{
      int ctr=0;
      while (passing[] == true)
        {
            if (length <= 100)
            ctr++;
         }
     return ctr;
}

does this look right?

Set part 2 and 3 aside.

Did you try putting step 1 in a program to see if it compiled/worked?

Why would your instructor tell you to pass length to the function if they didn't want you to use it somehow in the function? You need it to determine how many times you put true into passing. Since you know how many times you want to put true into passing a for loop would traditionally be used to do it, though a while loop could also be used.

How do you identify which element of passing you are assigning something to? You use an index in the subscript operator [], correct?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.