Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > BOOK: Beginning Visual C#
|
BOOK: Beginning Visual C#
This is the forum to discuss the Wrox book Beginning Visual C#, Revised Edition of Beginning C# for .NET v1.0 by Karli Watson, David Espinosa, Zach Greenvoss, Jacob Hammer Pedersen, Christian Nagel, Jon D. Reid, Matthew Reynolds, Morgan Skinner, Eric White; ISBN: 9780764543821
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 24th, 2004, 04:09 PM
Authorized User
 
Join Date: Jul 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beginning Visual C# Exercises - Chapter 05 Answers

1. Answer a - int does not convert implicitly to short
        Answer c - boolean (and string) data types do not convert implicitly

2. enum color : short
        {
            // Per Sir Isaac Newton's set of seven rainbow colors plus black and white
            black,
            red,
            orange,
            yellow,
            green,
            blue,
            indigo,
            violet,
            white
        }

        Byte could replace the underlying data type in the above example.
            However, if you were to fine tune the color gradient to include
            more than 256 colors, then you would exceed the byte range

3. ....Add into existing code Ch04Ex06 after top of class
        struct imagNum
        {
            public double real, imag;
        }

        .... insert (or rewrite) into existing code Ch04Ex06 after "int iterations;" line
        // Maintain console window dimensions: 49 rows, 80 columns
        // Lose one row (49 -1) and column (80 -1) as starting points
        // Reduce imaginary input by 2.4 (48 rows * .05 step)
        double imagConstraint = 2.4;
        // Increase real input by 2.36 (79 columns * .03 step) - .01 [rounding adj]
        double realConstraint = 2.36;
        imagNum myStart;
        Console.WriteLine("Enter a two-place decimal number between -2.00 and 2.00");
        myStart.imag = Convert.ToDouble(Console.ReadLine());
        Console.WriteLine("Enter a two-place decimal number between -2.00 and 2.00");
        myStart.real = Convert.ToDouble(Console.ReadLine());

        .... Replace (or rewrite) next two "for ..." lines
        //for (imagCoord = 1.2; imagCoord >= -1.2; imagCoord -= 0.05)
        for (imagCoord = myStart.imag; imagCoord >= myStart.imag - imagConstraint; imagCoord -= 0.05)
        {
            //for (realCoord = -0.6; realCoord <= 1.77; realCoord += 0.03)
            for (realCoord = myStart.real; realCoord <= myStart.real + realConstraint; realCoord += 0.03)
            {

4. No, there are two errors in the second line of code:
        * An array of 5 elements may be accessed with an index of 0 through 4;
            the supplied index of 5 will generate an "IndexOutOfRangeException"
        * The assignment value requires quotes around it, so will not compile

5. Console.WriteLine("Enter a phrase to turn around:");
        string thePhrase = Console.ReadLine();
        char[] thework = thePhrase.ToCharArray();
        thePhrase = "";
        for (int i = thework.Length -1; i >= 0; i--)
            thePhrase += thework[i];
        Console.WriteLine("Here is your response in reverse order:");
        Console.WriteLine(thePhrase);

6. Console.WriteLine("Answer my imaginary question with a NO included:");
        string thePhrase = Console.ReadLine();
        // Handle 3 possible "no" cases
        thePhrase = thePhrase.Replace("no", "yes");
        thePhrase = thePhrase.Replace("No", "Yes");
        thePhrase = thePhrase.Replace("NO", "YES");
        Console.WriteLine("Here is the answer you meant to write:");
        Console.WriteLine(thePhrase);

7. Console.WriteLine("What has been the best occurrence today?");
        string thePhrase = Console.ReadLine();
        Console.WriteLine("Let me quote each word you stated:");
        Console.WriteLine("\"" + thePhrase.Replace(" ", "\" \"") + "\"");





Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning Visual C# Exercises - Chapter 05 seblake C# 1 July 26th, 2004 07:40 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.