Coding Assignment #6



Download 10.16 Kb.
Date28.01.2017
Size10.16 Kb.
#9442

Coding Assignment #6


  1. Sebesta Programming Exercises # 1-4. (p. 694, 7th ed. p. 718, 8th ed.) Test the code.

  2. Puzzling 9 Ball Problem (the example is in the notes)
    You have nine colored balls: 1 black, 2 white, 2 red and 4 green.
    Find solutions for the following 2 sets of constraints.

    1. Situation #1

      1. The balls in positions 2 and 3 are not green.

      2. The balls in positions 4 and 8 are the same color.

      3. The balls in positions 1 and 9 are of different colors.

      4. There is a green ball to the left of every red ball.

      5. A white ball is neither first nor last.

    2. Situation #2

      1. The balls in positions 1 and 2 are not the same color.

      2. The balls in positions 2 and 9 are of different colors.

      3. The balls in positions 3 and 8 are the same color.

      4. There is a black or white ball to the left of every red ball.

      5. There are at most 2 green balls together.

Find all solutions. Print your solutions out with nice formatting.
Turn in a file (ballsoln.prlg) with your rules in it, and a transcript showing your rules solving the problem.

  1. Programming Ancestry Problem
    Use Figure 2, (page 41, 7th or 8th edition) Genealogy of common high-level programming languages. Include Fortran95 which is added in the 8th edition figure.
    Create a minimum number of facts to represent relationships. Example facts:
    newLanguage(fortranI),
    parent(fortranI,algol58). and programmingLanguage(algol60).
    Write rules so that questions involving the following functors may be answered with your facts.
    Create the following functors, shown below with the functor name followed by a slash followed by the number of parameters the functor takes (functor/number of parameters).
    If a functor has more than 1 parameter - choose parameter names to specify their order and meaning. e.g. newLanguage(Language), parent(OlderLanguage,NewerLanguage), languageType(Language,Type), etc.

    • newLanguage/1
      (the language is new and thus has no parent)

    • programmingLanguage/1
      (there is a programming language with that name)

    • languageType/2.
      (imperative, functional, logic, objectoriented, scripting, ??)

    • parent/2.
      (the second language is a direct descendent of the first)

    • ancestor/2.
      (the second language is one or more links after the first language)

    • descendant/2.
      (the second language is one or more links before the first language)

    • family/2.
      (two different languages that have a parent or an ancestor language in common)

Some example querries you should be able to answer:


ancestor(algol60, basic). => Yes
descendant(X, algol60). => X = algol58, no
family(algolW, L) => L = algol68, L = simula1, L = pl1.
languageType(L, functional). => L = lisp, L = commonLisp, L= scheme, ...
programmingLanguage(foo) => no.
Turn in a transcript demonstrating that your rules work on the most “interesting” languages shown in Figure 2. Choose about 10 languages. Make sure you test each of your rules and each language.

Extra credit: Find another 10 programming languages (which are not in Figure 2) and add them to your database.

Extra credit: Add functors designer/2 and fullname/2, identifying the primary designer of each language, e.g.
designer(lisp,mccarthy).
fullname(mccarthy,'John McCarthy').
use single quotes (') rather than double quotes (") for strings in Prolog.

Download 10.16 Kb.

Share with your friends:




The database is protected by copyright ©ininet.org 2024
send message

    Main page