Вы находитесь на странице: 1из 3

Assignment 2 (Individual Assignment) Sem 1, 2013/2014 Display: 23/9/2013 Deadline: 7/10/2013

Write a program in C++ that calculates the amount to be paid to an employee based on the hours worked and rate per hour. A user will enter hours worked and rate per hour for an employee. Your program should have a function payCheck that calculates and returns the amount to be paid. The formula for calculating the salary amount is as follows: for the first 40 hours, the rate is the given rate (the rate that a user has entered); for hours over 40, the rate is 1.5 times the given rate. Tuliskan satu program di dalam C++ untuk mengira jumlah bayaran yang perlu dibayar kepada seorang pekerja yang bergantung kepada jumlah jam bekerja dan kadar bayaran per jam yang diberikan. Pengguna sistem akan memasukkan jumlah jam bekerja dan kadar bayaran per jam yang akan diberikan. Program anda perlu mempunyai satu fungsi paycheck yang akan mengira jumlah bayaran yang diperolehi dan mengembalikan jumlah bayaran. Pengiraan bayaran adalah seperti berikut: Untuk 40 jam pertama, kadar bayaran per jam adalah seperti kadar per jam yang dimasukkan; manakala jumlah jam selebihnya, kadar bayaran adalah 1.5 kali ganda lebih daripada kadar bayaran per jam yang diberikan.

Q1 : Write the above program using a simple C++ program. Q2: Write the above program using a structure for an employee. An example of a structure is as below: struct Employee { string SNama; int iJamBekerja; float fBayaranPerJam ; }; Q3 : Modify question 2 (Q2) above by creating 5 employees. Your program should calculate the payment for each of employee. Display all employee names and payments. Your program should also display who earns the highest salary and display the name of that employee.

Q4: Trace the partial of program below:

1. int v = 8, *r, *s; 2. int *p; 3. int q = 100; 4. p = &q; 5. r = p; 6. *p = 20; 7. p = new int; 8. *r = 30; 9. q = v; 10. s = p; 11. *s = 50; What are the last values of *p, q, *r, v dan *s?

Q5: Given the following codes: 1. int *p , *q , v , nom[5]; 2. p = &v; 3. *p = 12; 4. q = p; 5. nom[0] = *q; 6. p = nom; 7. p++; 8. nom[2] = 12; 9. *p = 13; 10. *q = 10; 11. v = 11; 12. *(p+3) = 16; 13. p = &nom[3]; 14. *p = 10; 15. p--; What are the last values of *p, *q, v and nom ? Q6 : Given below declaration : struct Node { int value; Node * next; }; In the main function, the following codes are given: 1. Node *q, *r; 2. Node *p = new Node; //address of this new Node adalah 10000

3. q = r = NULL; 4. p -> value = 9; 5. p -> next = NULL; 6. q = new Node; //address of this new Node adalah 10050 7. p->next = q; 8. p->next->value = 8; 9. q->next = new Node; //address of this new Node adalah 10100 10. r = q; 11. r-> value = 10; 12. q->next->value = 11; 13. q = q-> next; 14. q -> next = NULL; What are the last values of p->value and q->value ?

Вам также может понравиться