Question

  • Creator
    Topic
  • #2148128

    c programming for a beginner

    Locked

    by dj_ineedmoney ·

    the peolples details to be used

    4
    324 herold st, here, VIC 3180
    John, William
    4
    5000.799805

    51
    123 Smith St, DOncaster, NSW 2891
    John, william
    5
    5555.500000

    1
    121 Martin Place, Point Cook, VIC 2910
    Brian, Davis
    7
    2000.000000

    42
    12 Peterson St. Fadden, ACT 2904
    Peter, Smith
    6
    1000000.000000

    0

    The work

    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. Delete property from catalogue
    3. Save catalogue to file
    4. Search property
    5. Sort and display catalogue
    6. 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 from again.

    Task 2 [20 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 a run-time(dynamically) allocated data structure. You should not use compile-time (static) memory allocation. You can assume the file will have the following format.

    [Number of properties]
    [Address of property]
    [Real estate agent firstname], [Real estate agent surname]
    [Number of bedrooms]
    [Price of property]
    [List of features in one decimal number]
    ?
    ?
    [Address of property]
    [Real estate agent firstname], [Real estate agent surname]
    [Number of bedrooms]
    [Price of property]
    [List of features in one decimal number]

    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 gets to read in a whole line at a time.

    [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.

    [List of features in one decimal number] ? The binary representation of the decimal number is used to specify the existence of certain features in the property (See lecture 13 to see how to convert between positive decimal numbers and two?s complement binary number). Only the last six binary digits are used, since there are a total of six possible features. A binary value of 1 for the feature indicated the feature exists, 0 indicates the feature does not exist for the property. Below is the list of features along with their binary representation:

    000001 – garage
    000010 – ensuite
    000100 – dishwasher
    001000 – air conditioner
    010000 – heating
    100000 – study

    So for example a property that has an ensuite, air conditioner and heating would be specified using the decimal number 26 which translates to the binary representation 011010.

    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
    47
    292 Smith St, Blackburn, ACT 3920
    Amit, Chandhri
    2
    222292.84
    38

    Task 3 [15 marks code correctness]

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

    1. Specify the property address
    2. Specify real estate agent first name
    3. Specify real estate agent surname

    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 to be deleted. Note the specified string may match more than one property. For example if the user specifies the first name peter then there maybe more than one property with the real estate agent peter. In this case all properties that match must be deleted. Note the string has to completely match the 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

    If more than one matching property is found then all matching properties are deleted. The program needs to free up memory that is no longer needed as a result of the deletion.

    Task 4 [10 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 5 [13 marks code correctness]

    Implement the search catalogue menu option. This option allows the user to search for properties that have certain features. After selecting this option the user will be asked to type in a list of features. Then the properties that contain ALL the searched features will be displayed (note this is different from the exercise 2 of lab 6 where you are asked to find all students that is at least studying one of two subjects specified by the user ). Please note you must use bitwise operators for this exercise. If bitwise operators are not used then you will get zero marks for this question. The user specifies the list of features as follows:

    The list of features entered by the user is all in one line. You can assume the user inputs the list of features all in lower case. There is a comma followed by a space between each feature.

    [name of feature], [name of feature], ??

    Where name of feature can be one of the following:

    garage
    ensuite
    dishwasher
    air conditioner
    heating
    study

    The properties that match the selected features are displayed as follows:

    —————————————————————
    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]
    List of features: [List of features in one decimal number]
    —————————————————————
    ….
    ….
    —————————————————————
    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]
    List of features: [List of features in one decimal number]
    —————————————————————

    Note: [Number of properties], [Address of property], [Real estate agent firstname], [Real estate agent lastname], [Number of bedrooms], [Price of property], [List of features in one decimal number] have the same meaning as those for task 2.

    Here is an example output:

    —————————————————————
    Address: 273 Cavalier St, Glen Waverly, VIC 2911
    Real estate agent: Angela Smith
    Number of bedrooms: 10
    Price: $100000000
    List of features: 49
    —————————————————————
    Address: 29 Kennon Ave, Melbourne, VIC 2831
    Real estate agent: Clive Johnson
    Number of bedrooms: 1
    Price: $102922
    List of features: 61
    —————————————————————

    Task 6 [20 marks code correctness]

    Implement the sort and display catalogue menu option. Once this option is selected the following sub-menu is displayed:

    1. Sort property by surname of real estate agent
    2. Sort property by price
    3. Sort property by number of bedrooms

    To get full marks for this task you should design your sorting algorithm so that it uses function pointers to allow the same algorithm implementation to be used to sort for all 3 different attributes. Note the easiest way to do this is use the qsort library function in C.

    After the above choice is made the properties are sorted in ascending order and displayed according to the same format as for task 5.

All Answers

  • Author
    Replies
    • #2461090

      Clarifications

      by dj_ineedmoney ·

      In reply to c programming for a beginner

      Clarifications

    • #2461070

      what is your point or question?

      by dr dij ·

      In reply to c programming for a beginner

      that’s a nice example of an assignment, so what? what is your point in posting this?

      are you sharing that to show us what is happening in your C class?
      are you trying to get someone to do your homework for you?
      are you trying to start a discussion if it is too hard or easy?

    • #2461017

      Start here.

      by bizzo ·

      In reply to c programming for a beginner

      /* hello world program */
      #include “stdio.h”

      void main()
      {
      printf(“\nHello World\n”); // print to screen
      }

      And then learn C.

      A quote from your rather lengthy post:
      “To get full marks for this task you should design your sorting algorithm …”

      The word here is YOU. *YOU* should design.

      Rather than post the entire assignment, you’re only goning to get flamed with this, try working on the assignment yourself. If you get stuck, post a question. You might be surprised, you might actually manage to do the work yourself. Unless you’re some sort of waster who expects everyone to drop everything to help you. You only get from life what you put in.

      http://www.google.co.uk/search?hl=en&rlz=1T4GZHZ_enGB231GB231&q=c+programming+for+a+beginner&btnG=Search&meta=

    • #2461011

      Here is a little bit for you to chew on..

      by Anonymous ·

      In reply to c programming for a beginner

      The term associated with extension methods is duct typing.

      Listing 1 shows an extension method that uses Reflection to send the property values of an object to a TextWriter stream. In SimpleExtensionMethod an array of integers is assigned to the anonymous variable numbers. A LINQ query is invoked to create a new anonymous type from the number indicating the value and the number?s parity?odd or even. Finally the result of the query calls the extension method Write, sending the property name and value for each object to the console.

      Listing 1: An extension method that displays the state of an object using new features of .NET and Reflection.

      using System;
      using System.Collections;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.IO;
      using System.Reflection;
      using System.Data;
      using System.Data.SqlClient;
      namespace ExtensionMethod
      {
      class Program
      {
      static void Main(string[] args)
      {
      SimpleExtensionMethod();
      }
      public static void SimpleExtensionMethod()
      {
      var numbers = new int[]{1,2,3,4,5,6};
      var oddsEvens = from num in numbers
      let parity = num % 2 == 0 ? “Even” : “Odd”
      select new {Number=num, Parity=parity};
      foreach(var obj in oddsEvens)
      obj.Write(Console.Out);
      Console.ReadLine();
      }
      public static class WriteObjectState
      {
      // extension method that writes an object’s state
      public static void Write(this object obj, TextWriter writer)
      {
      var formatted = from info in obj.GetType().GetProperties()
      let value = info.GetValue(obj, null)
      select new {Name=info.Name, Value=value==null?””:value};
      Array.ForEach(formatted.ToArray(), r=>
      writer.WriteLine(r));
      }
      }
      }

      The extension method Write in the static class WriteObjectState extends object and accepts a TexTWriter, for example, Console.Out. The Write extension method uses a LINQ query to select and iterate through all of the object?s properties and project these aspects of a property to a new type. The Array.ForEach method iterates over each property name and value pairing and sends these to the writer (the console).

      Please post back if you have any more problems or questions.

Viewing 3 reply threads