Duration: 60 mins (1 hr) Marks: 40 Semester: Spring 2021
Course Code: CSSE4193 Course Instructors: Danish Javed, Sadaf Baloch, Saad Azhar Saeed INSTRUCTIONS: 1 Write down your name and registration number on every sheet. 2 State all your assumptions clearly. Answer all questions in context of class discussions, handouts and the text book. 3 Understanding question is a part of exam, therefore no queries will be entertained during exams. 4 You need to submit the exam within allocated time no extra time will be granted. Question 1: (Binary Marking) 4 Marks Attempt all questions in sequential order and use appropriate formats.
Question 2: Short Questions 9 + 12 = 21 Marks
(1) Consider the code of commission problem given below. List all du-paths for variables ‘finalPrice’, ‘totalPrice’ and ‘staffDiscount’. Which of the du paths are definition-clear? (5) 1 program Example 2 var staffDiscount, totalPrice, finalPrice, discount, price 3 staffDiscount = 0.1 4 totalPrice = 0 5 input(price) 6 while(price != -1) do 7 totalPrice = totalPrice + price 8 input(price) 9 end while 10 print("Total price: " + totalPrice) 11 if(totalPrice > 15.00) then 12 discount = (staffDiscount * totalPrice) + 0.50 13 else 14 discount = staffDiscount * totalPrice 15 end if 16 print("Discount: " + discount) 17 finalPrice = totalPrice - discount 18 print("Final price: " + finalPrice) 19 endprogram Format Variable Du Path DC Path(YES/NO) (2) For the code above (Question 2 part 1), write appropriate paths for the following slices: (a) S(finalPrice,18) (3) (b) S(totalPrice,10) (3) (c) S(discount,16) (3) (d) S(price,11) (3) Format Slice Path Question 3: 5+2.5+2.5+5 = 15 Marks For the following code perform the specified requirements (a) Make the CFG for the following Program (5) (b) Find cyclomatic complexity (2.5) (c) Write down the basis paths (2.5) (d) Write test cases for basis path testing (5) FORMAT Tid Input Actual Path #include <stdio.h> 1. int main() 2. { 3. int side1, side2, side3; /* Input three sides of a triangle */ 4. printf("Enter three sides of triangle: \n"); 5. scanf("%d%d%d", &side1, &side2, &side3); 6. if((side1 + side2) > side3) { 7. if((side2 + side3) > side1){ 8. if((side1 + side3) > side2){ /* * If side1 + side2 > side3 and * side2 + side3 > side1 and * side1 + side3 > side2 then * the triangle is valid. */ 9. printf("Triangle is valid."); } 10. else{ 11. printf("Triangle is not valid."); } } 12. else{ 13. printf("Triangle is not valid."); } } 14. else { 15. printf("Triangle is not valid."); } 16. return 0; 17. }