Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

Sharing positivity.

β˜…β˜†β˜†

A quote of the day utility picks a random quote from a 2D array of quotes and outputs it.

Quote of the day

Make

Write a program that stores quotes in a 2D array. The first index stores the quote and the second index stores the author. The program should output a random quote and the author.

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called random_quote that:

  1. Returns a string array of two elements. The first element is a random quote. The second element is the author of the quote.

You can use the following data:

Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Martin Fowler

Code is like humour. When you have to explain it, it’s bad.
Cory House

Simplicity is the soul of efficiency.
Austin Freeman

The data structure for the first quote would be initialised as:

quote[0, 0] = "Any fool can write code that a computer can understand. Good programmers write code that humans can understand.";
quote[0, 1] = "Martin Fowler";

Complete the main program so that:

  1. The random_quote subprogram is called and the returned quote is stored in a string array called quote.
  2. The output is formatted so that the quote is enclosed in speech marks.
  3. The output is formatted so that the author is indented by two spaces followed by a hyphen.

Typical inputs and outputs from the program would be:

"Simplicity is the soul of efficiency."
  - Austin Freeman
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
  - Martin Fowler
πŸ†˜ If you're really stuck, use this Parsons code sorting exercise
Complete program
// Quote of the day program

using System;

class Submission
{
---
    // -------------------------
    // Globals
    // -------------------------
---
    static Random random_generator = new Random();
---


    // -------------------------
    // Subprograms
    // -------------------------
    // Function to output a random quote
---
    static string[] random_quote()
    {
---
        // Initialise data
        string[,] quote = new string[3, 2];
        quote[0, 0] = "Any fool can write code that a computer can understand. Good programmers write code that humans can understand.";
        quote[0, 1] = "Martin Fowler";
        quote[1, 0] = "Code is like humour. When you have to explain it, it’s bad.";
        quote[1, 1] = "Cory House";
        quote[2, 0] = "Simplicity is the soul of efficiency.";
        quote[2, 1] = "Austin Freeman";
---
        // Pick a random quote
        int index = random_generator.Next(0, 3);
---
        string[] chosen_quote = new string[2] { quote[index, 0], quote[index, 1] };
---
        return chosen_quote;
---
    }
---


    // -------------------------
    // Main program
    // -------------------------
    public static void Main(string[] args)
    {
---
        string[] quote = random_quote();
---
        Console.WriteLine("\"" + quote[0] + "\"");
        Console.WriteLine("  - " + quote[1]);
---
    }
---
}