EPFU - Tutorial 6: Files, structures
Transkrypt
EPFU - Tutorial 6: Files, structures
EPFU Tutorial 6: Files, structures Ph.D. Mariusz Kaleta, Ph.D. Piotr Palka Institute of Control and Computation Engineering Warsaw University of Technology December, 2012 Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 1 / 12 Vectors Design a structure to hold 2-dimensional vectors Design functions for initialization, addition, subtraction, scalar multiplication, length, dot product Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 2 / 12 Vectors Design a structure to hold n-dimensional vectors Design functions for initialization, addition, subtraction, scalar multiplication, length, dot product Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 3 / 12 Complex numbers A complex number is one that has real and imaginary parts: C = R + iI , where i is an imaginary unit Design a structure which holds a complex number Design functions for initialization, addition, multiplication Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 4 / 12 EPFU students databases Design a structure to store the personal information of an EPFU student (name, id, phone, test grades, final grade) Some tests are graded of 0 to 100 points (no fractions) and some are graded of 0 to 5 (fractions possible) Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 5 / 12 Students, cont. Write a function equalEntry that takes two entry records as parameters and returns true if the entries contain identical data and false otherwise Write a function comesFirst that takes two entry records as parameters and returns true if the name within the first entry comes before the name of the second. In comparing names, comesFirst initially should compare last names. If the last names are different, comesFirst should check dictionary order, ignoring capitalization. If the last names are identical, then comesFirst should compare the first names using dictionary order and ignoring capitalization. Write a program that reads two entry records, prints whether they are identical (using equalEntry for the test), and prints which of the two entries comes first (using comesFirst). Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 6 / 12 Reading from a file Write a program that reads the content of a file and prints it on the screen. Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 7 / 12 Writing to a file Using the structure of EPFU student that contains the personal information of a student and final grade, write a program that asks the user to enter student records and then stores them in a file named student.txt. Create file, if it does not exist. Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 8 / 12 Poker Using structures, enumeration write declarations for: a playing card a deck of cards a poker hand of five playing cards Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 9 / 12 Poker Define a program that counts a probability of particular poker’s hands: pair three of a kind four of a kind full house Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 10 / 12 Design a program which Reads a given text file Generates a table of frequency count of alphabets appearing in the text Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 11 / 12 Design a program which Searches a given file for a record equal to an input value of code Structure of the file is as given below 1 2 3 4 5 6 7 8 CODE abc VALUE 5 CODE efg VALUE 3 ... CODE abc VALUE 8 ... Mariusz Kaleta, Piotr Palka EPFU, tutorial 6 12 / 12