Multiple Choice Questions (with solutions)

https://csci-1301.github.io/about#authors

May 22, 2024 (01:30:36 PM)

  1. Why are the instructors sharing most of the material in odt, docx, pdf, html and md?

  2. What does “free” software means?

  3. In your IDE, the shortcut to compile your program is usually…

  4. To share or backup a project, you need to…

  5. If your IDE returns the message

    Program.cs(21,21): Error CS0117: 'Console' does not contain a definition for 'WiteLine' (CS0117) (Solution)

    This means that…

  6. Consider the following code:

    int age, defaultChoice = 0;
    decimal averagePrice;

    Which of the following is correct?

  7. Consider the following code:

    int person = 12;
    int pie = 5;
    int piePerPerson = pie / person;
    Console.WriteLine("Each guest gets " + piePerPerson + " pie(s).");

    What will be displayed by it?

  8. Consider the following statement:

    decimal balance = 2.5M;
    decimal price = 12;
    decimal remainingBalance = balance - price;

    Which of the following is correct?

  9. The method used to read a string from the user is called…

  10. Consider the following program:

    Console.WriteLine("Enter your age.");
    string fromUser = Console.ReadLine();
    int age = _______ (fromUser);

    To correctly be able to store the string in fromUser into age, you should replace _______ with…

  11. What are, respectively, the return types of a constructor and of a ToString method?

  12. What is the name of a constructor method?

  13. What are the three logical connectives in C# (that we studied)?

  14. Which of the following will evaluate to true?

  15. Will the following expression evaluates, and if so, what will it evaluate to?

    true == false || 2 / 1 > 0 && 3 - 1 != 2 * 0.5 + 0.5

    evaluates?

  16. What will be displayed by the following code?

    int number = 10;
    while (number <= 15)
    {
        number+=2;
        Console.Write(number + " ");
    }
  17. What will be displayed by the following code?

    int i = 0;
    while(i < 10)
    {
        Console.WriteLine(i);
    }
  18. Consider the following code:

    Console.WriteLine("Enter… something!");
    int answer;
    bool valid = int.TryParse(Console.ReadLine(), out answer);
    Console.WriteLine($"returns: {valid}, value:{answer}");

    If the user enters “Train”, then it will display:

  19. Consider the following code:

    string answer;
    Console.WriteLine("Enter something");
    answer = Console.ReadLine();
    while (answer != "yes" || answer !="Yes"){
        Console.WriteLine("Enter something");
        answer = Console.ReadLine();
    }

    What can the user enters to exit this loop:

  20. Consider the following code:

    int answer;
    Console.WriteLine("Enter something");
    answer = int.Parse(Console.ReadLine());
    while (answer > 10 && answer < 100){
        Console.WriteLine("Enter something");
        answer = int.Parse(Console.ReadLine());
    }

    What can the user enters to exit this loop?

  21. What is the correct way of creating an array of int of size 5 named myArray?

  22. Consider the following code:

    int[] grades = {10, 20, 5, 15};
    Console.WriteLine(grades[2]);

    What will it display?

  23. Consider the following code:

    char[] grades = {'A', 'B', 'C', 'D', 'F'};
    int i = 0;
    while(i < grades.Length){
        i++;
        Console.WriteLine(grades[i]);
    }

    Something is wrong with it, can you tell what?

  24. What will be displayed by the following code?

    for (int e = -5; e <= 20; e += 5)
    {
        Console.Write(e + " ");
    }
  25. What will be displayed by the following code?

    int variable = 0;
    for (int e = 1; e <= 5; e += 1)
    {
        variable += e;
    }    
    Console.WriteLine(variable);