In: Computer Science
Question: Not sure how to proceed with question below:
In this task, task 2(a) will be extended so that an array of
five Person objects are created. Write the comma
separated values format of each object in separate lines in a file
named persons.txt. Make use of the
toString() method of Person to obtain comma separated values.
Create a hyperlink pointing to the file persons.txt and include it
on the task page. When the user clicks
on the link, the browser can then download it.
This is question 2a below: not need to be answered
Task 2: Chapter 14: page name=task2.php 40 marks
This task consists of two different subtasks.
(a) [15 marks]
Code a class named Person, which has three data properties to store
the name, a telephone number and
an e‐mail address of a person.
The class must have a constructor to initialise all three data
properties, three set methods and three get
methods to change and access the data properties of the
class.
The class must also have a toString() method with an argument named
$csv initialised to a default
boolean value true. By default, this function must return the value
of data properties in comma separated
values (refer to Chapter 23, Section named ‘How to read and write
CSV data’). On the other hand, if the
method is called with boolean value false, it returns a string
representation of the data properties in a
different format (for example, see showAll() method in Section ‘How
to loop through an object’s
properties’ in Chapter 14).
Create an object of the class Person, invoke all six set and get
methods, and invoke toString() with
both boolean values. Display the results returned by toString()for
both method calls.
I believe you are learning web development in PHP and OOPS at the same time, its great.
Why i said that, because my industrial exp says, web developers think using new frameworks and technologies is the only thing they should do.
Thats not good, i am happy that OOPS is your concern.
Now before answering, i would recommend you to be good with oops concepts
FIRST TASK, seems its independent but dont fall trap into the question lang, instead think unless u build a entity class for PERSON, how can you manage your task page,
Infact managing task page is just piece of cake,
Main thing here is how to design class PERSON thats your second task.
Lets work on it.
Now build a class with attributes given.
Class Person{
Private String name,
Private Long telephone,
Private String email,
//constructor to intialise,
Person(String name, String email, Long telephone) {
This. Name =name,
This. Email=email,
This. Telephone =telephone
}
//now gettters setters,
Public void setEmail(String Email) {
This email =email
}
Public void setName(String name) {
This.name =name
}
Public void setTelephone(Long telephone ) {
This telephone =telephone
}
Public void getName(){
Return this. Name
}
,
Public Void getEmail () {
Return this email
}
Public void getTelephone() {
Return this. Telephone
}
Public toString(csv = True) {
Now if you call this method with false value
Return string representation of data values in txt file
Otherwise,
Return comma separated values
}
}
Now to read text file, check out
<?php
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>
This part is easy go through w3schools you will get it.
Now make another class Test, where you should intialize 5 objects of class person
This is it, its an pseudo code implementation, of requirements, good thing about pseudocode is you can develop your logic in any langugae
As it is said, pseudocode never rusts.
Viola, congratulations you have learned how to generate pseudocode for OOPS programming.
I would suggest, leanr oops from geeksforgeeks you will be a better programmer.
Happy learning ??