Académique Documents
Professionnel Documents
Culture Documents
N
=1
- o)
2
where N is the total number of samples,
i is the sample number,
si is the i
th
score and
a is the average value.
The standard deviation is a measure of the dispersion of a set of data from its mean. The more spread
apart the data, the higher the deviation. The program should perform the following tasks:
i. read the total number of subjects registered by the students.
ii. read the input scores (in fraction form) of each registered subjects.
iii. calculate the average and standard deviation of input scores.
iv. output the average and standard deviation (in decimal form) of the input scores to determine
whether the special attention should be given to the students should be printed to the
lecturer. The attention should be given to the students only if the calculated deviation is more
than 20% of the average input scores.
You are required to complete the following function definitions to compute average and standard
deviation and write a main() function to call the functions written. Include a loop that is not
case-sensitive to allow the user repeat this computation for new input values again and again until the
lecturer says he or she wants to end the program.
double frac_to_decimal(int numerator, int denominator)
{ //write the function definition }
double average_compute (int get_numerator[],int get_denominator[],int get_size)
{ //write the function definition }
double deviation_compute (int get_nume[],int get_deno[],int get_subject,double average)
{ //write the function definition }
Hint: Your program may use DYNAMIC ARRAY to capture the input scores in fraction (i.e. score
/total score) and perform TYPE CASTING to achieve accurate result.
12
Sample output:
13
Q5. b)
Cryptography - Data Encryption and Decryption
A company wants to transmit data over the telephone, but is concerned that its phones could be tapped.
All of the data are transmitted as four-digit integers.
The company has asked you to write a program that:
i. encrypts the data so that it can be transmitted more securely.
ii. decrypts the encrypted data to read the original contents of the data
Pseudo code for encryption:
1) The user would initially be asked to enter a four-digit integer.
2) The integer is assigned to a integer variable.
3) The program identifies (extract) each digit from the integer variable (Hint: uses %, /)
4) Each identified digit is reassigned to another variable respectively (there should be 4 variables, one
variable for each digit).E.g. digit1, digit2, digit3, digit4.
5) Each digit is encrypted with the formula: (k*3) % 10
6) Swap the encrypted first and third digit
7) Swap the encrypted second and fourth digit
8) Show the encrypted integer from the four integer variables.
Under the same C++ source file, write a decryption source code that inputs a four-digit encrypted
integer and decrypts it to form the original number.
Pseudo code for decryption:
1) The user would initially be asked to enter a four-digit encrypted integer
2) Decrypt the four-digit encrypted integer using your own algorithm
3) Show the decrypted integer
4) Swap the decrypted first and third digit
5) Swap the decrypted second and fourth digit
6) Show the decrypted integer from the four integer variables.
Your program should continuously display a Menu to let the user choose which operation he wants
to execute (encryption or decryption). Terminate your program ONLY IF the user decides to quit.
In cryptography, encryption is the process of encoding messages or information in such a way
that only authorized parties can read it.
Encryption translate plain text data (plaintext) into
something that appears to be random and meaningless (ciphertext). Decryption is the process of
converting ciphertext back to plaintext.
14
Sample output:
15
Q6.
a) Write a program to perform tasks as show below:
Write a function called double round(double argument_1, int argument_2) to do the rounding
algorithm and return the rounded value to the main().
Argument_1 is the original value to be rounded and argument_2 is the number of decimal places
(fractional part) to be applied on the value received.
PROGRAM REQUIREMENTS:
Display the data in column 1 and column 2 to 6 decimal places.
Display the data in column 3 and 4 to the number of decimal places decided by the user.
Hint:
Utilize the predefined function in <cmath> library, floor(x) to round x to the largest integer not
greater than x where floor(9.2) is 9.0 and floor(-9.8) is -10.
For example,
y = floor( x + .5 )
Rounds x to the nearest integer.
y = floor( x * 10 + .5 ) / 10;
Rounds x to the tenths position (one decimal place).
y = floor( x * 100 + .5 ) / 100;
Rounds x to the hundredths position (two decimal places).
16
Q6.
b) The end of the boom O in Fig. 6 b) is subjected to three concurrent forces. Write a program
to compute the vector FR, magnitude FR and orientation of the resultant force when being
10, 20, 30, 40, 50, 60, 70, 80 degrees.
Fig. 6 b) (i) Fig. 6 b) (ii)
Sample Output: