using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace net1
{
public class inventory
{
public int partnumber;
public string description;
public string manufacture;
public double price;
public double shipping_cost;
public inventory()
{
}
public inventory(int partnumber_4, double price_4)
{
partnumber = partnumber_4;
price = price_4;
}
public inventory(int partnumber_1, double price_1, double shipping_cost_1)
{
partnumber = partnumber_1;
price = price_1;
shipping_cost = shipping_cost_1;
}
public inventory(int partnumber_1, string description_1, string manufacture_1, double price_1, double shipping_cost_1)
: this(partnumber_1, price_1, shipping_cost_1)
{
description = description_1;
manufacture = manufacture_1;
}
public virtual double total_price(int quantity)
{
return price * quantity;
}
public virtual double total_cost(double product_cost_1, double shipping_cost_1)
{
return product_cost_1 + shipping_cost_1;
}
public void user_entry()
{
tag1:
Console.WriteLine("enter part#");
try
{
partnumber = Convert.ToInt32(Console.ReadLine());
}
catch (Exception e1)
{
Console.WriteLine("invalid entry " + e1.Message);
goto tag1;
}
Console.WriteLine("enter part description");
description = Console.ReadLine();
Console.WriteLine("enter part manufacture");
manufacture = Console.ReadLine();
tag2:
Console.WriteLine("enter part unit price");
try
{
price = Convert.ToDouble(Console.ReadLine());
}
catch (Exception e2)
{
Console.WriteLine("invalid entry " + e2.Message);
goto tag2;
}
tag3:
Console.WriteLine("enter shipping cost");
try
{
shipping_cost = Convert.ToDouble(Console.ReadLine());
}
catch (Exception e3)
{
Console.WriteLine("invalid entry " + e3.Message);
goto tag3;
}
}
public void print()
{
Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", "partnumber", "price", "shipping_cost", "description", "manufacture");
Console.WriteLine("{0,-15}{1,-15:f2}{2,-15:f2}{3,-15}{4,-15}", partnumber, price, shipping_cost, description, manufacture);
}
}
public class used_product : inventory
{
public used_product()
{
}
public used_product(int partnumber_2, double price_2)
{
partnumber = partnumber_2;
price = price_2;
}
public override double total_price(int quantity)
{
return base.total_price(quantity) * 0.9; //used product 90% value
}
}
public class bulk_purchase : inventory
{
public bulk_purchase()
{
}
public bulk_purchase(int partnumber_3, double price_3)
{
partnumber = partnumber_3;
price = price_3;
}
public override double total_price(int quantity)
{
if (quantity < 10)
{
return base.total_price(quantity);
}
else if (quantity < 20)
{
return base.total_price(quantity) - 0.5 * quantity; //bulk purchase discount
}
else
{
return base.total_price(quantity) - quantity;
}
}
}
class Program
{
static void Main(string[] args)
{
/*inventory x = new inventory();
x.user_entry();
x.print();*/
/*inventory a = new inventory(1, 5);
used_product b = new used_product(2, 5);
bulk_purchase c = new bulk_purchase(3, 5);
Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", "unit price", "quantity", "regular cost", "used product cost", "bulk purchase cost");
for (int i = 0; i < 11; i++)
{
Console.WriteLine("{0,-15}{1,-15}{2,-15}{3,-15}{4,-15}", 5, i * 10, a.total_price(i * 10), b.total_price(i * 10), c.total_price(i * 10));
}*/
inventory[] y = { new inventory(5, 5), new inventory(6, 4), new inventory(3, 7), new inventory(8, 2), new inventory(1, 9) };
for (int i = 0; i < y.GetLength(0); i++)
{
y[i].print();
}
inventory[] xy = new inventory[y.GetLength(0) - 1];
xy = delete_part_number(y, 3);
for (int i = 0; i < xy.GetLength(0); i++)
{
xy[i].print();
}
inventory[] xyz = new inventory[y.GetLength(0)];
xyz = sort_by_part_number(y);
for (int i = 0; i < xyz.GetLength(0); i++)
{
xyz[i].print();
}
Console.ReadLine();
}
static public inventory[] sort_by_part_number(inventory[] x)
{
inventory[] sorted = new inventory[x.GetLength(0)];
for(int i=0; i<x.GetLength(0);i++) //copy into sorted
{
sorted[i] = new inventory();
sorted[i].partnumber=x[i].partnumber;
sorted[i].price=x[i].price;
}
for (int j = 0; j < sorted.GetLength(0); j++)
{
for (int i=0; i+j < sorted.GetLength(0); i++)
{
if (sorted[j].partnumber > sorted[i + j].partnumber)
{
swap(ref sorted[j],ref sorted[i + j]);
}
}
}
return sorted;
}
static public void swap(ref inventory x,ref inventory y)
{
int partnumber_temp = x.partnumber;
double price_temp = x.price;
x.partnumber = y.partnumber;
x.price = y.price;
y.partnumber = partnumber_temp;
y.price = price_temp;
}
static public inventory[] delete_part_number(inventory[] x, int part) //delete part # from inventory
{
inventory[] new_inventory = new inventory[x.GetLength(0) - 1];
for (int j = 0; j < new_inventory.GetLength(0); j++)
{
new_inventory[j] = new inventory();
}
for (int i = 0; i < x.GetLength(0) - 1; i++)
{
if (part == x[i].partnumber)
{
for (; i < x.GetLength(0) - 1; i++)
{
new_inventory[i].partnumber = x[i + 1].partnumber;
new_inventory[i].price = x[i + 1].price;
}
return new_inventory;
}
new_inventory[i].partnumber = x[i].partnumber;
new_inventory[i].price = x[i].price;
}
return new_inventory;
}
}
}
No comments:
Post a Comment