Assignment 1 Report: Name: Manuja Sellahewa Student ID: Lab Class: Teacher:Miss - Lushaka Nissansala
Assignment 1 Report: Name: Manuja Sellahewa Student ID: Lab Class: Teacher:Miss - Lushaka Nissansala
Assignment 1 report
Question 1
1. Program description
In the Graphics Window, create two buttons. Using SplashKit SDK, Button 1
displays a unique artwork with three forms. When clicked, Button 2 reveals a
second design with four shapes and has a 50 px height and width.
2. Source code:
3. #include <iomanip>
4. #include <iostream>
5. using namespace std;
6.
7. int main() {
8.
9. int pay_code;
10. double total_pay =0 ;
11.
12. while (1) {
13. cout << "Enter employee's number code (-1 to end): ";
14. cin >> pay_code;
15.
16. //if the user enters -1 the program ends
17. if (pay_code == -1) {
18. break;
19. }
20. float weekly_pay;
21.
22. switch (pay_code) {
23.
24. case 1: {
25. //Team leaders weekly pay calculation
1
26. float tl; // team leader payment rate is shortned as tl
27. cout << "Enter the Team leader's pay rate: ";
28. cin >> tl;
29. weekly_pay = tl;
30. total_pay =total_pay+weekly_pay;
31. break;
32. }
33.
34. case 2: { //sales workers weekly pay calculation
35. float gws;//gross weekly sales is shortened as gws
36. cout << "Enter Sales employee's gross weekly sales: ";
37. cin >> gws;
38. weekly_pay = 500 + 0.065 * gws;
39. total_pay =total_pay+weekly_pay;
40. break;}
41.
42. case 3: { //piece workers weekly pay calculation
43. int pc; //pc stands fo number of pieces completed
44. float p_price;// p_price stands for price per piece
45. cout << "Enter the number of pieces completed: ";
46. cin >> pc;
47. cout << "Enter the employee's per piece pay rate: ";
48. cin >> p_price;
49. weekly_pay = pc * p_price;
50. total_pay =total_pay+weekly_pay;
51. break;}
52.
53. case 4: { //Hourly workers weekly pay calculation
54. float h_rate;//hourly rate
55. float h_worked;
56. const int w_hours = 60;//normal working hours is declared as an integer constant
57. cout << "Enter the hourly worker's pay rate: ";
58. cin >> h_rate;
59. cout << "Enter the number of hours worked: ";
60. cin >> h_worked;
61.
62. if (h_worked <= w_hours) {
63. weekly_pay = h_worked * h_rate;// calculation for weeklypay if condition is true
64. } else {
65. float ot_hours;
66. ot_hours = h_worked - w_hours;
67. weekly_pay = (w_hours * h_rate) + (ot_hours * (h_rate * 1.5));// calculation for weeklypay
if condition is false
68. }
69. total_pay =total_pay+weekly_pay;
70. break;
71. }
72.
73. default://if the entered code is not in the valied range
74. cout << "You have entered an invalid code." << endl;
75. break;
2
76. }
77.
78.
79.
80. if(pay_code > 0 && pay_code < 5) {
81. cout << fixed << setprecision(2) << "Fortnightly pay is: " << weekly_pay << endl;
82. }
83. //total payroll
84.
85.
86. }
87. //displaying the output
88.
89. cout << "The total payroll for the fortnight is: " << fixed << setprecision(2) << total_pay << endl;
90.
91. return 0;
92. }
3
Question 2
1. Program description
A C++ programme uses input from sales data, piece rates, or hours worked to
determine weekly compensation for several mobile manufacturing job types. In order
to provide effective administration and summary of staff remuneration inside the
business, the programme displays the computed pay and totals all payroll.
2. Source code:
#include <splashkit.h>
int main(){
while (!quit_requested())
{
process_events();
if (mouse_clicked(LEFT_BUTTON)){
if (mouse_x() >= 0 && mouse_x() <= 50 && mouse_y() >= 0 && mouse_y() <= 50){
clear_screen(COLOR_WHITE);
4
fill_rectangle (COLOR_BLUE, 220, 320, 60, 60);
fill_rectangle (COLOR_BLUE, 320, 320, 60, 60);
else if (mouse_x() >= 750 && mouse_x() <= 800 && mouse_y() >= 0 && mouse_y() <= 50){
//set the background color of the window
clear_screen(COLOR_WHITE);
// Draw head
fill_circle(COLOR_YELLOW, 400, 300, 150);
draw_circle(COLOR_BLACK, 400, 300, 150);
// Draw eyes
fill_circle(COLOR_RED, 350, 250, 40);
draw_circle(COLOR_BLACK, 350, 250, 40);
fill_circle(COLOR_RED, 450, 250, 40);
draw_circle(COLOR_BLACK, 450, 250, 40);
// Draw pupils
fill_circle(COLOR_BLACK, 350, 250, 20);
fill_circle(COLOR_BLACK, 450, 250, 20);
// Draw nose
fill_circle(COLOR_PINK, 400, 300, 20);
draw_circle(COLOR_BLACK, 400, 300, 20);
// Draw mouth
draw_line(COLOR_BLACK, 375, 350, 425, 350);
draw_line(COLOR_BLACK, 375, 350, 375, 380);
draw_line(COLOR_BLACK, 425, 350, 425, 380);
// Draw ears
fill_triangle(COLOR_BROWN, 250, 200, 300, 100, 350, 200);
draw_triangle(COLOR_BLACK, 250, 200, 300, 100, 350, 200);
fill_triangle(COLOR_BROWN, 550, 200, 500, 100, 450, 200);
draw_triangle(COLOR_BLACK, 550, 200, 500, 100, 450, 200);
}
}
refresh_screen(60);
5
}
return 0;
}
6
Question 3
1. Program description
A player throws three dice with a total of six faces and numbers ranging from 1 to 6.
On the three upward faces, the dots are added together. The player succeeds if the
total exceeds or equals 13 points. The player loses if the number is six or fewer. The
total of the first roll determines a point. The player must keep rolling the rolls in order
to win until they have proven their claim. The roll must be higher than or equal to 15
for the loser to lose before presenting the case.
2. Source code:
3. #include <iostream>
4. #include <cstdlib>
5. #include <ctime>
6. using namespace std;
7.
8. int rollDice() {
9. return (rand() % 6) + 1;
10. }
11.
12. int main() {
13. srand(time(NULL));
7
14.
15. int total = 0;
16. int points = 0;
17. int rolls = 0;
18.
19. while (true) {
20. rolls++;
21.
22. if (rolls == 1) {
23. cout << "First roll: ";
24. for (int i = 0; i < 3; i++) {
25. int dice = rollDice();
26. cout << dice;
27. total += dice;
28. if (i < 2) {
29. cout << " + ";
30. }
31. }
32. cout << " = " << total << endl;
33.
34. if (total >= 13) {
35. cout << "Player Wins" << endl;
36. break;
37. } else if (total <= 6) {
38. cout << "Player loses" << endl;
39. break;
40. } else {
41. points = total;
42. cout << "Point is " << points << endl;
43. }
44. } else {
45. cout << "Roll " << rolls << ": ";
46. for (int i = 0; i < 3; i++) {
47. int dice = rollDice();
48. cout << dice;
49. total += dice;
50. if (i < 2) {
51. cout << " + ";
52. }
53. }
54. cout << " = " << total << endl;
55.
56. if (total == points) {
57. cout << "Player wins" << endl;
58. break;
59. } else if (total >= 15) {
60. cout << "Player loses" << endl;
61. break;
62. }
63. }
64. }
8
65.
66. return 0;
67. }