Page 1

BIL342 Software Engineering Laboratory II Subject : Submission Date : Due Date : Advisors :

Generic Programming with ADA 02.March.2009 18.March.2009 Prof. Dr. Ersin TÖRECİ, R.A. Aydın Kaya

1.Introduction It's often better to create a more generic version of a subprogram or package first and then use them to create more specific subprograms or packages. To use a generic package (or subprogram), we have to create a real package from generic package. This process is called instantiating, and the result is called an instantiation or instance. A generic_declaration declares a generic unit, which is either a generic subprogram or a generic package. A generic_declaration includes a generic_formal_part declaring any generic formal parameters. A generic formal parameter can be an object; alternatively (unlike a parameter of a subprogram), it can be a type, a subprogram, or a package. 2. Experiment 2.1 Description In this experiment you’ll implement a basic generic database system that holds three different data types and lists them according to given queries. Program takes 4 parameters: data type, data file, query file and result file. (For further information: 2.4) Data file contains unsorted data (may have duplicates). Program reads them line by line and keeps in a dynamic data structure. Query file contains selection statements on datas. A query file may contain more then one line. Result file contains query results with sorted data. 2.2 Input-Output Files 2.2.1 Data File: Sample data files given in Appendix A. 2.2.2 Query File: Query Structure: select (operator)<value> [AND/OR] (operator)<value > There are six operators: << : smaller than >> : greater than <= : smaller or equal >= : greater or equal

== !=

: equal : not equal

Example: select select select select select

<< 15 OR >= 50 >> 100 AND << 205 == 12.Apr.2009 >= 2+5i AND << 56-6i << 78+2i

2.2.3 Result File Query results must be sorted and written to output file .

2.3 Types and Restrictions Your generic database can be constructed with 3 types; Integer Complex Number : a+bi Date : dd.mmm.yyyy

*Every complex number can be written in the form a + bi, where a and b are real numbers called the real part and the imaginary part of the complex number. Youâ&#x20AC;&#x2122;ll only consider magnitude of complex numbers. Magnitude(M) of a+bi complex number is ;

Above example shows that two complex numbers different directions.

and z have same magnitude but

3+4i => M = 5 3-4i => M = 5 4+3i => M = 5 4-3i => M = 5 3+4i = 3-4i = 4+3i = 4-3i, for your program. Hints for implementation: Date: subtype Day_Type is Integer range 1..31; type Month_Type is(Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec); subtype Year_Type is Integer range 1900..2100; type Date_Type is record Day : Day_type; Month : Month_Type; Year : Year_Type; end record;

Complex Number: type Complex_Number_Type is record Real_Part : Integer; Imaginary_Part : Integer; end record;

2.4 Execution main [type] [data file] [query file] [result file] [type] : This parameter can be 窶電 , -i or -c . d for date type, i for integer type , c for complex type . [data file] : This file holds dataset elements. Each line has one element. [query file] : This file holds queries. Each line has one element. [result file] : Query results will be shown in this file. Example: main -i intdb.txt iquery.txt result.txt main -c complexData.txt compq.txt cresult.txt

2.4 An Example Command:


â&#x20AC;&#x201C;i integerAp.txt query.txt


Data file : Integer data in appendix A. (integerAp.txt) Query file: (query.txt) select << 100 AND select >= 100 select == 187 OR

>= 30 >> 200

Result file: (Query file has three statement. Each query will be handled separately and append previous result) 1st query result: 56 56 85 90


<< 100

2nd query result: 187 187 234


>= 100

3rd query result: 187 187 234


== 187

intresult.txt 56 56 85 90 187 187 234 187 187 234



>= 30

>> 200

Notes Donâ&#x20AC;&#x2122;t miss the deadline. You will submit your ADA source codes (.ads, .adb) and your report(.pdf) in a zip file via the online submission system. Save all your work until the assignment is graded. The assignment must be original, individual work. Duplicate or very similar assignments are both going to be considered as cheating and receive F3 from the course. Before the submission, be sure that your program runs properly in Windows platform with the gnat (3.15) compiler. I will test your programs via the gnat 3.15. You can find compiler files in experiments ftp. You can ask your questions through courseâ&#x20AC;&#x2122;s news group and you are supposed to be aware of everything discussed in the newsgroup. Appendix A Sample Integer data: 10 6 234 56 23 187 90 56 187 85 Sample Date data: 5.Apr.1954 12.Dec.2002 4.Mar.1978 12.Mar.1978 23.Aug.1950 2.Feb.2006 5.Jul.1999 20.Jan.2001 2.Apr.2002

Sample Complex data: 5+2i 10+7i

4+30i 2-5i 23+i 7-8i 100-9i 9+45i 7+34i 1-1i

References American National Standard Reference Manual for the ADA Programming Language ,


342, 2. odev

Read more
Read more
Similar to
Popular now
Just for you