CP 123
CP 123
I. E
II. C
III. D
IV. B
V. A
VI. A
VII. B
VIII. D
IX. C
X. A
Question. 2
I. I
II. O
III. F
IV. G
V. E
VI. J
VII. P
VIII. H
IX. N
X. M
Question 3.
a. I.char grade=’A’
II.bool paymentStatus=true;
III.int juiceBotleSold=0;
IV.double billingAmount=0.0;
V.float GPA=0.0;
II.temp=temp+5;
III.double payRate=12.50;
IV.int tempNum=firstNum;
Question 4.
a.I.marks
II. double values
III.28
IV.29
b. While loop is used when number of iteration is known ,also has condition statement at the
beginning.while
For loop is used when number of iteration is known,also has initialization, condition,and
increment/decrement statement.
c. sum=sum+values[iI;
d . #include <iostream>
int main() {
int values[5];
int sum=0;
} Sum=values[0]+values[1]+values[2]+values[3]+values[4];
Return 0;
Question 5.
a. 1. net_price_per_copy: float
2. estimated_copies_sold: int
3. fixed_royalty_upon_delivery: float
4. fixed_royalty_upon_publication: float
5. royalty_rate_option2: float
6. royalty_rate_first_4000: float
7. royalty_rate_above_4000: float
b .#include <iostream>
#include <iomanip>
Int main() {
Float net_price_per_copy;
Int estimated_copies_sold;
Cout << “Enter the net price of each copy of the novel (in Tshs): “;
Cout << “Enter the estimated number of copies that will be sold: “;
Float total_royalty_option3;
} else {
}
Cout << fixed << setprecision(2); // Formatting the output to 2 decimal places
Return 0;
c.
Question 6.
a.Output:
b.output:
27
c.Outputs:
0
1
d.
e. Syntax error
Should be written as
#include<iostream>
Int main() {
If (0) {
else
Return 0;
Question 7:
a.The program will throw an error, specifically a ValueError, because it cannot convert a string into an
integer.
b.#include <iostream>
char operation ;
int addition ;
int subtraction ;
int multiplication ;
If(addition){
Cout << num1 << “ + “ << num2 << “ = “ << (num1 + num2) << endl;
If(subtraction){
Cout << num1 << “ – “ << num2 << “ = “ << (num1 – num2) << endl;
If(multiplication){
Cout << num1 << “ * “ << num2 << “ = “ << (num1 * num2) << endl;
If (num2 != 0){
Cout << num1 << “ / “ << num2 << “ = “ << (num1 / num2) << endl;
Else{
Cout << “Invalid operation. Please select one of +, -, *, /.” << endl;
Return 0;
d.
Question 8.
Identifier: userInput
II.Remainder value:
Identifier: remainder
III.Continue flag:
Identifier: continueFlag
Identifier: validInput
V.Termination flag:
Identifier: terminateFlag