HTW Berlin Medieninformatik

HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 2: Informatik II
Winter Term 2010/11


Exercise 14: It's Déjà vu all over again!1

Lab exercises:

  1. How do you go about reading in characters from a file in C++? Write and test a method that returns the next character in a file. Note that you have to do something with the carriage returns - such as ignoring them - and that you have to decide what to do when there are no characters to be returned.
  2. How do you write a string to a file? How do you write an integer to a file? A character? How do you create a file, anyway?
  3. Now the fun begins! Write a C++ application to read in a file character by character, counting the frequencies with which each character occurs. When there are no more characters, create a file frequency.txt and output the frequencies for each character. You should be able to deal with German texts.
  4. Output a histogram of the character frequencies. One simple kind of histogram has horizontal lines proportional to the magnitude of the number it represents. For example:
    A : **********
    B : *****
    C : ******
  5. Now make your histogram application display the histogram with vertical lines and input the file name as a parameter.
  6. (For the bored) How do you deal with Unicode in C++? Can you make a histogramm for GIF-encoded pictures?

Your report is due by 11.00 pm the night before your next lab!

1 Attributed to Yogi Berra, a famous American baseball player


Copyright 2010 Prof. Dr. Debora Weber-Wulff
Questions or comments: <weberwu@htw-berlin.de>
Some rights reserved. - Copyright and Warranty