Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C# PROGRAM-- I need help with writing a c# - program that manages data using a 2

ID: 3863932 • Letter: C

Question

C# PROGRAM-- I need help with writing a c# - program that manages data using a 2 dimensional array of integers AND must be menu driven

A certain automobile dealership sells fifteen different models of automobiles and employs ten salesmen. A record of sales for each month can be represented by a table, the first row of which contains the number of sales of each model by salesman 1, the second row contains the number of sales of each model by salesman 2, and so on.

For example the sales table appears as follows:

0 0 2 0 5 6 3 1 3 4 3 3 1 0 2

5 1 9 0 0 2 3 2 2 3 1 4 6 2 1

0 0 0 1 0 0 0 3 1 6 2 1 7 3 2

1 1 1 0 2 2 2 5 2 7 4 2 8 2 1

5 3 2 0 0 0 5 2 1 2 6 6 6 1 4

4 2 1 0 1 1 0 4 4 1 5 5 1 2 1

3 2 5 0 1 2 0 1 3 5 4 3 2 1 2

3 0 7 1 3 5 1 0 6 8 2 2 3 2 1

0 2 6 1 0 2 2 1 1 2 1 5 4 3 0

4 0 2 3 2 1 3 2 3 1 5 4 0 1 0

The system should be menu driven with the following options also .

General Auto Sales

==================

1. Add a new sale

2. Sales Per Salesman by model

3. All Sales Per Salesman

4. All Sales For The Company

5. Exit

QUESTIONS:

1) You should be able to add a new sale.

--When this option is selected a screen pops up:

"Enter Transaction Code:"

A transaction code is a 4 character string. For example 0912 is a valid transaction code. The first two characters represent the salesman code , and the last two characters represent the automobile model code. Once the transaction code is entered at the above prompt, a verification is required check if the entered code is a valid one. If the code is invalid then an error message is displayed. If the entered code is a valid one, the value of the (9,12) location of the table must be incremented by 1. [Note: In C#, array indices start from 0. Therefore 0, 0 location is a valid location for a 2-D array. Therefore 0000 is a valid code.

2) Sales per salesman by model.-- If this option is selected, again, similar transaction code (as described in 1) is entered first. (The verification MUST be done for all options)

Suppose the code 0111 was entered. This is a valid code. This means salesman 01, 11th model. Read the (01,11) location of the 2-D array and display the following information.

Sales Representative Code : 01

Automobile Model : Mirage

Total Sold By This Representative : 4

3) All Sales Per Salesman. This is similar to option 2 except for that all models sold by that representative is displayed.

As an example , say the code 0809 was entered. This is also a valid code. The following information is displayed on the screen

Sales Representative Code : 08

Automobile Model Number Sold

-------------------------- -----------------

Camry 0

Corolla 2

And so forth.

4) Total Sales for the company : A monthly sales report must be produced in a form

Explanation / Answer

using System.IO;
using System;

class Program
{
static int row = 10; //number of salesperson
static int col = 15; //number of car model
  
static void add(int[,]arr,int code1,int sale)
{
int num=code1,temp,factor=1,i=0;
int [] code = new int[4];
temp=num;
  
//breaking code
while(temp!=0)
{
temp=temp/10;
factor = factor*10;
}
while(factor>1)
{
factor = factor/10;
code[i]=num/factor; // code is now strored in code[]
num = num % factor;
i++;
}
for(int j=0;j<4;j++)
Console.WriteLine((j+1)+". "+code[j]);
  
int salesman=code[0];
Console.WriteLine("Sales man is: "+salesman);
if(salesman>10) Console.WriteLine("ERROR: invalid salesman code :"+salesman+"!!!");
else
{
int automobile=(code[1]*10)+code[2];
Console.WriteLine("automobile is: "+automobile);
if(automobile>15) Console.WriteLine("ERROR: invalid automobile code :"+automobile+"!!!");
else
{
arr[salesman,automobile]=arr[salesman,automobile]+sale;
Console.WriteLine("Sale is increamented by "+sale);
  
}
}
Console.WriteLine("Updated Sales table is: ");
for (i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
Console.Write(arr[i,j]+ " ");
Console.Write(" ");
}
  
}
  
static void per_salesman(int [,]arr,int code1)
{
int num=code1,temp,factor=1,i=0;
int [] code = new int[4];
temp=num;
string[] model = new string[] {"Arash","Morgan","Prodrive","Brooke","David Brown","Bentley","Ultima","Jaguar","Marlin","Zenos Cars","Ginetta","Rolls-Royce","Land Rover","Westfield","Caparo" };
//breaking code
while(temp!=0)
{
temp=temp/10;
factor = factor*10;
}
while(factor>1)
{
factor = factor/10;
code[i]=num/factor; // code is now strored in code[]
num = num % factor;
i++;
}
for(int j=0;j<4;j++)
Console.WriteLine((j+1)+". "+code[j]);
  
int salesman=code[0];
Console.WriteLine("Sales Representative Code : "+salesman);
if(salesman>10) Console.WriteLine("ERROR: invalid salesman code :"+salesman+"!!!");
else
{
int automobile=(code[1]*10)+code[2];
//Console.WriteLine("automobile is: "+automobile);
if(automobile>15) Console.WriteLine("ERROR: invalid automobile code :"+automobile+"!!!");
else
{
Console.WriteLine("Automobile Model : "+model[automobile]);
Console.WriteLine("Total Sold By This Representative : "+arr[salesman,automobile]);
}
}
}
  
static void Main()
{
int[,] arr = new int[15,15]; //array to store matrix of model name and sales person
int ch;
int code1,len;
String code;
Random randNum = new Random();
for (int i = 0; i < row; i++) //to access number of sales person. intiallity there are 10 salespersons
{
for (int j = 0; j < col; j++)//to access number of car model
arr[i,j] = randNum.Next(0, 10);
}
  
//print the array matrix
Console.WriteLine("Sales table is: ");
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
Console.Write(arr[i,j]+ " ");
Console.Write(" ");
}
  
while(true)
{
Console.WriteLine(" General Auto Sales");
Console.WriteLine("==================");
Console.WriteLine("1. Add a new sale");
Console.WriteLine("2. Sales Per Salesman by model");
Console.WriteLine("3. All Sales Per Salesman");
Console.WriteLine("4. All Sales For The Company");
Console.WriteLine("5. Exit");
Console.WriteLine("Enter choice: ");
ch = int.Parse(Console.ReadLine());
if(ch==5) break;
switch(ch)
{
case 1: Console.WriteLine("Enter code: ");
code = Console.ReadLine();
len=code.Length;
if(len==4)
{
int.TryParse(code, out code1);
Console.WriteLine("Enter number of sale to increase: ");
int sale = int.Parse(Console.ReadLine());
add(arr,code1,sale);
}
else Console.WriteLine("ERROR: code is invalid!!!");
break;
case 2: Console.WriteLine("Enter code: ");
code = Console.ReadLine();
len=code.Length;
if(len==4)
{
int.TryParse(code, out code1);
per_salesman(arr,code1);
}
else Console.WriteLine("ERROR: code is invalid!!!");
break;
case 3:
break;
case 4:
break;
default:Console.WriteLine("Invalid Choice");
break;
}
}
  
}
}

will post 4th and 3rd code