Escolar Documentos
Profissional Documentos
Cultura Documentos
START
Calculate Total Pay = Normal Pay Rate x Normal Hours + Overtime ay Rate x Overtime Hours
Display TOTAL
END
2. Convert the flow chart of Figure 4.2 into correct C++ code. START
END
3. Given the following C++ program, compile and run the program. Write down any syntax error that occurs. Rewrite the program to correct the error. a.
1 2 3 4 5 6 7 8 9 //Program 4.1 #include <iostream> Using namespace std; int main ( ) { Cout << I like programming ; system (PAUSE) ; Return 0 ; }
b.
1 2 3 4 5 6 7 8 9 10 11 //Program 4.2 #include <iostream> Using namespace std; int main ( ) { Nilai1 = 4 ; int nilai1 ; cout << nilai1 ; system (PAUSE) ; return 0 ; }
c.
1 2 3 4 5 6 7 8 9 10 11 //Program 4.3 using namespace std; int main ( ) { int number ; cout << Enter an integer number : ; cin >> number ; cout << number ; system (PAUSE) ; return 0 ; }
d.
1 2 3 4 5 6 7 8 9 //Program 4.4 #include <iostream> using namespace std; int main ( ) { cout << This is my simple program system (PAUSE) ; return 0 ; }
4. Analyze the problem by giving a defining diagram, design an algorithm either pseudo code and / or flowchart (perform desk-checking), translate the design into a C++ program, compile, run and test with your own test data. You will receive an integer from the screen, add 5 to it, double it, subtract 7 from it, and display the final number on the screen.
5. Identify which one of the following would be an illegal variable name or identifier. Give reason for your selection.
i. ii. Total Student 3 students
6. Identify which of the following variable declaration are incorrect. Give reason for your answer and provide the correct variable declaration.
i. ii. iii. iv. v. Char aksara = b; Int n 12 ; Fload mark = 99.9 ; Short snum = 44444 ; Int wl = 20, w2 = 55; w4 = 190 ;
7. Write assignment statements that perform the following operations with variable a, b and c. i. Adds 2 to variable a and stores the result in b. ii. Multiplies b with 4 and stores the result in b. iii. Divides a by 3.14 and stores the result in b. iv. Subtracts 8 from b and stores the result in a. v. Stores the value 27 in a. vi. Stores the character L in c.
Algorithm 5.1 : Calculating total sales value for three items 1. 2. 3. 4. 5. 6. Start Store 12.95 in the item 1 variable. Store 24.95 in the item 2 variable. Store 6.95 in the item 3 variable. Sum up the three variables and store the result in the subtotal variable. Multiply the subtotal variable with 0.06 and store the result in the sales tax variable. 7. Subtract the sales tax amount from the subtotal and store the result in the total variable. 8. Display each items value, the subtotal value, the amount of sales tax and the total. 9. End.
Algorithm 5.2 : To calculate the total of three numbers 1. 2. 3. 4. 5. 6. 7. 8. Start Set TOTAL to 0 Read NUMBER 1 Read NUMBER 2 Read NUMBER 3 Add NUMBER 1, NUMBER2 and NUMBER 3 and store in TOTAL Display TOTAL End