Writing Code
When you are asked to write a program in the questions below, you should write one Rust source code file that lives in thecode/plain/src/bin/ directory, has a main function, and can be run with cargo run –bin foo (where foo.rs is the name of the Rust source code file). Do not use any additional crates in your solutions.
Question: File/Strings
Write a program examfile.rs that opens a file and prints out the lines of the file (with line numbers) if the line contains “the” (lowercase only). The file to open should be given as the first command-line argument to your program. The line numbers printed should be the original line numbers in the file, before restricting to the lines containing “the”.Your output should be equivalent to running cat -n | grep the. That is, suppose the file examfile.txt contains:the rain
in spain
falls
mainly
on the
plain
Then your output should be the same as:$ cat -n examfile1.txt | grep the
1 the rain
5 on the
(you do not need to worry about padding numbers or anything like that; just put two spaces between the line number and the line text).
Question: Simple Interactive Program
Write a simple interactive program examinter.rs that plays a very simple text adventure game with the user. If you are unfamiliar with text adventure games, play Zork online for a few minutes. Your adventure game should have at least four locations, and the user should be able to go between them using go north, go south, go east, go west, etc. if the locations are connected in that direction. Your program should print a description of the location whenever you enter that location (via a go command). Hints: number each location; store the location descriptions in, say, a Vec; number each direction (e.g., 0 is North, 1 is East, etc.) and then have a paths:Vec<[Option;4]> structure that stores whether or not there is a path leading from a location and which location it goes to, i.e., paths[i][d] = Some(j) if you can go in direction dfrom location i and end up in location j; and paths[i][d] = None if you cannot go in direction d from location i.

For This or a Similar Paper Click Here To Order Now