With C#, use a rectangular array to solve the following problem: A company has t
ID: 3557351 • Letter: W
Question
With C#, use a rectangular array to solve the following problem: A company has three salespeople (1 to 3) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each type of product sold. Each slip contains the following:
a. The salesperson number
b. The product number
c. The total dollar value of the product sold that day
Thus, each salesperson passes between 0 and 5 slips per day. Assume that the information from all of the slips from last month are available. Write an app that will read all the information for last months sales and summarize the total sales by salesperson and by product. All totals should be stored in rectangular array sales. After processing all the information for last month, display the results in tabular format, with each column representing a particular salesperson and each row representing a particular product. Cross total each row to get the total sales of each product for last month. Cross total each column to get the total sales by salesperson for last month. Your tubular output should include these cross totals to the right of the totaled row and below the totaled columns.
Explanation / Answer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
int n,i=1,salesPerNo,ProdNo,totDoll;
int[,] arr=new int[5,3];
for (int k = 0; k < 5; k++)
{
for (int j = 0; j < 3; j++)
{
arr[k, j] = 0;
}
}
Console.WriteLine("Enter no of slips");
n=int.Parse(Console.ReadLine());
while (i <= n)
{
Console.WriteLine("Enter values for SlipNo:" + i + "=");
Console.Write("Sales Person No=");
salesPerNo = int.Parse(Console.ReadLine());
Console.Write("Product NO=");
ProdNo = int.Parse(Console.ReadLine());
Console.Write("Total dollar value=");
totDoll = int.Parse(Console.ReadLine());
arr[ProdNo-1, salesPerNo-1] = arr[ProdNo-1, salesPerNo-1] + totDoll;
i++;
}
Console.WriteLine("salesPNO/PNO 1 2 3 sum");
Console.WriteLine(" 1 "+arr[0,0]+" "+arr[0,1]+" "+arr[0,2]+" "+(arr[0,0]+arr[0,1]+arr[0,2]));
Console.WriteLine(" 2 " + arr[1, 0] + " " + arr[1, 1] + " " + arr[1, 2] + " " + (arr[1, 0] + arr[1, 1] + arr[1, 2]));
Console.WriteLine(" 3 " + arr[2, 0] + " " + arr[2, 1] + " " + arr[2, 2] + " " + (arr[2, 0] + arr[2, 1] + arr[2, 2]));
Console.WriteLine(" 4 " + arr[3, 0] + " " + arr[3, 1] + " " + arr[3, 2] + " " + (arr[3, 0] + arr[3, 1] + arr[3, 2]));
Console.WriteLine(" 5 " + arr[4, 0] + " " + arr[4, 1] + " " + arr[4, 2] + " " + (arr[4, 0] + arr[4, 1] + arr[4, 2]));
Console.Write(" Sum= " + (arr[0, 0] + arr[1, 0] + arr[2, 0] + arr[3, 0] + arr[4, 0]));
Console.Write(" " + (arr[0, 1] + arr[1, 1] + arr[2, 1] + arr[3, 1] + arr[4, 1]));
Console.Write(" " + (arr[0, 2] + arr[1, 2] + arr[2, 2] + arr[3, 2] + arr[4, 2]));
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.