I\'ve tried several different approaches to this and can\'t figure out how to wr
ID: 3566213 • Letter: I
Question
I've tried several different approaches to this and can't figure out how to write this code without errors. If you can help, I'd greatly appreciate it. Please submit the code in C#. Thank you.
Develop a C# console application that implements three arrays; a string array initialized with exactly the following five data items { "Widget 15.50", "Thingy 50.99", "Ratchet25.00", "Clanger115.49", "Fracker75.25" }, a string array to hold the five part names to be parsed from the previously detailed string array, an array of five double value prices to be parsed from the previously mentioned array.
Create a void method that will accept as arguments the two arrays of strings and the array of doubles when called from Main. In the method you will access the five members of the first string array mentioned above and you will parse out the name portion of each string element (first 7 bytes), assigning the string value to the corresponding element in the array of names. In the method you will also parse out the numeric portion of each string and assign it to the corresponding element of the price array. The parsing should be done using the string method SubString.
In Main, after calling the parsing method you will display the elements of both the array of names and the array of prices side-by-side (do not display the array from which you parsed the data items).
The output should look something like this:
Widget $15.50
Thingy $50.99
Ratchet $25.00
Clanger $115.49
Fracker $75.25
Press any key to continue . . .
Explanation / Answer
using System;
public class Parse
{
void parsing(string[] a,double[] b)
{
string[] name = new string[5]{ "Widget 15.50", "Thingy 50.99", "Ratchet25.00", "Clanger115.49", "Fracker75.25" };
int i=0;
for(i=0;i<5;i++)
{
a[i] = name[i].Substring(0,7);
b[i] = Convert.ToDouble(name[i].Substring(7,5));
Console.WriteLine(a[i]+" $"+b[i]);
}
}
public static void Main()
{
Parse o = new Parse();
string[] a = new string[5];
double[] b = new double[5];
o.parsing(a,b);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.