Description
Question 1
What do the following two code segments print for the cases x = 1 and x = 10?
- i) while (x > 1) { ii) do { printf(“%d”, x); printf(“%d”, x);
x–; x–;
} } while (x > 1);
Question 2
- Write a C program to enter 4 module marks of a student from the keyboard and display the total of all four module marks.
- Modify the program written in i) above to enter 4 module marks of 3 students and display their total marks.
- Display the student with the highest total mark.
Question 3
Write a C++ program using for loops to display the following pattern on the screen.
*
**
***
****
*****
****** *******
*******
*****
***
*
Additional Exercises
Question 1
Write for statements that print the following sequences of values
- 1, 2, 3, 4, 5, 6, 7
- 3, 8, 13, 18, 23
- 20, 14, 8, 2, –4, –10
Question 2
A program is needed for Black Cabs Transport Company, to calculate the total amount a particular customer should pay for a given trip. The services provided by the cab service company are listed below.
| Package No | Package Name |
| 1 | Comfort Journey |
| 2 | Budget cab Journey |
| 3 | Crowded Journey – Dual A/C |
| 4 | Crowded Journey – Single A/C |
For comfort Journey package, Rs.150.00 is charged for the first kilometer and for each additional kilometer, Rs.175.00 will be charged. For a Budget cab Journey package each kilometer is charged at Rs. 100.00. For a Crowded Journey – Dual A/C package the first kilometer is charged at Rs. 130.00 and each remaining kilometer is charged at Rs.150.00. If the customer selected Crowded Journey – Single A/C package, the first kilometer is charged at Rs120.00 and for each remaining kilometer is charged at Rs. 130.00.
- Write a C program to input the package no and total distance of the tour in Kilometers through the keyboard. The program should display corresponding total amount that the customer has to pay. (Hint: use nested selection statements.)
Ex: Package No: 2
Total Distance: 5 Km Total Amount: Rs. 500
- Modify your program to display an error message “Invalid Package Number” if the user inputs a wrong package number.
- Modify the program to handle many customers. After displaying the total amount to pay by the first customer, your program should display the prompt “Do you have more customers?” If the user inputs “y” or “Y”, program should ask for the package no and total distance of the next customer. If the user inputs “n” or “N” program should terminate.




