Wrox Programmer Forums
|
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 August 24th, 2003, 11:42 PM
Registered User
 
Join Date: Aug 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 6 Exercises

Just wanted to put this out to help anyone, and if anyone sees anything incorrect or if they believe they have a better answer. Go ahead and point out any errors or helpers if you want.

1. a) Return type does not equal to return value
b) This one im not so sure i think you don't need the params in front of int[] args, or that the parmeters don't match

2. a) seems theres 2, twos

I had entered a string named: "String" and a int: 10 into my command line arguements

        static void Main(string[] args)
        {
            string myString = args[0];
            int myInt = Convert.ToInt32(args[1]);
            Console.WriteLine("{0} command line arguments were specified:", args.Length);
            Console.WriteLine("The string command line was: {0}\nThe int command line was: {1}",
                myString, myInt);
        }

2. b)

    class Class1
    {
        delegate string impersonateDelegate();

        static string input()
        {
            return Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter a string:");
            impersonateDelegate impersonate = new impersonateDelegate(input);
            string myString = impersonate();
            Console.WriteLine("Your string was {0}", myString);
        }
    }

3 and 4)

Seemed like these where similiar problems so I just joined them into one app. You don't really need the info in main since it just asked for a function in the struct on 4. But I just wanted to be able to interact with it and see it work.

    class Class1
    {
        struct order
        {
            public string itemName;
            public int unitCount;
            public double unitCost;

            public double Total()
            {
                return unitCount * unitCost;
            }
            public string TotalCost()
            {
                return "Order information: " + unitCount + " " + itemName + " items at $" + unitCost
                    + " each, total cost $" + Total();
            }
        }
        static void Main(string[] args)
        {
            order orderTotal;
            orderTotal.itemName = "CD";
            orderTotal.unitCost = 15;
            Console.WriteLine("How many {0}'s do you want:", orderTotal.itemName);
            orderTotal.unitCount = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine(orderTotal.TotalCost());
        }
    }
 
Old September 4th, 2003, 05:40 PM
Registered User
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think the problem with the second function in exercise 1 is that the params type cannot be used as a parameter unless it is the last one in the function. For instance, the function's definition SHOULD be:

static void myFunction(string label, bool showLabel, params int[] args)
{
   ...
}
 
Old October 17th, 2003, 11:31 AM
Authorized User
 
Join Date: Aug 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Chris Beach Send a message via AIM to Chris Beach Send a message via MSN to Chris Beach Send a message via Yahoo to Chris Beach
Default

1 b) also whats the defualt for showLabel? nothing? true? or false?
params should be the last item of the declaration as well

 
Old March 9th, 2004, 06:38 PM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Compustein Send a message via AIM to Compustein Send a message via MSN to Compustein Send a message via Yahoo to Compustein
Default

Here is my take on 2b./3. it just eliminates the redundant assignment of the string.

class Class1
{
    delegate string procDel();

    static string Readit()
    {
    return Console.ReadLine();
    }
.
.
.
static void Main(string[] args)
    {
    Console.Write("Please enter any string of characters: ");

    procDel myString = new procDel(Readit);

    Console.WriteLine("\nString entered was {0}\n", myString());
    }
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 - End of chapter exercises whizzkid1892 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 July 30th, 2008 12:02 PM





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