This is for C# and using microsoft visual studios. Task is below I wrote a progr
ID: 3592160 • Letter: T
Question
This is for C# and using microsoft visual studios. Task is below
I wrote a program that is incomplete. Your task is to complete the program. Read the requirement carefully and work methodically--don't jump around--focus on one thing at a time. It may look scary but It shouldn't be too hard because I built the entire structure for you. Refer to the textbook chapters, videos, and ppt slides for help.
This quiz covers Chapters 5, 6, 7 and 8 in the textbook—Looping, Using Arrays, Using Methods, and Advanced Method Concepts, respectively. Your task for this quiz is to write a program. The requirements for your program are as follows:
Your program:
0. must download quiz2.cs and change namespace to Quiz_2_your_name
1. must implement a method/function called findElement() that accepts 2 arguments ([1] a string to search for and [2] an array to search) and, if the string is found in the array, returns the index where it is found (0...array.Length-1) or if string is not found, returns -1.
2. must implement a method/function called findElement() that accepts 2 arguments ([1] an integer to search for and [2] an array to search) and, if the integer is found in the array, returns the index where it is found (0...array.Length-1) or if integer is not found, returns -1.
3. must implement a method/function called findElement() that accepts 2 arguments ([1] a float to search for and [2] an array to search) and, if the float is found in the array, returns the index where it is found (0...array.Length-1) or if float is not found, returns -1.
4. must implement a method/function called sumElements() that accepts 1 argument (an integer array) and returns the sum.
5. must implement a method/function called sumElements() that accepts 1 argument (a float array) and returns the sum.
6. must add method calls in method Main() to invoke findElement() on the following arrays:
flowersAndFlowerBuds
poddedVegetables
bulbsAndStemVegetables
rootAndTuberousVegetables
seaVegetables
culinaryFruits
Hint: this is simple. Just copy similar code (lines 85-88) and update appropriately. Please add after line 88 and follow the list order to speed my turn-around time on grading.
Incomplete code:
using System;
namespace Quiz_2_Kevin_Kevin
{
class Program
{
public static readonly string[] vegetables =
{"amaranth","arugula","beet","bok choy", "borage","broccoli","brussell sprouts",
"cabbage","catsear","celery","celtuce","chaya","chickweed","chicory","chinese mallow",
"chrysanthemum leaves", "collard greens","common purslane","corn salad","cress","dandelion",
"dill","endive","fat hen","fiddlehead","fluted pumpkin","garden rocket","golden samphire",
"good King Henry","grape leaves","greater plantain","kai-lan","kale","Komatsuna","kuka",
"lagos bologi","lamb's lettuce","lamb's quarters","land cress","lettuce","lizard's tail",
"malabar spinach","melokhia","miner's lettuce","mizuna greens","mustard","Napa cabbage",
"New Zealand spinach","orache","pak choy","paracress","pea sprouts","poke","radicchio",
"rapini","samphire","sculpit","stridolo","sea beet","sea kale","Sierra Leone bologi",
"soko","sorrel","sour cabbage","spinach","summer purslane","swiss chard","tatsoi",
"turnip greens","watercress","water spinach","wheatgrass","yarrow","yao choy","shepher's purse"};
public static readonly string[] botanicalFruits =
{ "avocado","bell pepper","bitter melon","bitter gourd","chayote",
"cucumber","ivy gourd","eggplant","aubergine","brinjal","luffa","olive fruit","pumpkin","pineapple",
"squash","sweet pepper","tinda","tomatillo","tomato","vanilla","West Indian gherkin","winter melon",
"zucchini","courgette","marrow"};
public static readonly string[] flowersAndFlowerBuds =
{ "artichoke","broccoli","broccolini flowers","caper","cauliflower",
"daylily","courgette flowers","squash blossoms"};
public static readonly string[] poddedVegetables =
{ "American groundnut","azuki bean","black-eyed pea","chickpea",
"common bean","drumstick","dolichos bean","fava bean","garbanzo","green bean","guar",
"horse gram","India pea","lentil","lima bean","moth bean","mung bean","okra","pea",
"peanut","pigeon pea","ricebean","runner bean","snap pea","snow pea","soybean","tarwi",
"tepary bean","urad bean","velvet bean","winged bean","yardlong bean"};
public static readonly string[] bulbAndStemVegetables =
{ "asparagus","cardoon","celeriac","celery","chives",
"elephant garlic","Florence fennel","garlic","garlic chives","kohlrabi","kurrat",
"lemongrass","leek","lotus root","nopal","onion","pearl onion","potato onion",
"Prussian asparagus", "spring onion","scallion","shallot","tree onion","Welsh onion",
"wild leek","gau soon"};
public static readonly string[] rootAndTuberousVegetables =
{ "ahipa","arracacha","bamboo shoot","beetroot","burdock",
"broadleaf arrowhead","camas","canna","carrot","cassava","Chinese artichoke",
"daikon","Earthnut pea","elephant foot yam","ensete","galangal","ginger",
"Hamburg parsley","horseradish","Jerusalem artichoke","jicama","mashua","parsnip",
"pignut","potato","prairie turnip","radish","rutabaga","salsify","scorzonera",
"skirret","swede","sweet potato","taro","ti","tigernut","turmeric","turnip",
"ulluco","wasabi","water caltrop","water chestnut","yacon","yam"};
public static readonly string[] seaVegetables =
{ "aonori","arame","carola","dabberlocks","dulse","hijiki","kombu",
"laver","gim","mozuku","nori","ogonori","sea grape","sea lettuce","wakame"};
/*
* there are literally hundreds of culinary fruits
* ...I just included a sampling here.
*/
public static readonly string[] culinaryFruits =
{ "Acai","African moringa","Amazon tree-grape","American black elderberry",
"American grape","apple","banana","blueberry","cantaloupe","Chinese jujube","coconut",
"coffee","Cornelian cherry","Costa Rican guava","date","dragonfruit","Indian gooseberry",
"fig","gooseberry","grapefruit","Chilean guava","honeydew","Indian prune","jabuticaba",
"Korean melon","kumquat","lime","mango","nectarine","orange","pawpaw","peach","pear",
"quince","raspberry","rhubarb","Spanish lime","strawberry","tangerine","ugni","vanilla",
"watermelon","youngberry","zwetsche"};
public static readonly int[] integerArray = { 5, 76, 888, 4356, -7, -458, 44 };
public static readonly float[] floatArray = { 3.14159f, 42.4f, 3.3f, 98.6f, -987.0f, -200.0001f, 5_678.3f };
static void Main(string[] args)
{
Console.WriteLine("Brett Robblee's Quiz 2");
string findThis;
int index = -1;
findThis = "mustard";
index = findElement(findThis, vegetables);
if (index > -1)
Console.WriteLine("Found vegetable: {0}", vegetables[index]);
else
Console.WriteLine("{0} not found.", findThis);
/*
* Requirement #6 -- follow the instructions in the comments on lines 92-98
* Hint: this is easy because I already wrote the code. You just have to copy and adapt.
*/
// replicate lines 81-86 here and search and find an element in the flowersAndFlowerBud array
// search and find an element in the poddedVegetables array
// search and find an element in the bulbsAndStemVegetables array
// search and find an element in the rootAndTuberousVegetables array
// search and find an element in the seaVegetables array
// search and find an element in the culinaryFruits array
// search BUT DO NOT FIND an element in the culinaryFruits array to prove that your "else" code works.
index = findElement(-458, integerArray);
if (index > -1)
Console.WriteLine("Found integer: {0}", integerArray[index]);
index = findElement(3.14159f,floatArray);
if (index > -1)
Console.WriteLine("Found float: {0}", floatArray[index]);
Console.WriteLine("The sum of the elements in integerArray is {0}", sumElements(integerArray));
Console.WriteLine("The sum of the elements in floatArray is {0}", sumElements(floatArray));
}
/*
Requirement #1
must implement a method/function called findElement() that accepts 2 arguments ([1] a string to search for and [2] an array to search) and,
if the string is found in the array, returns the index where it is found (0...array.Length-1) or
if string is not found, returns -1.
*/
static int findElement(string element, string[] elementArray )
{
// your code here
return -1;
}
/*
Requirement #2
2. must implement a method/function called findElement() that accepts 2 arguments ([1] an integer to search for and [2] an array to search) and,
if the integer is found in the array, returns the index where it is found (0...array.Length-1) or
if integer is not found, returns -1.
*/
static int findElement(int element, int[] elementArray)
{
// your code here
return -1;
}
/*
Requirement #3
3. must implement a method/function called findElement() that accepts 2 arguments ([1] a float to search for and [2] an array to search) and,
if the float is found in the array, returns the index where it is found (0...array.Length-1) or
if float is not found, returns -1.
*/
static int findElement(float element, float[] elementArray)
{
//your code here
return -1;
}
/* Requirement #4
* must implement a method/function called sumElements() that accepts 1 argument (an integer array) and returns the sum.
*/
static int sumElements(int[] elementArray)
{
// your code here
return sum;
}
/* Requirement #5
* must implement a method/function called sumElements() that accepts 1 argument (a float array) and returns the sum.
*/
static float sumElements(float[] elementArray)
{
//your code here
return sum;
}
}
}
Explanation / Answer
Here ABC'D' is the bounding box.
After you're certain there's a collision, you need to check which above case it belongs to. If the bottom of the rectangle is above the center, then the first, if the top is above but the bottom is below, then it's the second case, and if the top is below the center, then it's the third.
If it's the first or the third case and the rectangle goes right (it has a positive velocity), then you need to set the center's x coordinate based on the algorithm:
where r is the radius of the circle.
If the rectangle is goes left (it has a negative x velocity), then the new center's x coordinate is
If it's the second case and the rectangle goes right, then the new center x is
And if it goes to left, the new x is
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.