Language: C# Please be as explicit as possible into the algorithm of the program
ID: 3886843 • Letter: L
Question
Language: C#
Please be as explicit as possible into the algorithm of the program!
Thanks!!!
a. Create a rectangular multidimensional array of type double. b. Your array shall accommodate up to 50 rows and 20 columns c. Create a console program that: i. Asks the user which account (row) to work with: (1 - 50) ii. Each row is treated as a separate "account" of numbers. iii. Accepts up to 19 values for the selected account/row. iv. Stop accepting values when the user: 1. enters 0, or 2. user enters 19 values v. The 20^th column will hold the sum of the numbers in the precious 19 columns for that row. vi. Remember: each row is an account, and every account keeps 19 column values, and a total in the last column vii. When the user chooses 0 for the account/row, stop accepting user input and write out the entire spreadsheet to a file call, "spreadsheet.dat"Explanation / Answer
Ans :
using System;
using System.Diagnostics;
using System.IO;
namespace MyArrayApplication
{
class MyArray
{
static void Main(string[] args)
{
const string fileName = "spreadsheet.xls"; //spreadsheet name
string userInput;
int row_no,i;
double sum = 0;
double[,] array = new double[50,20];
Spreadsheet spreadsheet = new Spreadsheet();//create a new Spreadsheet
Console.Write("Choose account row (1-50) : ");
userInput = Console.ReadLine();
row_no = Convert.ToInt32(userInput);
Console.WriteLine(" Enter element in account({0})",row_no);
for(i=1;i<19;i++)
{
userInput = Console.ReadLine();
array[row_no,i] = Convert.ToInt32(userInput);
if(array[row_no,i]==0)
{
break;
}
sum += array[row_no,i];
}
array[row_no,19] = sum;
spreadsheet.ImportFrom2DArray(array); //get the data from array
if (File.Exists(fileName)) File.Delete(fileName);
spreadsheet.SaveAs(fileName);//save the spreadsheet
spreadsheet.Close();//close spreadsheet
Process.Start(fileName);//open spreadsheet
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.