Question

In: Computer Science

A company has three salespeople (1 to 3) who sell five different products (1 to 5)....

A company has three salespeople (1 to 3) who sell five different products (1 to 5). Once a day, each saleperson 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 that product sold that day Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month is available. You are required to write a C# program that will read all the information for last month’s sales and summarize the total sales by salesperson and by product. All sales data should be stored in a two-dimensional 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. You tabular output should include these cross-totals to the right of the totaled rows and below the totaled columns.

A sample output is as follows:

Enter sales person number (-1 to end): 1

Enter product number: 100

Enter sales amount: 1000

Invalid input!

Enter sales person number (-1 to end): 1

Enter product number: 1

Enter sales amount: 100

Enter sales person number (-1 to end): 1

Enter product number: 3

Enter sales amount: 200

Enter sales person number (-1 to end): 1

Enter product number: 5

Enter sales amount: 300

Enter sales person number (-1 to end): 2

Enter product number: 2

Enter sales amount: 400

Enter sales person number (-1 to end): 2

Enter product number: 4

Enter sales amount: 500

Enter sales person number (-1 to end): 3

Enter product number: 1

Enter sales amount: 600

Enter sales person number (-1 to end): 3

Enter product number: 2

Enter sales amount: 700

Enter sales person number (-1 to end): 3

Enter product number: 3

Enter sales amount: 800

Enter sales person number (-1 to end): -1

Product Salesperson 1 Salesperson 2 Salesperson 3 Total

1 $100.00 $0.00 $600.00 $700.00

2 $0.00 $400.00   $700.00 $1,100.00

3 $200.00 $0.00 $800.00 $1,000.00

4 $0.00 $500.00 $0.00 $500.00

5 $300.00 $0.00 $0.00   $300.00

Total $600.00 $900.00 $2,100.00

Solutions

Expert Solution

Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
namespace Sales
{
class Program
{
static int numOfPerson = 3;
static int numProduct = 5;
static void Main(string[] args)
{
double[,] monthSales = new double[5, 3] { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
double salesAmount;
int productNumber,personNumber;
while (true)
{
Console.Write("Enter sales person number (-1 to end): ");
personNumber = Convert.ToInt32(Console.ReadLine());
if(personNumber==-1)
break;
Console.Write("Enter product number: ");
productNumber = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter sales amount: ");
salesAmount = Convert.ToInt32(Console.ReadLine());
if (personNumber <=3 && (productNumber >= 1 && productNumber <= 5))
{
monthSales[productNumber - 1, personNumber - 1] = salesAmount;
}
else
Console.WriteLine("Invalid input");
}
printSales(monthSales);
}

private static void printSales(double[,] monthSales)
{
int i, j;
double [] personTotalSales=new double[numOfPerson];
Console.WriteLine("\n\n");
Console.WriteLine(String.Format("{0,-5}| {1,-10} | {2,-10} | {3,-10} | {4,14}","Product","Salesperson 1","Salesperson 2","Salesperson 1","Total"));
for (i = 0; i < numProduct; i++)
{
double sum = monthSales[i, 0] + monthSales[i, 1] + monthSales[i, 2];
Console.WriteLine(String.Format("{0,7}| {1,13} | {2,13} | {3,13} | {4,13}", (i + 1), monthSales[i, 0].ToString("C", new CultureInfo("en-US")), monthSales[i, 1].ToString("C", new CultureInfo("en-US")), monthSales[i, 2].ToString("C", new CultureInfo("en-US")), sum.ToString("C", new CultureInfo("en-US"))));
}
Console.WriteLine("----------------------------------------------------------------------");
for (j = 0; j < numOfPerson; j++)
{
personTotalSales[j] = monthSales[0, j] + monthSales[1, j] + monthSales[2, j] + monthSales[3, j] + monthSales[4, j];
}
Console.WriteLine(String.Format("{0,7}| {1,13} | {2,13} | {3,13} ", "Total", personTotalSales[0].ToString("C", new CultureInfo("en-US")), personTotalSales[1].ToString("C", new CultureInfo("en-US")), personTotalSales[2].ToString("C", new CultureInfo("en-US"))));
}
}
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.


Related Solutions

IN JAVA A salesman wants to go to five different cities and sell some products. The...
IN JAVA A salesman wants to go to five different cities and sell some products. The locations of the cities are listed in the following table. City # X_location Y_location City 1 1 1 City 2 1 3 City 3 4 1 City 4 5 3 City 5 3 5 The distance between two cities is defined as the Euclidean distance. That is: Distance = sqrt( (x1 – x2)^2 + (y1 – y2)^2 ) For example, the distance between cities...
A company pays its five salespeople on a commission basis. The salespeople receive $200 plus 10%...
A company pays its five salespeople on a commission basis. The salespeople receive $200 plus 10% of their sale. For example, for the employee sale of $1000, the commission is $300. Write a C program that: inputs each employee sales. The program then calculates the employee commission, prints out each employee commission. The program calculates the total sum of all commissions paid, and print. Your program will use a sentinel value to exit. You must use a one-dimensional array for...
Why might a company sell its products for different prices in different markets even if the...
Why might a company sell its products for different prices in different markets even if the income levels of its target consumers were the same in all cases?
Rosie’s Company has three products, P1, P2, and P3. The maximum Rosie’s can sell is 76,000...
Rosie’s Company has three products, P1, P2, and P3. The maximum Rosie’s can sell is 76,000 units of P1, 57,000 units of P2, and 45,000 units of P3. Rosie’s has limited production capacity of 42,000 hours. It can produce 12 units of P1, 6 units of P2, and 3 units of P3 per hour. Contribution margin per unit is $5 for the P1, $15 for the P2, and $25 for the P3. What is the most profitable sales mix for...
Find five (5) different preserved foods in your fridge and/or cupboard that represent five (5) different...
Find five (5) different preserved foods in your fridge and/or cupboard that represent five (5) different types of food preservation. Provide a picture of that product and briefly discuss what methods were employed to maintain product freshness and safety/hygiene. Please make sure you have a mix of both physical and chemical preservation methods
A sample of 15 consumers provided the following product ratings for three different products. Five consumers...
A sample of 15 consumers provided the following product ratings for three different products. Five consumers were randomly assigned to test and rate each product. Product A B C 53 83 63 60 99 49 79 91 33 41 82 51 69 93 52 Use the Kruskal-Wallis test and α = 0.05 to determine whether there is a significant difference among the ratings for the products. State the null and alternative hypotheses. H0: MedianA = MedianB = MedianC Ha: MedianA...
A sample of 15 consumers provided the following product ratings for three different products. Five consumers...
A sample of 15 consumers provided the following product ratings for three different products. Five consumers were randomly assigned to test and rate each product. Product A B C 51 81 61 66 90 40 70 99 31 49 87 59 60 91 57 Use the Kruskal-Wallis test and α = 0.05 to determine whether there is a significant difference among the ratings for the products. (a). State the null hypothesis (b). Find the value of the test statistic (c)....
6-A3 Joint Products: Sell or Process Further The Mussina Chemical Company produced three joint products at...
6-A3 Joint Products: Sell or Process Further The Mussina Chemical Company produced three joint products at a joint cost of $117,000. These products were processed further and sold as follows: Chemical Product Sales Additional Processing Costs A $230,000 $190,000 B $330,000 $300,000 C $175,000 $100,000 The company has had an opportunity to sell at split-off directly to other processors. If that alternative had been selected, sales would have been A, $54,000; B, $32,000; and C, $54,000. The company expects to...
QUESTION 5. Company X wants to procure products from two different suppliers it has determined, but...
QUESTION 5. Company X wants to procure products from two different suppliers it has determined, but has doubted the quality of these suppliers' products. For this reason, he took random samples from both suppliers before placing their exact orders. He bought 50 products randomly from supplier A, and their average survival time was 153 hours and standard deviation was 10 hours. The average duration of 50 products bought from supplier B was 150 hours and the standard deviation was 5...
A manufacturing company produces products at three factories designated as numbers 1, 2, and 3. The...
A manufacturing company produces products at three factories designated as numbers 1, 2, and 3. The products are shipped to two demand destinations designated as A and B. For the coming month, production will be: Factory 1 = 3,000 units; Factory 2 = 2,500 units; and Factory 3 = 4,200 units. And for the coming month, demand will be: Destination A = 4,500 units and Destination B = 6,000 units. Which of the following is a correct linear programming constraint...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT