Assignment 1

The report should be on paper and have the following sections:

A first side with

A short description of each sub-task, in your own words (do not copy the text from this assigmnet specification)

Source code (well commented).

Printouts from test runs, to show that the program works as intended

and finally some words about problems you might have had and other comments about the assignment.


The assignment should be completed
individually. Of course you may help each other, and discuss different solutions and methods, but the report and the programs should be written by you, and if neccesary you should be able to explain in detail the function of the programs.

The report should be handed in at the latest at 12.00 on Friday the 17:th of November.

Assignment 1 consists of five sub-tasks:

  1. Write a short program that displays your name and your adress ocn the screen. How do you produce a 'new line'

     

  2. Certain mathematical functions can be apporximated by series expansion. One example is the sin(x) funtion:

    sin(x) = x/1! - x^3/3! + x^5/5! - x^7/7! + …

    Write a C-funtion sinus with the following prototype:

    double sinus(double x, int n)

    that calculates the sine of x with the help of n terms in the expansion.

    Write a main program that uses your function and compares it with the built-in sin function, for some different values of x. Let the user type in values for x and n. If the built-in sin function uses the same method as you do, how many terms do you estimate that it uses ? Your function only has to be able to handle arguments in the range 0 to PI/2.

     

  3. A palindrome is a sentence or a word that looks the same even if read backwards (apart from spaces and punctiation). here is an axample:

    sirap i paris

    a man a plan a canal Panama

    ni talar bra latin

    Write a program that read a text from the keyboard and checks whether it is a palindrome or not. If you want to you may use the built-in type string. Be particularily careful to check that the user doesn't type in more characters than your string can hold. Note that the program should not differentiate between upper and lower case, i.e. 'Anna' is regarded to be a palindrome. Also make sure that spaces are discarded.

     

  4. Draw a class diagram of an airport, with airplanes, pilots, passengers, tickets and so on. You should have at least ten classes in your diagram. Note that no program is neccesary in this task !

  5. Declare a class PlayingCard, with colour and suite (e.g. ten of hearts, king of diamonds). Declare a class Deck that contains playing cards. You should be able to shuffle the cards and also to deliver one card at a time from the deck. Also declare a class PokerHand that holds five cards. You should be able to print out the hand and also ask it if it is a flush or a straight. How often does this happen ? Write a main program that simulates a number of poker hand and calculates some statistics.