如何用数学编写这个函数? [英] How do I write this function with math?

查看:87
本文介绍了如何用数学编写这个函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我得到了这个任务,要求我使用类,如果是周期广告(如果需要的话)。

So i got this assignment which requires me to use classes, if's ad for cycles(if needed).

1.Create a class called "Nail" that has variables for storing length and thickness. The store has three types of Nails. Find which nails are the longest and the thickest.





所以我完成了第一项任务。现在第二个我输了:





So i've done the first task. Now on the second im lost:

2.Create a class  called "Box" that stores variables for length, width and height of the box(already did this). You need to construct the box in which nails are hammered in every 10 cm if their length is 8 cm or every 15 cm if their length is 10 cm. Calculate how many nails are needed?







3.Add some variables in the "Box" class to the Insert () method, which allows you to change the size of the box - length, width and height. Of which
nails will be needed the most if we increase the box height "x" cm?





我真的需要一些帮助我失去了...我需要计算盒子的面积,至少这就是我的想法,idk也许是另一种计算所有这一切的方式...



所以继承我的代码;



I really need some help with this im lost...I need to calculate the area of the box, atleast thats how i think, idk maybe theres another way to calculate all of this...

So heres my code;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tss
{
    class Nail  //Dont pay attention to weigth
    {
        private int length, thickness, weight;

        public Nail(int naillength, int nailthickness, int nailweight)
        {
            length = naillength;
            thickness = nailthickness;
            weight = nailweight;
        }


        public int TakeLength() { return length; }

        public int TakeThickness() { return thickness; }

        public int TakeWeight() { return weight; }

    }
    class Box
    {
        private int length, wideness, height;

        public Box(int boxlength, int boxwideness, int boxheight)
        {
            length = boxlength;
            wideness = boxwideness;
            height = boxheight;
            length = int.Parse(Console.ReadLine());
            wideness = int.Parse(Console.ReadLine());
            height = int.Parse(Console.ReadLine());

        }


        public int TakeLength() { return length; }

        public int TakeWideness() { return wideness; }

        public int TakeHeight() { return height; }
    }
    class Calculations
    {
        static void Main(string[] args)
        {
            Nail p1;
            p1 = new Nail(8, 5, 4);
            Console.WriteLine("1st - nail length: {0,3:d} cm \n1st - nail thickness {1, 4:d} mm \n1st - nail weigth: {0,5:d} g",
                p1.TakeLength(), p1.TakeThickness(), p1.TakeWeight());

            Nail p2;
            p2 = new Nail(10, 6, 5);
            Console.WriteLine("2nd - nail length: {0,3:d} cm \n2nd - nail thickness: {1, 4:d} mm \n2nd - nail weigth: {0,5:d} g",
                p2.TakeLength(), p2.TakeThickness(), p2.TakeWeight());

            Nail p3;
            p3 = new Nail(12, 7, 6);
            Console.WriteLine("3st - nail length: {0,5:d} cm \n3 - nail thickness: {1, 4:d} mm \n3 - nail weigth: {0,5:d} g",
                p3.TakeLength(), p3.TakeThickness(), p3.TakeWeight());

            /// This finds the biggest value
            Console.WriteLine(Math.Max(Math.Max(p1.TakeLength(), p2.TakeLength()), p3.TakeLength()));
            Console.WriteLine(Math.Max(Math.Max(p1.TakeThickness(), p2.TakeThickness()), p3.TakeThickness()));

            Box d1;
            d1 = new Box(1, 1, 1);
            Console.WriteLine("Box length: {0,5:d} cm \nBox wideness: {1, 4:d} cm \nBox height: {0,5:d}cm",
                d1.TakeLength(), d1.TakeWideness(), d1.TakeHeight());

            }
        }
    }
}



还没有真正找到一种方法来计算多少钉子我需要..



我尝试过的事情:



试过一切。我只需要帮助我如何构建这个程序。


Havent really found a way how to calculate how many nails i need..

What I have tried:

Tried everything. I just need help on how i should build this program.

推荐答案

所以,你有盒子的长度,宽度和高度。从那里,你可以确定你需要钉钉的区域的长度。

假设你需要一个封闭的盒子,那么你需要将它钉在两个相对的两侧,沿着四个连接它们的剩余边缘。所以指甲的总长度将是

So, you have the length, width, and height of the box. From that, you can determine the "length" of the area you need to nail.
Assuming you need a closed box then you need to nail it all the way round two opposite sides, and along the four remaining edges which join them. So the "Total length" to nail will be
T = (H * 2 + L * 2) * 2 + 4 * W

然后看看你有什么指甲。这个问题只列出了两种尺寸:8厘米长,10厘米长,告诉你使用的间距。



你的工作是弄清楚要使用多少10厘米的指甲,以及多少8厘米的指甲。首先使用10厘米进入每个边缘,然后在没有足够的一侧进入另外10厘米的情况下用8厘米填补空隙。



尝试一下论文第一篇:应该更清楚。

Then look at what nails you have. The question only lists two sizes: 8cm long, and 10cm long and tells you what spacing to use.

Your job is to work out how many 10cm nails to use, and how many 8 cm nails. start by using the 10cm into each edge, then "fill in the gaps" with 8cm when there isn't enough side to get another 10cm in.

Try it on paper first: it should be clearer.


这篇关于如何用数学编写这个函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆