I am very new to the development side. Please help me to find the answer for this question. If possible please explain me how to do this.
The following simple bit of C# code creates an ArrayList.
It then adds a number of “BoxesOfWidgets” to the ArrayList, adding Widgets within each box.
The method GetRidOfTheSmallWidgets is meant to get rid of all of the widgets with lengths less than 20. Please add the code into this method to search through the ArrayList of boxes, and remove the small widgets from them.
You may not use foreach loops, iterators, or any other loop construct that is language specific.
Guys please help me to find this
Page 1 of 110 Replies - 460 Views - Last Post: 27 April 2012 - 08:55 AM
Replies To: Guys please help me to find this
#2
Re: Guys please help me to find this
Posted 26 April 2012 - 11:52 PM
What have you tried? We are not a coding writing service.
#3
Re: Guys please help me to find this
Posted 26 April 2012 - 11:55 PM
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
ArrayList colBoxesOfWidgets = new ArrayList();
colBoxesOfWidgets.Add(new BoxOfWidgets("Cardboard"));
((BoxOfWidgets)colBoxesOfWidgets[0]).colWidgets.Add(new Widget("The blue widget", 12));
((BoxOfWidgets)colBoxesOfWidgets[0]).colWidgets.Add(new Widget("The red widget", 15));
((BoxOfWidgets)colBoxesOfWidgets[0]).colWidgets.Add(new Widget("The silver widget", 6));
((BoxOfWidgets)colBoxesOfWidgets[0]).colWidgets.Add(new Widget("The green widget", 52));
colBoxesOfWidgets.Add(new BoxOfWidgets("Metal"));
((BoxOfWidgets)colBoxesOfWidgets[1]).colWidgets.Add(new Widget("The gold widget", 9));
((BoxOfWidgets)colBoxesOfWidgets[1]).colWidgets.Add(new Widget("The orange widget", 115));
((BoxOfWidgets)colBoxesOfWidgets[1]).colWidgets.Add(new Widget("The pink widget", 1));
colBoxesOfWidgets.Add(new BoxOfWidgets("Metal"));
((BoxOfWidgets)colBoxesOfWidgets[2]).colWidgets.Add(new Widget("The grey widget", 12));
((BoxOfWidgets)colBoxesOfWidgets[2]).colWidgets.Add(new Widget("The black widget", 15));
((BoxOfWidgets)colBoxesOfWidgets[2]).colWidgets.Add(new Widget("The white widget", 19));
((BoxOfWidgets)colBoxesOfWidgets[2]).colWidgets.Add(new Widget("The brown widget", 60));
((BoxOfWidgets)colBoxesOfWidgets[2]).colWidgets.Add(new Widget("The peach widget", 16));
GetRidOfTheSmallWidgets(colBoxesOfWidgets);
}
public static ArrayList GetRidOfTheSmallWidgets(ArrayList colBoxesOfWidgets){
//Place your code in here
//It should remove all widgets that have lengths lower than 20.
return colBoxesOfWidgets;
}
}
class BoxOfWidgets
{
public string boxType;
public ArrayList colWidgets;
public BoxOfWidgets(string newBoxType)
{
boxType = newBoxType;
colWidgets = new ArrayList();
}
}
class Widget
{
public string name;
public float length;
public Widget(string newName, float newLength)
{
this.name = newName;
this.length = newLength;
}
}
}
MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!
This post has been edited by JackOfAllTrades: 27 April 2012 - 03:59 AM
#4
Re: Guys please help me to find this
Posted 27 April 2012 - 12:07 AM
Put code in [code] tags. Ok, so you're almost there. Surely, you can up the logic to do this. You've managed to get this far. What algorithm have you come up with?
This post has been edited by blackcompe: 27 April 2012 - 12:07 AM
#5
Re: Guys please help me to find this
Posted 27 April 2012 - 12:13 AM
blackcompe, on 27 April 2012 - 12:07 AM, said:
Put code in [code] tags. Ok, so you're almost there. Surely, you can up the logic to do this. You've managed to get this far. What algorithm have you come up with?
Hai,
Thanks for the reply first. Actually I am a undergraduate student. This is the test. I am a basic learner of .net. I tried to this much. But i dont know how to do it without for loop and iterations concept.
I want to create a function tat deletes data..
#6
Re: Guys please help me to find this
Posted 27 April 2012 - 12:51 AM
They're testing your knowledge of recursion. Try and come up with a solution or some psuedocode at least.
#7
Re: Guys please help me to find this
Posted 27 April 2012 - 03:25 AM
blackcompe, on 27 April 2012 - 12:51 AM, said:
They're testing your knowledge of recursion. Try and come up with a solution or some psuedocode at least.
First Arraylist is colBoxesOfWidgets
colBoxesOfWidgets.Add(new BoxOfWidgets("Cardboard"));- This line Adds a new BoxOfWidget item
'CardBoard' and also adds a new Arraylist called colWidgets
The subequent lines add items in the new arraylist colWidgets
so the stucture of the arraylist is
In the 0th location of Arraylist colBoxesOfWidgets there is a new arraylist colWidgets where colwidgets
contains items Cardbox,blue widget,red widget,silver widget etc
In the 1st location of Arraylist colBoxesOfWidgets there is a new arraylist colWidgets where colwidgets
contains items metal,gold widget,orange widget,pink widget etc
Same with the 2nd location as well
I dont know how to write the formal code for this...
#8
Re: Guys please help me to find this
Posted 27 April 2012 - 04:08 AM
I find it easier when do recursion to start with the base case first.
#9
Re: Guys please help me to find this
Posted 27 April 2012 - 04:10 AM
#11
Re: Guys please help me to find this
Posted 27 April 2012 - 08:55 AM
Did you receive the majority of this code from your professor with the instructions to write the missing method(s), or did you really just jack all of that code and then ask us how to use it?
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote








|