CSCI 1301 - Lab 21

Clément Aubert

November 1, 2018

This lab is a review session: come with questions and problems, that we can try to solve together. There are two activities below, do them if times allow, or to start a discussion.

Part I – Solving Project #4

You can download

(nota: those files will be back after the Fall 2018 class completed this assignment.)

Part II – Pushing Further (Optional)

Some students used two techniques that were not introduced in class to solve the 4th project, here is a short presentation of them.

  1. ToLower: String is actually a class, and not a datatype. It means that it comes with methods, as any class does. Among them is a method called ToLower, that doesn’t take any argument, and returns a copy of the string calling it converted to lowercase. A typical example of usage would be:
string test = "HI MOM";
test = test.ToLower();
Console.WriteLine(test);

There are numerous other methods, listed at https://msdn.microsoft.com/en-us/library/system.string_methods(v=vs.110).aspx. Here is an example of a statement using EndsWith, a method that takes a string as argument and returns a boolean:

string test2 = Console.ReadLine();
if (test2.EndsWith("mom")) {
    Console.WriteLine("The string you entered ends with \"mom\"!");
}

Write statements using StartsWith and ToUpper, two methods really similar to the ones we just introduced.

  1. Environment.Exit is a brutal way of exiting a progam, but it works:
using System;
class Test
    {
    public static void Main()
    {
        Environment.Exit(0);
        Console.WriteLine("Hi Mom!");
    }
}

This is definitely not the kind of code you should be using at this point: goto, Environment.Exit and empty return were used by some of you to exit the program, but a fine handling of conditional statements was enough to do what was needed. As of now, you should refrain from using such statements, but knowing them could be useful in the future.