Jump to content

Recommended Posts

Hey guys,

 

So long story short:

 

I've got an assignment due in two weeks time. I'm going away next weekend so want to finish it before then. Problem is, we haven't covered all the necessary material in class yet, and would be expected to work on it over the final weekend it is due. I have a partner for this, but he is of no use in any IT subject.

 

 

I would greatly appreciate if anyone could direct me to online tutorials or such, because I don't know how to do the following: construct the form so that the data can be written to a file in a way it can later be read, how to actually write this data to file, how to retrieve and read it.

 

 

The assignment in short:

 

Develop a form-based Web application that provides the following functionality:

o   Selection of a shape to develop

o   Creation of  a collection of shapes

o   Various user queries of your own choice

 

A system developed using object-oriented php which supports inter alia:

o   Various shapes

o   A collection of shapes

o   File I/O

 

 

The pitiful excuse I have so far gives me this: http://www.aberdonia.com/aberdonia/web-dev/coursework/testing/showshapes.php

Link to comment
https://forums.phpfreaks.com/topic/286654-a-little-advice-needed-with-oop/
Share on other sites

Post your code here.

 

Which part?  :sweat:

 

Do we get part of your tuition for teaching you what you are supposed to be learning?

 

Well in principle the same could be asked of any person in education/business that has a question and asks online, no?

 

Just to clarify, I'm not looking for anyone to write any actual code for me to use. Just would like some help understanding what direction I should be looking at, possible online resources or maybe even just some motivational support.  :tease-01:

 

Tl;dr, Unfortunately not!  :happy-04:

How about the showshapes.php file?

 

Okay, I'm trying front to back-end now.

 

As in trying to get the information entered into a form (shapecreationform), which is then posted to shapelcass.php. Simply trying to get the information at this stage to echo, but having enough trouble with that.

 

http://www.aberdonia.com/aberdonia/web-dev/coursework/shapecreationform.php

 

Code for the form:

 

<form method="post" action="shapeclass.php">
<table>
<?php
 

$shapes[0] = "first";
$shapes[1] = "second";
$shapes[2] = "third";
$shapes[3] = "fourth";
$shapes[4] = "fifth";
$shapes[5] = "sixth";
$shapes[6] = "seventh";
$shapes[7] = "eighth";

 
$tableRow = 0;
while($tableRow != 
{
echo ' 
<tr>
<th>Select</th>
<th>Choose Shape</th>
<th>Base Length</th>
<th>Height</th>
<th>Diameter</th>
<th>Side length</th>
<th>Colour</th>
</tr>
<td><input type="checkbox" name="checkboxes[]" /></td>
<td> 
<select name="shapes[]">
<option value="Square">Square</option>
<option value="Rectangle">Rectangle</option>
<option value="Rhombus">Rhombus</option>
<option value="Circle">Circle</option>
<option value="Triangle">Triangle</option>
<option value="Hexagon">Hexagon</option>
</select>
</td>
 
<td><input type="text" name="length[]" style="width:50px" /></td>
<td><input type="text" name="height[]" style="width:50px" /></td>
<td><input type="text" name="diameter[]" style="width:50px" /></td>
<td><input type="text" name="sidelength[]" style="width:50px" /></td>
<td><input type="text" name="colour[]" style="width:50px" /></td>
</tr>
';
$tableRow++;
}
?>
</table>
<input type="submit" value="Submit" name="submit" />
</form>
 
Code for shapeclass.php
 
<?php
 
class Shape
{
//Variables
protected $shapeType;
protected $colour;
 
//Constructor
public function __construct($shapeType, $colour)
{
$this->shapeType = $shapeType;
$this->colour = $colour;
}
}
 
$length == $_POST["length"];
$height == $_POST["height"];
$radius == $_POST["radius"];
$sides == $_POST["sides"];
 
for ($k = 0; $k < count($length); $k++)
{
echo "<p>Length is: " . $length[$k] . "</p>";
echo "<p>The shape has : " . $sides[$k] . "</p>";
echo "<p>The shape has : " . $sides[$k] . "</p>";
echo "<p>The shape has : " . $sides[$k] . "</p>";
echo "<p>The shape has : " . $sides[$k] . "</p>";
}
 
?>
Edited by KevinM1

1) You are declaring a class Shape but you are not using it?

2) You have one class Shape to represent all your shapes shows you haven't been paying attention in math 101 because assuming that for the squares and rectangle you have a method getSides() then what do you return for a circle? Similarly what do you return for getRadius() on a square?

 

You already have the form you simply have to add some validation and add the proper classes. For File I/O you can create a simple File object. Take a look here for the functions required to perform file operations:

 

http://php.net/manual/en/book.filesystem.php

 

I have no idea what is meant with collection of shapes perhaps a simple array?

 

$shapes = array(
  new Circle($radius),
  new Square(),
  new Rectangle(),
);
But as since these have no common ancestors it's hard to iterate over them and execute something meaningful on them. Edited by ignace

@TheNatalShark, please post your code in code tags, like ignace did in his snippet. You can do it either by clicking the <> button on our editor, or by manually placing your code within


tags. I've taken the liberty of doing it for you in your previous post.

 

$length == $_POST["length"];
$height == $_POST["height"];
$radius == $_POST["radius"];
$sides == $_POST["sides"];

 

The == performs a comparison between the right and left sides of the double-equals, not an assignment of the right side to the left.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.