首页 \ 问答 \ 我怎么能做我的类的对象数组(继承另一个自定义类)?(How can I do an array of object of my class (with inheritance of another custom class)? [closed])

我怎么能做我的类的对象数组(继承另一个自定义类)?(How can I do an array of object of my class (with inheritance of another custom class)? [closed])

我必须做这个小程序的作业:

该计划必须管理玩具代理。 以下行是具体内容:

  1. 玩具必须具有唯一的代码,名称,类别(可以具有此价值:汽车,娃娃装,电子玩具,机器人,购物车,桌游),价格;
  2. 批次必须有一个独特的代码,插入批次的玩具清单,现在可用的批次类型的数量,数据生成;
  3. 玩具必须存储在名为“toys.txt”的文本文件中,而批次必须存储在大小为10.000的数组中;

我如何实现第[3]点的第二部分?

我用这个字段实现了一个名为Toy的类:

  • int code
  • string name
  • enum category {car, ....}
  • double price

之后,我用这个字段实现了第二个名为Lot的类:

  • int code
  • int numberOfLotAvaiable
  • string data
  • Toy toys

“必须存储大小为10.000的数组”我是否必须在类Lot中添加一个带有数组的字段? 或者我是否必须在Main方法中执行Lot类型的数组? 甚至,我还要做其他课吗?

感谢您提供各种帮助!


I have to do for homework this little program:

The program have to manage an agency of toys. The following line are the specifics:

  1. Toys must have a unique code, a name, a category (that can have this value: car, babydoll, electronic toy, robot, peluche, boardgame), price;
  2. The lots must have a unique code, the list of toys which are inserted in the lot, the number of the lot-type now avalaible, data production;
  3. Toys must be storaged in a text file called 'toys.txt', while lots must be storaged in an size-10.000 array;

How can I implement the second part of point [3]?

I have implement a class called Toy with this field:

  • int code
  • string name
  • enum category {car, ....}
  • double price

After that, I have implement a second class called Lot with this field:

  • int code
  • int numberOfLotAvaiable
  • string data
  • Toy toys

"lots must be storaged in an size-10.000 array" Do I have to add a field in class Lot with an array? Or Do I have to do an array of type Lot in the Main method ? Even, Do I have to do an other class?

Thank you in advantage for all kind of help!


原文:https://stackoverflow.com/questions/17504275
更新时间:2022-10-20 15:10

最满意答案

这是一个PHP解决方案,其中下面的整个代码将在同一个文件中使用。

您现在的代码似乎缺少一些东西,例如<table></table><form></form>标签,以及提交按钮。

另外,(表单)选择需要“名称”属性; 你不能单靠一个“id”。

<form action="" method="post">
<table border="1">
    <td><center>
            <select name="row7">
            <option value = "0" selected>0</option>
            <option value = "1" >1</option>
            <option value = "2" >2</option>
      </select>
    </td>
    <td><center>
         <select name="row8" class="Drops">
            <option value = "0" selected>0</option>
            <option value = "1">1</option>
            <option value = "2">2</option>
        </select>
       </td>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// error_reporting(0);

if(isset($_POST['submit']) && isset($_POST['row7']) && isset($_POST['row8'])){

                $var7 = (int)$_POST['row7'];
                $var8 = (int)$_POST['row8'];

                $total2 = (int)$var7+$var8;
// echo $total2;
}
?>
     <td><center><textarea name='row12' cols='2' rows='1' readonly='true'>
     <?php if(!empty($total2)) { echo (int)$total2; } ?>
     </textarea></center></td>
    </table>

<input type="submit" name="submit" value="ADD">

</form>

Here is a PHP solution, where the entire code below is to used inside the same file.

Your present code seems to be missing a few things, such as <table></table> and <form></form> tags, as well as a submit button.

Plus, the (form) selects require a "name" attribute; you cannot rely on an "id" alone.

<form action="" method="post">
<table border="1">
    <td><center>
            <select name="row7">
            <option value = "0" selected>0</option>
            <option value = "1" >1</option>
            <option value = "2" >2</option>
      </select>
    </td>
    <td><center>
         <select name="row8" class="Drops">
            <option value = "0" selected>0</option>
            <option value = "1">1</option>
            <option value = "2">2</option>
        </select>
       </td>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// error_reporting(0);

if(isset($_POST['submit']) && isset($_POST['row7']) && isset($_POST['row8'])){

                $var7 = (int)$_POST['row7'];
                $var8 = (int)$_POST['row8'];

                $total2 = (int)$var7+$var8;
// echo $total2;
}
?>
     <td><center><textarea name='row12' cols='2' rows='1' readonly='true'>
     <?php if(!empty($total2)) { echo (int)$total2; } ?>
     </textarea></center></td>
    </table>

<input type="submit" name="submit" value="ADD">

</form>

相关问答

更多