School of Mathematical Sciences Universiti Sains Malaysia MAT 181 Programming For Scientific Applications Lab 3
School of Mathematical Sciences Universiti Sains Malaysia MAT 181 Programming For Scientific Applications Lab 3
There are 2 ways to print the source file (.cpp file) and output:
i) To print directly from MS Visual Studio menu (for the .cpp file), or
ii) To copy the source program/output and paste it to a 3 rd party editor (e.g. MS Word). This is a more
preferred way if you want to include the source program and output in the documentation for better
formatting purpose.
Refer to Appendix A and Appendix B at the end of this lab sheet for step-by-step guide how to perform
copy-paste.
z
x
B C
y
It is known that z = x 2 + y 2 and the area of ABC is ½ |BC| |AC|. Write a complete program to compute z
x
and the area of ABC for given values of positive x and y. Also, find the angle , ( = tan −1
). If x or y is
y
not positive, the program should be terminated. Assume that the user can continue computing these values
for different x and y as long as he wants to.
Note 1. In C++, to compute y = x5 for example, we use the function pow(u,v)which is already
defined in an existing header file of the MS Visual Studio compiler. To compute y = x5 we
write y = pow(x,5).
2. To compute = tan-1(x), use the function atan(); = tan-1(x) becomes theta =
atan(x); the function atan(x) is also already defined inside the compiler.
Page 1 of 6
2. The bending moment in a simply supported beam of span L subjected to a concentrated load P at the
midspan is given by
x L
P 2 0x <
M ( x) = 2
P ( L − x) L
xL
2 2
where x is the distance from the left support.
L/2 L/2
Write a C++ program to read the load, P, the beam span, L, and the distance x and computes the bending
moment. Your program must check for the validity of the x value, i.e. 0 ≤ x ≤ L, before proceeding to
compute the bending moment.
Your output should look like the following,
Enter load (P), beam span (L) and the distance (x): 20 56 89
The distance x must be within the value of 0 and 56. Try again.
Enter load (P), beam span (L) and the distance (x): 20 56 78
The distance x must be within the value of 0 and 56. Try again.
Enter load (P), beam span (L) and the distance (x): 20 56 34
The bending is 220
3. Write a program to calculate and output the minimum, maximum and average of a list of positive test scores.
Assume that the scores will be entered one per line and that the list will end with a negative sentinel score.
Minimum score is 12
Maximum score is 79
Average score is 46.6
Page 2 of 6
4. Write a complete C++ program to calculate the wages of employees which are based on the number of hours
worked times the hourly rate. The user must type in the employee number, the number of hours the employee
has worked and the hourly rate. Your output should look like the following:
Page 3 of 6
Appendix A
Step-by-step guide: How to copy a source file and paste to MS Word
Figure 1 Figure 2
Figure 3
Page 4 of 6
Appendix B
Step-by-step guide: How to copy the output and paste to MS Word
Figure 4
Figure 5
Page 5 of 6
Figure 6
Page 6 of 6