Examen 2014 PDF

Title Examen 2014
Course Matemáticas Financieras
Institution Universidad Pontificia Comillas
Pages 5
File Size 498.1 KB
File Type PDF
Total Downloads 11
Total Views 148

Summary

Download Examen 2014 PDF


Description

Fundamentals of Computer Science 1º IEM, ITL First Name:

May/2014

Last name:

Group: □ FI_6 □ FI_8

ATTENTION: THE STUDENT MUST FILL OUT HIS NAME ON ALL THE PAGES 1.

Duration: 1h30.

2.

Keep all the exam sheets stapled together.

3.

Use of pencil is permitted.

4.

Use of the sentences exit, continue, break (apart from its use in switch) is not permitted.

Program 1 (3 pts)

Program 2 (3.5 pts)

Program 3 (3.5 pts)

Total

Program 1: (3 points) A fraction (wikipedia) represents a part of a whole or, more generally, any number of equal parts. When spoken in everyday English, a fraction describes how many parts of a certain size there are, for example, one-half, eight-fifths, three-quarters. It consists of an integer numerator, displayed above a line (or before a slash), and a non-zero integer denominator, displayed below (or after) that line. The numerator represents a number of equal parts, and the denominator, which cannot be zero, indicates how many of those parts make up a unit or a whole. For example, in the fraction 3/4, the numerator, 3, tells us that the fraction represents 3 equal parts, and the denominator, 4, tells us that 4 parts make up a whole. The picture illustrates 3/4:

A fraction is said to be an improper fraction if the numerator is greater than the denominator: 13/6, 18/8, 5/2,… A fraction is said to be a proper fraction if the denominator is greater than the numerator: 1/3, 3/8, 3/4, … A mixed number is the sum of a non-ze mproper fraction can be converted to a mixed number as f !

Example:

!

=1

! !

1

Fundamentals of Computer Science 1º IEM, ITL

May/2014

Other examples: Write a program to execute the following: 1. Read from the keyboard 2 integer numbers: numerator (num) and denominator (denom) y validate them (check they form an improper fraction and that the denominator is not 0) 2. Convert the improper fraction in a mixed number by means of a function call to ObtainMixed() function. This function receives the numerator (num) and denominator (denom ) previously read, and gives back the integer number (int_num, part of the mixed number) and the numerator of the proper fraction (num_proper, corresponding to the mixed number). 3. Display the resulting mixed number in the main program 4. By means of a function DisplayMixed(), display the mixed number in a graphical way, as shown in the following examples. This function receives the integer number(int_num, part of the mixed number) and the numerator of the proper fraction (num_proper, corresponding to the mixed number) and the denominator of the proper function (den_proper). This function displays the number of rows indicated by the integer number int_num, where each row is formed by den_proper (denominator of the proper fraction) number of asterisks “*”. Then, another row is displayed containing num_proper of asterisks, and a number of “-“ that corresponds to the difference between the denominator and the numerator of the proper fraction Write the main program, the ObtainMixed()and the DisplayMixed() functions Examples: 11 3 =2 4 4

8 3 =1 5 5

3 23 =4 5 5

****

***** *** - -

***** ***** ***** ***** *** - -

**** ***-

Program 2: (3.5 points)

2

Fundamentals of Computer Science 1º IEM, ITL

May/2014

Write a function SearchLocalMax() to search the local maximum voltage levels in a matrix m of 2 columns containing at each row the information of a sample: time, voltage (t0, v0 t1, v1 t2, v2 …,…) A local maximum at location i is found if: The voltage level at sample i > The voltage level at sample i -1 and The voltage level at sample i > The voltage level at sample i +1 The prototype of the function is: void SearchLocalMax(float m[][2], int nrow); The function will follow these steps: 1. Search for the local maxima in m and count them. 2. Allocate dynamic memory for this number of elements to a vector of float max and to a vector of integers loc 3. Copy each local maximum voltage from m into the vector of float max and the corresponding location (row number in m) of each maximum into the vector of integers loc 4. Look for the maximum value in max vector 5. Display (call the function Display) the samples (time, voltage) in m from the previous local maximum up to the next local maximum. If there is no previous local maximum, display samples starting at the first sample in m. If there is no next local maximum, display samples up to the last sample in m. void Display(float m[][2], int loc_ini, int loc_end); Write the SearchLocalMax() function and the Display() function Example: given the matrix m: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

time 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

voltage 690.7 691.2 692 691.8 691 691.9 692.6 693.1 692.9 691.3 689.5 689 689.4 689.7 690.1 689.9 689.3

The size of the vectors will be 3 and the vectors will be filled as indicated: 3

Fundamentals of Computer Science 1º IEM, ITL loc 2 7 14

May/2014

max 692 693.1 690.1

The maximum voltage is 693.1, and all the samples will be displayed from sample 2 up to sample 14.

Program 3 ( 3.5 points) A phone company keeps its daily client´s data in a static vector of structures. For every client the structure T_CLIENT with fields: phone number, balance in euros and the time in seconds that the client is permitted to call. At first, the program has to initialize the vector of structures to be able to work with data of every client, by reading from the keyboard the phone number and initializing the balance and time permitted in seconds to cero. There will be a loop (loop 1) where the password and the phone number is read in the loop(the phone number is not validated) (it will be understood as turn on the phone). This loop 1 will continue while the string read is not “exit”. In this loop the password will be checked (the same for all users for simplicity: “passwd”). Then into the loop 1, the client will enter a loop (loop2) that will list the following options: 1) Add money to increase balance: The client can add money to his balance. Based on the amount of money the time permitted to call will also be increased. 2) Make a phone call: The client can use the phone to call during a period of time and based on a calling rate (defines as constant RATE with value of 10 cents for every second). The balance and time permitted will be updated at each call. 3) Turn off phone: When the client selects this option the program will call the function TurnOff() and ends the loop of the menu (loop2).

Option-1: A client can increase his balance indicating the amount of money that he wants to add. The program will change the balance and calculate the time that has to be added to his previous permitted time. To do this, in the program main() the client has to introduce by keyboard the amount of money and then call the function. The prototype of the function to do this option is: void AddBalance(T_CLIENT vec[], int n, int phone_num, float money);

Option-2: The program will call the function Calls() to start calling. The phone call starts if the client´s balance is positive. The duration of the phone call is calculated by entering 4

Fundamentals of Computer Science 1º IEM, ITL

May/2014

a loop where every cycle of the loop indicates one second. In every cycle the program will reduce the permitted time and the balance of the client based on the value of a rate (constant RATE). The phone call will continue if the balance in every cycle is positive, additionally, the user has to validate the continuity of the call in every cycle by introducing the word “yes”. If the balance reaches a negative value the program shows a message indicating the end of call. In this case the time permitted to call and the balance of the client will be initialized to cero. Additionally, the client can stop the calling at any moment introducing the word “end” when validating the call, in this case his balance and permitted time will be updated. The function will return the final balance of this client ( that will be displayed on the monitor in main() ). The prototype of the function for this option is: float Calls( T_CLIENT vec[], int n, int phone_num) ;

Option-3: When this option is selected the data of the vector will be saved in a new binary file “clients.dat”, calling a function TurnOff(),and then the loop of this client will stop (loop2).Write the call for this function: void TurnOff(T_CLIENT vec[], int n, FILE *pf);

Note: It is not necessary to write the code of the function TurnOff().

5...


Similar Free PDFs