INSTRUCTIONS AND INFORMATION
Once extracted, the following list of files will be available in the folder DataSept2020:
Question 1:
Question1_u.pas
Question1_u.dfm
Question1_p.dpr
Question1_p.res
Question 2:
Trees.jpg
Question2ClassDefinition.pas
Question2_u.pas
Question2_u.dfm
Question2_p.dpr
Question2_p.res
Question 3:
dbConnection_u.pas
WasteDisposal.mdb
WasteDisposalBackup.mdb
Question3_u.pas
Question3_u.dfm
Question3_p.dpr
Question3_p.res
Question 4:
waste.txt
Question4_u.pas
Question4_u.dfm
Question4_p.dpr
Question4_p.res
QUESTION 1: GENERAL PROGRAMMING SKILLS
Do the following:
Your school has created a club to provide information and conduct research on various environmental issues. Complete the program for the club by using the instructions below.
1.1 Button [1.1 Display Club name]
Write code in the Q1.1 event handler to do the following:
Example of output:
1.2 Button [1.2 Process]
Your school has collected paper, plastic and glass for recycling. The program in the Question 1 folder contains components to keep track of how much the monetary value is for each type of waste material that has been collected. A user will choose a waste material type and then enter the weight for that product. The refund value in Rands for each waste material type must be added up and displayed on the panels provided for paper, plastic and glass.
Write code to do the following:
The total price paid for each waste material must be calculated as follows:
Use the following data to test your solution:
Material | Weight in g | Weight in kg | Monetary value |
Paper | 356 | 0 | R 0 |
Paper | 1785 | 1 | R 25 |
Paper | 2356 | 2 | R 50 |
Plastic | 3500 | 3 | R 105 |
Plastic | 7854 | 7 | R 245 |
Glass | 1000 | 1 | R 40 |
Glass | 3745 | 3 | R 120 |
Example of output after entering the data in the table above: (16)
1.3 Button [1.3 Test for leap year]
A leap year has 366 days instead of 365 days. Write code in the onclick event of Q1.3 button to test if a year entered is a leap year.
To check whether a year is a leap year or not, you need to check the following 3 conditions:
Do the following:
Example of output:
Data to test your solution:
Leap years from 2004 to 2044:
2004
2008
2012
2016
2020
2024
2028
2032
2036
2040
2044
(12)
1.4 Button [1.4 Lucky letters]
Lucky prizes will be awarded to members of the club at a meeting.
Every third letter of the alphabet will be the first letter of the surnames of the winners, starting with the letter ‘A’.
Write code in the onclick event of Q1.4 button to display 9 letters of the alphabet, using the rule described above, in the richedit named reddisplay.
NOTE: String handling and iteration (loops) must be used.
Example of output: (6)
QUESTION 2: OBJECT-ORIENTED PROGRAMMING
A global organisation named ‘The Tree Project’ has branches around the world. A program is supplied in the QUESTION 2 folder to document the number of trees and workers as well as to calculate the monetary funds required to run this project in a particular country. |
Do the following:
The following user interface is displayed:
Complete the code for this program, as specified in QUESTION 2.1 and QUESTION 2.2.
2.1 The incomplete class (Tcountry) contains the declaration of five attributes that describe the objcountry object.
NAMES OF ATTRIBUTES | DESCRIPTION |
fcountry | The name of the country |
fleader | The name of the leader for the tree project in a country |
ftrees | The number of trees to be planted |
ffunds | The money required to run the project |
fassistants | The number of people working on the project |
Complete the code in the object class, as described in QUESTION 2.1.1 to QUESTION 2.1.4 below.
2.1.1 Write code for a constructor method named Create that will receive the name of a country and the name of a leader as parameters.
Assign these parameter values to the correct attributes and initialise the attributes for the number of trees and assistants to zero.(5)
2.1.2 Write code for a method named calculatefunds which must use the attributes named ftrees and fassistants to calculate and return the amount of funding needed for the tree project.
The funds are calculated as follows:
Example:
6 assistants and 100 trees: Cost of project = R250 + R600 + R200 = R1050 (6)
2.1.3 Write code for a method named addnumbers that will receive two integer parameters which will each represent the number of trees and the number of assistants with which you will increase the attributes of the class.
Set the value of the attributes as described below:
2.1.4 Write code for a method named tostring which must return a string.
The string must contain the attributes of the class joined together in the following format:
<country name>
<leader name> and <number of assistants > assistants
<number of trees> trees
Funds: <amount of funds required in Rands>
Example of output:
(8)
2.2 An incomplete unit Question2_u.pas has been provided.
It contains code for the object class to be accessible and has a global object variable, objcountry, already declared.
Do NOT delete or change any provided code.
Follow the instructions below to code the solution.
2.2.1 Button Q2.2.1
The user will enter a country name and a leader name in the provided edit boxes named edtcountry and edtleader.
Write code to do the following:
2.2.2 Button Q2.2.2
Write code to receive the input from the spinedits named sedtrees and sedassistants.
Use the methods of the class to do the following:
Example of output:
Joseph Mcuba as leader in South Africa starting with 30 trees and 5 assistants:
5 trees and 1 assistant added to the South African team with Joseph Mcuba as leader:
(8)
QUESTION 3: DATABASE PROGRAMMING
The database WasteDisposal.mdb contains the details of waste materials and disposal methods of a waste management company that manages the permanent removal of all waste for a city. The database contains two tables, namely Material and Disposal.
Table: Disposal
This table contains the methods of disposal of waste.
Field name | Data type | Description |
Disposalcode | Number – Long Integer | A unique number assigned to each profile |
DisposalMethod | Text (50) | The name of the method of waste disposal |
Employees | Number – Long Integer | The number of people required to carry out the disposal method |
Example of data in the Disposal table:
Disposal | ||
Disposalcode | DisposalMethod | Employees |
1 | Recycled | 120 |
2 | Reused | 320 |
3 | Landfill | 11 |
4 | Recoveredforenergy | 24 |
5 | Compostedonsite | 4 |
6 | Compostedoffsite | 10 |
Table: Material
This table contains information of all the waste materials that have been disposed of by the waste management company.
Field name | Data type | Description |
MaterialID | Autonumber | A unique number assigned to the material |
Materialtype | Text (50) | The different types of waste materials |
Datedisposed | Date/Time | Date that the last disposal took place |
Quantity | Number (long integer) | Weight in Tons that was last disposed on the date described in the Datedisposed field |
Greenhousefactor | Number (Double) | Carbon dioxide gas emissions factor for landfills. This number will be multiplied by the tonnage of the material, which results in the total carbon dioxide emission |
Disposalcode | Number (long integer) | Foreign key to connect to the Disposal table |
Example of data of the first ten records of the Material table.
Material | |||||
MaterialID | Materialtype | Datedisposed | Quantity | Greenhousefactor | Disposalcode |
1 | Plasticcontainers | 2019/10/02 | 85 | 0 | 1 |
2 | Plasticbags | 2019/09/28 | 26 | 0 | 1 |
3 | Polystyrene | 2019/07/31 | 45 | 1,8 | 3 |
4 | Glassbottlesbroken | 2019/09/18 | 74 | 0 | 1 |
5 | Glassbottlesnotbroken | 2019/07/10 | 25 | 0 | 2 |
6 | Aluminiumcanswhole | 2019/10/27 | 22 | 0 | 1 |
7 | Aluminiumcansflattened | 2019/08/13 | 14 | 0 | 1 |
8 | AluminiumcansBales | 2019/10/02 | 56 | 0 | 1 |
9 | Steelcanswhole | 2019/08/11 | 98 | 0 | 1 |
10 | Steelcansflattened | 2019/10/23 | 75 | 0 | 1 |
The following one-to-many relationship with referential integrity exists between the two tables in the database:
Do the following:
The user interface for all questions is displayed below:
NOTE:
Variable | Data type | Description |
tbldisposal | TADOTable | Refers to the table named Disposal |
tblmaterial | TADOTable | Refers to the table named Material |
3.1 In this section you may ONLY use SQL statements to answer QUESTION 3.1.1 to QUESTION 3.1.5.
Code to execute the SQL statements and display of the results of the queries is provided. The SQL statements are incomplete.
Do the following to complete the incomplete SQL statements assigned to the variables sSQL1, sSQL2, sSQL3, sSQL4 and sSQL5 per question respectively.
3.1.1 Button [3.1.1]
Write SQL code to display the MaterialType of all materials sorted in reverse alphabetical order.
Example of output of the first 13 records:
(4)
3.1.2 Button [3.1.2]
The user must enter the name of a material. Code has been provided for the material name “wood” to be entered in an input box and saved in a variable named sline.
Write SQL code to display the Materialtype of all materials that contain the word stored in the variable sline.
Example of output:
(5)
3.1.3 Button [3.1.3]
Write an SQL statement to display the Datedisposed and Ma materials disposed in October. (The year 2019 is the only the database.) terialtype of all year recorded in
Example of output:
(5)
3.1.4 Button [3.1.4]
The waste management company is expecting an increase of 10% in the number of employees next year.
Write an SQL statement to add 10% to the number of Employees. Rounding of numbers is not required.
(Code has been written to display the successfully updated table after editing.)
Example of output:
(4)
3.1.5 Button [3.1.5]
Display the total of all quantities of waste materials (Quantity) as Total_Quantities for each DisposalMethod.
Example of output:
(7)
3.2 In this section, only Delphi code may be used to answer QUESTION 3.2.1 and QUESTION 3.2.2.
Use the global variables, tblmaterial and tbldisposal, provided.
NO marks will be awarded for SQL statements in QUESTION 3.2.
3.2.1 Button [3.2.1]
Write code to set the Greenhousefactor to 2 for all materials that have a
Disposalcode equal to 6.
Example of output of the last 6 records:
(7)
3.2.2 Button [3.2.2]
Write code to calculate the total of all carbon dioxide emissions.
CO2 emissions are calculated by multiplying the Greenhousefactor by the Quantity (number of tons) of material waste.
Display the total by adding it to the end of the string located in the edit box named edtdisplay.
Example of output:
(8)
QUESTION 4: PROBLEM-SOLVING PROGRAMMING
Do the following:
Supplied GUI:
The supplied GUI represents the interface of the program used by a waste management company to record and report on waste disposal data.
A text file named waste.txt is included which contains the waste materials, method of disposal (either recycled or used as landfill) and the weights measured in kilograms of each material that was disposed of recently by the waste management company.
The format of the text file is:
<Waste material><Disposal method><weight of waste material in kg>
Example of some of the lines in the text file named waste.txt:
Paper;Recycled#2543
Cardboard;Recycled#495
Trash;Landfill#1885
Cardboard;Recycled#398
Trash;Landfill#1657
Paper;Recycled#2754
Cardboard;Recycled#769
Trash;Landfill#2025
Timber;Landfill#2125
Pallets;Recycled#398
Rubber;Recycled#4321
Tyres;Landfill#1258
Metal;Recycled#541
Food;Landfill#774
Grass;Landfill#1142
Trees;Landfill#685
Soil;Landfill#5547
Rubble;Recycled#3984
Clay;Recycled#547
A constant array named arrtypes has been declared and filled with unique waste material types.
arrtypes: array[1..15] of string = ('Paper','Cardboard','Trash','Timber','Pallets','Rubber','Tyres','Metal','Food','Grass','Trees' ,'Soil','Rubble','Clay','Computers');
Code has been written to read the items from each line of the text file into 2 global, parallel arrays, named arrdata and arrweights.
arrdata : array[1..100] of string; arrweights: array[1..100] of integer; icount: integer;
Arrdata contains the name of each waste material joined to either the word Recycled or Landfill with a semicolon separating the two words.
Arrweights contains integers representing the weight of the corresponding waste material in kilograms.
The variable icount holds the total number of items for the two parallel arrays.
Code has been written in the OnActivate event of the form to read data from the text file into the two arrays and then display the array contents into the rich edit.
Complete the code for each question, QUESTION 4.1 and QUESTION 4.2.
NOTE:
You must write code in the onchange event of the combobox named cmbreport.
Below is a diagram of the 4 options of the combobox.
For QUESTIONS 4.1 to 4.4 you must write code for each of the combobox options.
4.1 Combobox option [Total weight of ALL waste]
Calculate and display the total weight of all waste materials collected. The total must be displayed on the panel named pnloutput.
Example of output:
(4)
4.2 Combobox option [Total weight of RECYCLED waste]
Calculate and display the total weight of all recycled waste material. The total must be displayed on the panel named pnloutput.
Example of output:
(5)
4.3 Combobox option [Percentage of RECYCLED waste]
The recycled weight must be divided by the total weight and then multiplied by 100 and rounded to a whole number, in order to calculate the percentage of waste that was recycled.
Display the result on the panel named pnloutput.
Example of output:
(3)
4.4 Combobox option [TOTAL weight of EACH waste product]
The array named arrdata has many waste types that are duplicated, eg ‘Cardboard;Recycled’ occurs many times in the array.
The global constant array named arrtypes contains all of the unique types of waste that have been disposed of by the waste management company.
Use this information to calculate the total weights collected for each unique waste type and write the results to a text file named report.txt.
(Note: The text file named report.txt must be created using Delphi code.)
Example of the output to the text file, report.txt:
Paper = 13332 Cardboard = 6669 Trash = 22606 Timber = 5488 Pallets = 1194 Rubber = 5843 Tyres = 4643 Metal = 1624 Food = 4052 Grass = 5650 Trees = 11801 Soil = 7010 Rubble = 4872 Clay = 4986 Computers = 12640 |
(18)
[30]
TOTAL: 150