Programming Task-1

09/05/2010 22:57

 Implement a menu driven real estate catalogue system that allows users to perform various catalogue maintenance and search tasks.  You are only allowed to use the C programming language.  You are not allowed to use C++.

 Please use the “AssignTemplate.c” file given below as the basis for your solution.  If you follow that template you will not go far wrong.

    Please do not use global variables.  Up to 50% of marks will be lost for assignments that use global variables.

 

    Please do functional decomposition.  Up to 50% of marks will be lost for students who try to write the entire program in one main function or something similar.  There should be at least 5 functions for the assignment.  One function for each task 2 to 4.  Two functions for task 5.  More functions than 5 is highly recommended.  The aim of this rule is to teach you how to pass pointer arguments into functions.

     The assignment has been broken up into 5 tasks.

 

Task 1      [10 marks code correctness]

 

The program should be menu driven.  The user should be presented with the following menu:

 

1. Load catalogue from file

2. Save catalogue to file

3. Display catalogue

4. Search property from catalogue

5. Quit

 

After selecting one of the above options the corresponding task should be performed.  After completing the selected task, the menu should be displayed again for the user to choose again unless the 5th option is chosen.

 

Task 2  [26 marks code correctness]

 

Implement the load catalogue from file menu option.  After selecting this option the user should be asked to enter the name of a file to be loaded.  The file should then be loaded into an array of structures.  The array of structures should have been declared in the main function before the load catalogue function was called.  To get full marks for this task you should use run-time (dynamically) allocated memory for the array of structures.  If you use static memory allocation you will lose 5 marks.   You can assume the file will have the following format (note you can find an example input file inside the assignment folder called “example_input.txt”, make sure your program at least works with that file).

 

 

[Number of properties]

[Address of property]

[Real estate agent firstname], [Real estate agent surname]

[Number of bedrooms]

[Price of property]

[Address of property]

[Real estate agent firstname], [Real estate agent surname]

[Number of bedrooms]

[Price of property]

 

The … stands for intermediate catalogue entries. 

You can assume the property address string to be a maximum of 200 characters.

The firstname and surname strings have a maximum of 100 characters each.

 

Here is an explanation of the above fields:

 

[Number of properties]     -    This is the number of properties stored in the file

 

[Address of property] – A string specifying the address of the property, the string may contain spaces, punctuation, and numbers.  However the entire address is specified in one line.  Hint: you can use fgets to read in a whole line at a time.  Use stdin as the file pointer, since you are taking input from the keyboard.

 

[Real estate agent first name], [Real estate agent last surname] – Two strings which do not contain spaces but are separated by a comma followed by a space.

 

[Number of bedrooms]  - A number specifying the number of bedrooms in the property

 

[Price of property]  - Price of the property, it may contain a decimal point.

 

Below is an example of a catalogue file that contains 2 properties:

 

2

32 Bugden Ave, Forest Hill, VIC 3108

Peter, Kernighan

3

602000.82

292 Smith St, Blackburn, ACT 3920

Amit, Chandhri

2

222292.84

If the sample file is copied from windows XP into putty.  You my need to use the following command to change the format of the file from windows to unix:

 

dos2unix

 

Task 3     [12 marks code correctness]

 

Implement the save catalogue to file menu option.  After selecting this option the user should be asked to specify the name of the save file.  All the catalogue data should be stored onto the specified file in the same format as the file loaded in Task 2.

 

Task 4     [12 marks code correctness]

 

Implement the display catalogue menu option.

 

All the attributes of the properties should be displayed as follows:

 

Number of properties in catalogue  = [number of properties]

---------------------------------------------------------------

Address: [Address of property]

Real estate agent: [Real estate agent firstname] [Real estate agent surname]

Number of bedrooms: [Number of bedrooms]

Price: $[Price of property]

---------------------------------------------------------------

....

....

---------------------------------------------------------------

Address: [Address of property]

Real estate agent: [Real estate agent firstname] [Real estate agent surname]

Number of bedrooms: [Number of bedrooms]

Price: $[Price of property]

---------------------------------------------------------------

 

Note: [Number of properties], [Address of property], [Real estate agent firstname], [Real estate agent lastname], [Number of bedrooms] and [Price of property] have the same meaning as those for task 2.

 

Here is an example output:

 

Number of properties in catalogue= 2

---------------------------------------------------------------

Address: 273 Cavalier St, Glen Waverly, VIC 2911

Real estate agent: Angela Smith

Number of bedrooms: 10

Price: $100000000.00

---------------------------------------------------------------

Address: 29 Kennon Ave, Melbourne, VIC 2831

Real estate agent: Clive Johnson

Number of bedrooms: 1

Price: $102922.34

---------------------------------------------------------------

 

 

Task 5     [15 marks code correctness]

 

Implement the search property from catalogue menu option.  After selecting this option the user should be asked to specify the property using the following sub-menu:

 

1. Specify address

2. Specify real estate agent first name

3. Specify real estate agent last name

 

After choosing one of the above sub-menu options, the user should be asked to type in a string to be used for finding the property.  Note the string has to completely match the relevant property attribute.  Partial match is not considered a match.  

 

In the following example the user strings does not match the corresponding properties:

 

User types in for property address: 32 Bugden Ave, Forest Hill, VIC 3108

Actual property address:  32BugdenAve,ForestHill,VIC3108

 

User types in for real estate agent first name: peters

Actual real estate agent first name for property:  peter

 

User types in for real estate agent surname: peter

Actual real estate agent surname for property:  peterson

 

The search should be case insensitive.  Therefore the following does match:

 

User types in for real estate agent first name: peter

Actual real estate agent first name for property:  peTer

 

User types in for property address: 32 bugden ave, forest hill, vic 3108

Actual property address: 32 Bugden Ave, Forest Hill, VIC 3108

 

The matching properties found should be displayed onto the screen in the same format as task 4.  If more than one matching properties is found then all matching properties should be displayed.

 

Bonus Task     [10 marks code correctness]

 

If you want a bonus 10 marks for your assignment and are ready for a challenge then you can implement an extra option to the menu.  This is the “Delete properties” menu option.  Once the user selects this option then he/she will be asked to do the same as task 5 except the matching properties found are first displayed and then deleted from memory.  To get the marks for this task the memory for your array of structures must have been allocated using dynamic memory allocation in Task 2.  Here you will need to delete that array of structures and create a new smaller one that exactly fits the remaining (non-deleted) properties.   Note if the search matches more than one property than all the matched properties will need to be deleted.

 

Here u get-go!

AssignTemplate.c

#include
#include

struct property_type {
  // You need to fill in your struct here

};

// This function loads a catalogue of properties from a user specified file name.
// Note you need to use malloc inside this function to allocate the memory
// needed for the catalogue of properties.
// After the catalogue is allocated and filled up with properties loaded from the file,
// it is returned back to the main program via the property_type * return type.
// The pointer parameter numProperties is used to pass the number of properties back
// out to the numProperties variable in the main function.  This way the other
// functions will be able to use this variable to find how many properties
// are stored in the catalogue.

struct property_type * loadCatalogue(int * numProperties);

// This function saves catalogue into a user specified text file
void saveCatalogue(struct property_type * pCatalogue, int numProperties);

// This function displays the catalogue onto the screen.
void displayCatalogue(struct property_type * pCatalogue, int numProperties);

// This function finds a user specified property or set of properties and displays them
void findProperty(struct property_type * pCatalogue, int numProperties);

//  Important questions for you to consider:
//  ** Why are the parameters for the loadCatalogue function so different
//     from the other functions?  Please explain the difference in detail. ***
//     Some variant of this question WILL be on the exam.


int main() {

  struct book_type * propertyCatalogue;
  int numProperties;

  // Write a loop which continuously asks the user to choose one of
  // the following options until the quit option is selected:
  //     1. Load catalogue from file
  //     2. Save catalogue to file
  //     3. Display catalogue
  //     4. Find property from catalogue
  //     5. Quit
  //
  // Use a switch statement to handle the different user choices.
  //     In the case that load catalogue is chosen you should call the   
  //     loadCatalogue function as follows:
  //         propertyCatalogue = loadCatalogue(&numProperties);
  //
  //     In the case that save catalogue is chosen you should call the
  //     saveCatalogue function as follows:
  //         saveCatalogue(propertyCatalogue, numBooks);
  //   
  //     It is up to you to work out how and when to call the other functions.



  return 0;
}

 

 

 

Sample input:

4

324 herold st, here, VIC 3180

John, William

4

5000.799805

123 Smith St, DOncaster, NSW 2891

John, william

5

5555.500000

121 Martin Place, Point Cook, VIC 2910

Brian, Davis

7

2000.000000

12 Peterson St. Fadden, ACT 2904

Peter, Smith

6

1000000.000000