The ASCII Printer

Report a typo

Bruno really likes ASCII Art and emojis; he wants to create an AsciiPrinter interface that allows him to read ASCII Art from the ascii_art.txt file.

Bruno has already created the File string type; it will hold the file name, which must be a string.

Your task is to help Bruno write the required additional code to create the AsciiPrinter interface and afterwards call the AsciiPrinter within the main function to read the ascii_art.txt file and then print the read ASCII Art to the console.

This problem uses the ReadFile function from the os package to read the ASCII Art contained within the ascii_art.txt file. To solve this task, you don't need to know how to read from files or how the os package works. Your only objective is to create the AsciiPrinter interface and then call it within the main function.

Write a program
package main

import (
"fmt"
"log"
"os"
)

type File string

// Do not change the contents of the PrintAscii() method!
func (f File) PrintAscii() {
b, err := os.ReadFile(string(f))
if err != nil {
log.Fatal(err)
}
fmt.Println(string(b))
}

// Create the AsciiPrinter interface with the PrintAscii() method below:
type ? interface {
?
}

func main() {
// Create the variable 'a' of the AsciiPrinter interface type below:
var a ?

// Open and read the file "ascii_art.txt" with the 'a' AsciiPrinter interface:
a = File("ascii_art.txt")

// Call the PrintAscii() method on the 'a' AsciiPrinter interface below:
a.?
}
___

Create a free account to access the full topic