Question

In: Computer Science

QUESTION 40 When you plan the test runs for a program, you should do all but...

QUESTION 40

  1. When you plan the test runs for a program, you should do all but one of the following. Which one is it?

    a.

    list the invalid entries and unexpected user actions for each test run

    b.

    list the expected exceptions for each test run

    c.

    list the expected results for each test run

    d.

    list the valid entries for each test run

1.5 points   

QUESTION 41

  1. Which of the following for loops could you use to iterate the data in a vector named days if you need to be able to work with iterators within the loop?

    a.

    for (auto p: days) { ... }

    b.

    for (int i = 0; i < days.size(); ++i) { ... }

    c.

    for (auto iter = days.begin(); iter != days.end(); ++iter) { ... }

    d.

    all of the above

1.5 points   

QUESTION 42

  1. Code Example 8-2
    1. /* This application displays a student's score after a 5-point curve */
    2.
    3. void display_info(string fname, string lname, int score) {
    4.      cout << "Hello, " << fname << ' ' << Lname;
    5.      cout << "Your score on this is " << score;
    6.      score = score + 5;
    7. }
    8.
    9. int main() {
    10.     string first, last;
    11.     int score = 0;
    12.     cout << "first name: ";
    13.     cin >> first;
    14.     cout << "last name: ";
    15.     cin >> last;
    16.     cout << "score: ";
    17.     cin >> grade;

    18.     display_info(first, last, score);
    19. }

    (Refer to Code Example 8-2.) What is the error in the main() function?

    a.

    The cin statement on line 17 stores the input in an undefined variable named grade.

    b.

    The cin statement on line 17 does not define grade as an int.

    c.

    The function call on line 18 should send in fname and lname as arguments, not first and last.

    d.

    There are no errors in main().

1.5 points   

QUESTION 43

  1. Which of the following techniques could you use to define an array of strings named products with 5 elements?

    a.

    const int size = 5;
    array<string, size> products;

    b.

    array<string, 5> products;

    c.

    int size;
    cin >> size;
    array<string, size> products;

    d.

    all of the above

    e.

    a and b only

1.5 points   

QUESTION 44

  1. Which type of error lets the program run but produces the wrong results?

    a.

    user

    b.

    runtime

    c.

    syntax

    d.

    logic

1.5 points   

QUESTION 45

  1. How would you modify the following enumeration to change the underlying enumerator type to char?
    enum class Suit {
        diamonds = 'd',
        hearts = 'h',
        clubs = 'c',
        spades = 's'
    };

    a.

    enum class : char Suit {
        diamonds = 'd',
        hearts = 'h',
        clubs = 'c',
        spades = 's'
    };

    b.

    enum class Suit : char {
        diamonds = 'd',
        hearts = 'h',
        clubs = 'c',
        spades = 's'
    };

    c.

    enum class Suit char {
        diamonds = 'd',
        hearts = 'h',
        clubs = 'c',
        spades = 's'
    };

    d.

    enum class Suit {
        char diamonds = 'd',
        char hearts = 'h',
        char clubs = 'c',
        char spades = 's'
    };

1.5 points   

QUESTION 46

  1. If you don’t specify the values of the enumerators in an enumeration, they are stored as

    a.

    sequential int values starting at 1

    b.

    sequential int values starting at 0

    c.

    sequential char values starting at 'A'

    d.

    sequential char values starting at 'a'

1.5 points   

QUESTION 47

  1. Given the following code, if the user worked 45 hours at $10.00/hour, the output is as shown below.
    1. int main() {
    2.      double hours, rate, pay;
    3.      cout << "How many hours did you work? ";
    4.      cin >> hours;
    5.      cout << "What is your hourly rate? ";
    6.      cin >> rate;
    7.      if (hours > 40 && rate < 15)
    8.          pay = (40 * rate) + (hours - 40 * rate * 1.5);
    9.      else
    10.         pay = hours * rate;
    11.     cout << "Your pay is: $" << round(pay * 100) / 100;

    12. }
    Output:
    Your pay is: $-105
    Which line should be changed to fix this logic error?

    a.

    change line 8 to: pay = (40 * rate) + ((hours - 40) * rate * 1.5);

    b.

    change line 7 to: if (hours > 40 || rate < 15)

    c.

    change line 2 so hours and rate are integer values instead of floating-point values

    d.

    change line 11 to: cout << "Your pay is: $" << ceil(pay * 100) / 100;

1.5 points   

QUESTION 48

  1. Which of the following techniques could you use to initialize an array of ints named ages so its 4 elements contain the values 57, 33, 45, and 0?

    a.

    array<int, 4> ages { 57, 33, 45, 0 };

    b.

    array<int, 4> ages { 57, 33, 45 };

    c.

    array<int, 4> ages;
    ages[0] = 57;
    ages[1] = 33;
    ages[2] = 45;
    ages[3] = 0;

    d.

    all of the above

    e.

    a and c only

1.5 points   

QUESTION 49

  1. Which of the following is not an advantage of using a for loop and subscripting to iterate the data in a container?

    a.

    You can easily skip elements by changing the loop criteria.

    b.

    It uses a counter variable that can be useful for tasks such as displaying a number for each element.

    c.

    It’s available to all containers.

    d.

    You can get the value of an element without dereferencing an iterator that points to it.

Solutions

Expert Solution

Q 40) -> b.list the expected exceptions for each test run

Explaination :: We have to check all the exceptions that can be occured during execution which causes program to terminate abnormally.

Q 41)-->> c. for (auto iter = days.begin(); iter != days.end(); ++iter) { ... }

Explaination :: We use vector<int>::iterator ptr; .Iterators are used to point at the memory addresses of STL containers. They are primarily used in sequence of numbers, characters etc. They reduce the complexity and execution time of program.

Q 42)-->> a. The cin statement on line 17 stores the input in an undefined variable named grade.

Explaination :: variable grade is not declared due to this we will get the error.

Q43)-->> d. all of the above

Q 44-->> d. logic

Explaination :: If we run program without any error but still getting wrong result then the logic of the program is wrong.

Q45) --> b. enum class Suit : char {
    diamonds = 'd',
    hearts = 'h',
    clubs = 'c',
    spades = 's'

Q46--> b. sequential int values starting at 0

Explaination :: By default it starts with index 0

Q47-->> a. change line 8 to: pay = (40 * rate) + ((hours - 40) * rate * 1.5);

Explaination :: Operator precedance

Q 47-->> e. a and c only

Q 48-->> c. It’s available to all containers.


Related Solutions

Java - Create a program that simulates a slot machine. When the program runs, it should...
Java - Create a program that simulates a slot machine. When the program runs, it should do the following: - Ask the user to enter the amount of money he or she wants to enter into the slot machine. - Instead of displaying images, have the program randomly select a word from the following list: Cherries, Oranges, Plums, Bells, Melons, Bars (To select a word, the program can generate a random number in the range of 0 through 5. If...
You will create a program that runs in one of two modes, interactive mode and test...
You will create a program that runs in one of two modes, interactive mode and test mode. The mode will determined by the command line, passing in a "-i" flag for interactive or "-t" for test mode. Require the user to pass in a flag. $> ./lab02 -i Make a selection: 1) Insert value at position 2) Remove at position 3) Replace value at position 4) Print length 5) Print list 6) Exit Choice: $> ./lab02 -t <output from your...
What do you test when you test a control?
What do you test when you test a control?
Write a Java test program, all the code should be in a single main method, that...
Write a Java test program, all the code should be in a single main method, that prompts the user for a single character. Display a message indicating if the character is a letter (a..z or A..Z), a digit (0..9), or other. Java's Scanner class does not have a nextChar method. You can use next() or nextLine() to read the character entered by the user, but it is returned to you as a String. Since we are only interested in the...
When making a accounting scope and test plan what should be in it? How would I...
When making a accounting scope and test plan what should be in it? How would I present my information and data to auditors? make an example
When do you use a one-tailed test? When do you use a two-tailed test? How is...
When do you use a one-tailed test? When do you use a two-tailed test? How is SPSS used to perform the calculations needed for each?
when should you praise and reward children and when should you not? give 4 DO and...
when should you praise and reward children and when should you not? give 4 DO and 4 DO NOT examples Discuss what is Intrinsic motivation and extrinsic motivation. Relationship between rewards and intrinsic movtivation of learning.
The question is about C++ The main should test all functionalities of the playlist implement a...
The question is about C++ The main should test all functionalities of the playlist implement a linked list to store songs of a playlist. A song (which is your node) is going to include the following data: - int Song ID - string Song Title - string Author Title - double Length Don't forget to include the next pointer that will lead to the next song. Your playlist (which is your linkedlist) is going to include the following functionalities: -...
When should a country export goods and when should a country import goods When do you...
When should a country export goods and when should a country import goods When do you think tariffs and or quotas should be put in place? Do you think President Trumps strict trade policies will benefit the country and why
TO DO in JAVA: The program that runs is TrackInsurance. Open this up and add five...
TO DO in JAVA: The program that runs is TrackInsurance. Open this up and add five instances of your ArtInsurance class at the noted location in the main method. Use whatever data you like. TrackInsurance(below) package itp120mod6; import java.util.*; public class TrackInsurance extends Object { public static Scanner scan = new Scanner(System.in); // method that runs first public static void main(String[] args) throws Exception { // make an ArrayList of customers and insurance policies ArrayList cust = new ArrayList(); //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT