You are on page 1of 2

UiTM (NEGERI SEMBILAN)

Quiz 5 CSC 425

Name:

Matric No:

QUESTION 1 (Final Oct 2010)


a) Write a function definition to calculate how much Malaysian Ringgit would be required to
exchange either into US Dollar, European Euro or UK GBP. The function has the following prototype:

(8 marks)

doublebuy_currency(int,double);

The first parameter is for the type of currency where the numbers 1, 2, 3 would be used to represent the Dollar,
Euro and GBP respectively.
The second parameter would be the amount of money to be exchanged.
The function would return the amount of Malaysian Ringgit.

You are given the following exchange rate:


(Dollar) $1 = RM3.25.
(Euro)1 = RM4.78
(GBP)1 = RM4.94
Tip/Hint:double buy_currency(int type of currency, double amount of money to be exchanged)
{
If (type of currency ==1) amount of Malaysia Ringgit = 3.25 * amount of money to be exchanged
elseif
return amount of Malaysia Ringgit
}
b) Write another function definition to display the amount in Malaysian Ringgit and the amount of the exchanged currency.
This function will accept two parameters which are the amount of Malaysian Ringgit and the amount of the exchanged
currency. The function has the following prototype:
(3 marks)

void display_currency(double, double);


Tip/Hint:void display_currency(double amount of Malaysia Ringgit, double amount to be exchanged)
{
Output amount of Malaysia Ringgit;

Output amount to be exchanged


}
c) Write a main program that will input the type of currency and the amount of money. The
program would call all of the function above to exchange and display the Malaysia Ringgit currency into the desired
currency that the user has chosen.
(5marks)
Tip/Hint:Void main( )
{
.
Input type of currency
Input amount of money to be exchange
Call function buy_currency
Call function display_currency
..
}

Noth/quiz4csc425

OR QUESTION 2 ARRAY (APRIL 2011)


Write a C++ program that prompts the user to enter a sequence of letters. Store the characters in an array named l e t t e
r s with 10 elements. This program will determine whether a letter is a vowel or a consonant. Then, prepare a frequency
table to show the number of vowels and consonants in that array. The details of the program are explained as follows:
a) Write a function to input the sequence of letters. The function head is:

void inputLetters (char l e t t e r s [ 1 0 ])

(3 marks)

Tip/HintVoid InputLetters(char letter[10])


{
For (int i=0; i<10; i++)
Input into letters[i]
}
b) Write a function to determine whether the letter is a vowel or consonant. Then, count the frequency of vowel and
consonant. The function head is:

void determineLetters (char letters[10], int &vowel, int &consonant)

(6 marks)

Tip/HintVoid determineLetters(char letter[10], int &vowel, int &consonant )


{ For (int i=0; i<10; i++)
If letter[i] == a or e or I or o or u count frequency vowel
Else count frequency consonant
}
c) Write a function to display the frequency table as shown below:

(4 marks)

The letters are: thedogjumpoverthemoon


The frequency of vowel and consonant
Type
Vowel
Consonant

Frequency
8
13

Tip/HintVoid displayFrequency(char letter[10], int vowel, int consonant)


{

Output the title/text as shown


Output the array letter
}
d) Write a main function to call all the functions.

Tip/HintVoid main()
{

Call function inputLetter


Call function determineLetter(letter, vowel, consonant)
Call function displayFrequency(letter,vowel,consonant)
}

Noth/quiz4csc425

(3 marks)

You might also like