CSCI 1301 – Project 1 – Solution

Clément Aubert

September 12, 2020

Grade Calculation

The following guideline was used to grade your work over 20:

Points
You submitted something  + 20
You did not submit using D2L  − 2
It is not the right file (e.g., only the sln, or not a zip archive)  − 19 or  − 5 if the source code is present
The archive does not have the right name (i.e., “lname_fname.zip”)  − 2
The project does not have the right name (i.e., “Project01”)  − 2
There are no delimited comments at the beginning with your name and the date (i.e., /*…*/)  − 2
Your program does not compile  − 15
The variable for your username has the wrong type or value.  − 3
The first message is not properly displayed.  − 3
You are not correctly reading the height of the user.  − 3
Your conversion from centimeters to feet and inches is off.  − 4
The second message is not properly displayed.  − 3
You added meaningful comments to your code.  + 1

Of course, I will use this table only as a guideline, and use my judgment to grade your work, but I believe it is useful for you to see where my expectations were.

Solution

Please, find a possible solution in this archive. The Program.cs file contains:

/*
 * Clement Aubert
 * 09/12/2020
 * CSCI 1301 -- Project 1
 */

using System;

    class Program
    {
        static void Main(string[] args)
        {
        /* Display the information about us: */

        string uName = "caubert";
        Console.WriteLine(uName + " would like to know your height in meters. Please enter it: ");

        /* Gather the information about the user :*/

        double heightIncm; // We use a double to store the height in centimeters given by the user.
        heightIncm = (double.Parse(Console.ReadLine()) * 100); // This line does a lot.
        // 1. We read as a string the value entered,
        // 2. We convert it to a double,
        // 3. We multiply it by 100, to obtain centimeters instead of meters,
        // 4. We assign the result to heightIncm.

        /* Conversion */

        double heightInin; // Variable to hold the height in inches

        /* 
         * Conversion factor from cm to ft change with where you are!
         * https://en.wikipedia.org/wiki/Foot_(unit)#US_survey_foot
         * 
         * In Georgia, we use the U.S. Survey feet
         * https://www.ngs.noaa.gov/SPCS/images/spcs83_legislation_feet.png
         * 
         * So, 
         * 1 ft = 0.304800609601 m
         * 1 ft = 30.4800609601 cm
         * 
         * But we will use anther way of computing the height.
         * We will convert it to inches, using
         * 1 in = 2.54 cm
         * and then obtain the feet using
         * 1 ft = 12 in
         */

        heightInin = heightIncm / 2.54; // Store the height in inches of the user.
        // The rest of the computation, and the truncation, will take place at the next step.

        /* Displaying the result */
        Console.WriteLine(
            uName +  " computed that your height is " 
            + (int)(heightInin / 12) // Compute the number of feet, and truncate it.
            + " ft and "
            + (int)(heightInin % 12) // Compute the remainder of the previous operation, and truncate it.
            + " inches."
            );
    }
}