week 5 cs 2433

Cards (14)

  • What is the index of the last element?
    int numList[50];

    49
    Unknown, because the array has not been initialized.
    50
    0
    49
  • Given x = 4 and y = 8, what are the ending values of x and y?
    x = y;
    y = x;
    x = y;

    x = 8, y = 4
    x = 4, y = 4
    x = 8, y = 8
    x = 4, y = 8
    x = 8, y = 8
  • Which assigns the vector's last element with 99?
    vector myVector(15);

    myVector.at(16) = 99;
    myVector.at(0) = 99;
    myVector.at(15) = 99;
    myVector.at(14) = 99;
    myVector.at(14) = 99;
  • Given two vectors, studentNames that maintains a list of students, and studentScores that has a list of the scores for each student, which XXX and YYY prints out only the student names whose score is above 80? Choices are in the form XXX/ YYY.

    vector studentNames(NUM_STUDENTS);
    vector studentScores(NUM_STUDENTS);
    unsigned int i;
    for (i = 0; i < studentScores.size(); ++i) {
    if (XXX > 80) {cout << YYY << " ";
    }
    }

    studentScores.at(i) / studentScores.at(i)
    studentNames.at(i) / studentScores.at(i)
    studentScores.at(i) / studentNames.at(i)
    studentNames.at(i) / studentNames.at(i)

    studentScores.at(i) / studentNames.at(i)
  • Which best describes what is output?
    Assume v is a large vector of ints.
    int i;
    int s;
    s = v.at(0);
    for (i = 0; i < v.size(); ++i) {
    if (s > v.at(i)) {
    s = v.at(i);
    }}
    cout << s;

    max value in v
    min value in v
    last value in v
    first value in v
    min value in v
  • Which evaluates to true for the string str = "beta123"?

    islower(str[1])
    isspace(str[2])
    isalpha(str[4])
    isdigit(str[0])
    islower(str[1])
  • Given two same-sized integer vectors prevValues and newValues. Which assigns eq with 1 if the vectors are equal, and 0 otherwise. Choices are in the form XXX / YYY / ZZZ.
    if (XXX) {
    YYY;
    }
    else {
    ZZZ;
    }

    prevValues = newValues / eq = 1 / eq = 0
    prevValues == newValues / eq = 0 / eq = 1
    prevValues = newValues / eq = 0 / eq = 1
    prevValues == newValues / eq = 1 / eq = 0
    prevValues == newValues / eq = 1 / eq = 0
  • Which XXX outputs all the elements of vector myVals?
    for (i = 0; XXX; ++i) {
    cout << myVals.at(i) << " ";
    }

    i <= myVals.size();
    No such expression as the number of elements is unknown.
    i < myVals.size;
    i < myVals.size();
    i < myVals.size();
  • The numNegatives variable counts the number of negative values in the vector userVals. What should numNegatives be initialized to?
    vector userVals(20);
    unsigned int i;
    numNegatives = XXX;
    for (i = 0; i < userValues.size(); ++i) {
    if (userValues.at(i) < 0) {
    numNegatives = numNegatives + 1;
    }
    }

    0
    No initialization needed
    userVals.at(0)
    1
    0
  • Given array scorePerQuiz has 10 elements. Which assigns element 7 with the value 8?

    scorePerQuiz = 8;
    scorePerQuiz[8] = 7;
    scorePerQuiz[7] = 8;
    scorePerQuiz[0] = 8;
    scorePerQuiz[7] = 8;
  • What are the ending values in itemCount?
    vector itemCount;itemCount.push_back(6);itemCount.push_back(7);itemCount.push_back(8);itemCount.pop_back();

    6, 7, 0
    6, 7
    7, 8
    6, 7, 8
    6, 7
  • For the given program, which XXX iterates through the vector to find the state that is input (userState) until a match is found?
    vector stateNames(NUM_STATES);vector statePop(NUM_STATES);string userState;bool foundState = false;unsigned int i;
    cin >> userState;
    foundState = false;for (i = 0; XXX; ++i) {if (stateNames.at(i) == userState) {foundState = true;cout << userState << ", " << statePop.at(i) << endl;}}

    (i < NUM_STATES - 1) && (!foundState)
    (i < NUM_STATES - 1)
    (i < NUM_STATES)
    (i < NUM_STATES) && (!foundState)
    (i < NUM_STATES) && (!foundState)
  • Which XXX and YYY will find the minimum value of all the elements in the array? Choices are in the form XXX / YYY.
    int userVals[NUM_ROWS][NUM_COLS];int minVal = userVals[0][0];for (i = 0; i < NUM_ROWS; ++i) {for (j = 0; j < NUM_COLS; ++j) {if (XXX) {YYY;}}}

    userVals[j] < minVal / minVal = userVals[j]
    userVals[i][j] < minVal / minVal = userVals[i][j]
    userVals[i] < minVal / minVal = userVals[i]
    userVals[i][j] > minVal / minVal = userVals[i][j]
    userVals[i][j] < minVal / minVal = userVals[i][j]
  • What is the ending value of the element at index 0?
    int numbers[10];numbers[0] = 35;numbers[1] = 37;numbers[1] = numbers[0] + 4;

    37
    0
    35
    39
    35