Логистика JS
<script> class box{ constructor(width,length,height,mass,cost,price,description,id,sendDate,sender,accepter){ this.wi=width; this.le=length; this.he=height; this.ma=mass; this.co=cost; // ценность this.pr=price; // стоимость this.de=description; this.id=id; this.da=sendDate; this.se=sender; this.ac=accepter; } } var pack=Array(); pack[0]=new box(0.3,0.5,0.1,1.5,200.15,30,"Hamster","02350002243890","2017-11-02","TPT, 10135, Eesti, Harjumaa, Tallinn, Pärnu mnt 57","TPT, 10135, Eesti, Harjumaa, Tallinn, Pärnu mnt 57") pack[1]=new box(0.3,0.5,0.1,3.5,10.56,50,"Gold","02350002243832","2017-10-15","Estonia Bank","Findland Bank") pack[2]=new box(0.3,0.5,0.1,0.5,53.14,100,"Silver","02350002243891","2017-06-22","Findland Bank","Estonian bank") pack[3]=new box(0.3,0.5,0.1,1,5000.30,120,"t-shirts","02350002243891","2017-11-15","Aliexpress","TPT, 10135, Eesti, Harjumaa, Tallinn, Pärnu mnt 57") N=pack.length; totalMass=0; for(i=0; i<N; i++){ totalMass+=pack[i].ma; } alert("Общая масса груза: "+totalMass+"кг"); C=pack.cost; totalCost=0; for(i=0; i<N; i++){ totalCost+=pack[i].co; } alert("Общая ценность груза: "+totalCost+"евро"); P=pack.price; totalPrice=0; for(i=0; i<N; i++){ totalPrice+=pack[i].pr; } alert("Общая стоимость груза: "+totalPrice+"евро"); </script> Задачи: 1) Посчитать общий объём 2) Посчитать удельную ценну сумма цен доставки/на общую массу 3) Посчитать общую плотность груза 4) Посчитать плотность каждого груза отдельно 5) Посчитать удельную ценну сумма цен доставки/на общий объём 6) Самую ранюю посылку и самую позднию 7) Самый дешёвый, самый дорогой. |
Цитата:
|
Цитата:
|
Я надеялся, что есть добрые, которые и так помогут.
|
JetBlack, это называется не "помогут", а "выполнят работу за меня".
|
Вот маленький пример, а дальше сами, все можно сделать без циклов
class box{ constructor(width,length,height,mass,cost,price,description,id,sendDate,sender,accepter){ this.wi=width; this.le=length; this.he=height; this.v = (width * length * height); // объём this.ma=mass; this.co=cost; // ценность this.pr=price; // стоимость this.de=description; this.id=id; this.da=sendDate; this.se=sender; this.ac=accepter; box.amount += this.v; box.totalSum += price; } } var pack=Array(); box.amount = 0; box.totalSum = 0; pack[0]=new box(0.3,0.5,0.1,1.5,200.15,30,"Hamster","02350002243890","2017-11-02","TPT, 10135, Eesti, Harjumaa, Tallinn, Pärnu mnt 57","TPT, 10135, Eesti, Harjumaa, Tallinn, Pärnu mnt 57"); pack[1]=new box(0.3,0.5,0.1,3.5,10.56,50,"Gold","02350002243832","2017-10-15","Estonia Bank","Findland Bank"); pack[2]=new box(0.3,0.5,0.1,0.5,53.14,100,"Silver","02350002243891","2017-06-22","Findland Bank","Estonian bank"); pack[3]=new box(0.3,0.5,0.1,1,5000.30,120,"t-shirts","02350002243891","2017-11-15","Aliexpress","TPT, 10135, Eesti, Harjumaa, Tallinn, Pärnu mnt 57"); // Тут общий объем alert("Общий объём "+box.amount); N=pack.length; totalMass=0; for(i=0; i<N; i++){ totalMass+=pack[i].ma; } alert("Общая масса груза: "+totalMass+"кг"); //Тут удельная цена, по вашему коду alert("Удельная цена: "+ (box.totalSum/totalMass)); C=pack.cost; totalCost=0; for(i=0; i<N; i++){ totalCost+=pack[i].co; } alert("Общая ценность груза: "+totalCost+"евро"); P=pack.price; totalPrice=0; for(i=0; i<N; i++){ totalPrice+=pack[i].pr; } alert("Общая стоимость груза: "+totalPrice+"евро"); |
Часовой пояс GMT +3, время: 15:29. |