Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the 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 July 21st, 2004, 12:51 PM
Authorized User
 
Join Date: Jul 2004
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beginning Visual C# Exercises - Chapter 05

1. Answer a - int does not convert implicitly to short [2004/08/13 - missed this on original posting]
        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(" ", "\" \"") + "\"");
 
Old July 26th, 2004, 07:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Steven, you are doing a great favor to the readers of this book, you are doing what many others may be capable of doing but they lack your kindheartedness and willingness to help.

Ankur

Regards
Ankur Verma





Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning Visual C# Exercises - Chapter 18 seblake C# 1 October 9th, 2004 11:33 PM
Beginning Visual C# Exercises - Chapter 15 seblake C# 1 September 17th, 2004 08:41 PM
Beginning Visual C# Exercises - Chapter 11 seblake C# 1 August 9th, 2004 10:48 AM
Beginning Visual C# Exercises - Chapter 09 seblake C# 0 July 27th, 2004 03:23 PM





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