Professional Documents
Culture Documents
QUESTION 1
QUESTION 2
a. valid
b. valid
c. valid
d. valid
e. valid
f. invalid – start with a digit
g. valid
h. invalid – using $
i. invalid – using ()
j. invalid – using !
QUESTION 3
a. int
b. char
c. float
d. int
e. double
f. boolean
QUESTION 4
a. invalid
b. valid
c. invalid
d. valid
e. invalid
f. invalid
QUESTION 5
a. 25 / 3 = 8
b. 20 - 12 / 4 * 2 = 14
c. 32 % 7 = 4
d. 3 - 5 % 7 = -2
e. 18.0 / 4= 4.5
f. 28 - 5 / 2.0 = 25.5
g. 17 + 5 % 2 - 3 = 15
h. 15.0 + 3.0 * 2.0 / 5.0 = 16.2
QUESTION 6
a) (5 + 4) % 6= 3 (possible)
b) (5 + 6) % 3.5 = 4 (not possible because right operand has data type double)
c) (6 + 3.5.) % 5= 4.5 (not possible because right operand has data type double)
e) (5 % 6) % 4= 1 (possible)
f) (6 % 4) % 5= 2 (possible)
g) (5 * 4) % 6= 2 (possible)
QUESTION 7
a) 17 + 15 / 4 = 20
b) 20 % 3 + 4 = 6
c) 17 / 3 + 6.5 = 11.5
QUESTION 8
Sequence example1
#include <iostream>
#include <conio.h>
int main() {
// variable declaration
// input
cout << "insert radius: ";
cin >> radius;
// process
// output
cout << "The circle area is: " << circleArea << endl;
_getch;
return 0;
}
Sequence example2
#include <iostream>
#include <conio.h>
int main() {
// variable declaration
double netBalanced, payment, d1, d2, interestRate, averageDailyBalance, interest;
// input
cout << "insert net balanced: ";
cin >> netBalanced;
cout << "insert payment: ";
cin >> payment;
cout << "insert the number of days in the billing cycle : ";
cin >> d1;
cout << "insert the number of days payment is made before billing cycle ";
cin >> d2;
cout << "insert interest rate: ";
cin >> interestRate;
// process
averageDailyBalance = (netBalanced * d1 - payment * d2) / d1;
interest = averageDailyBalance * interestRate;
// output
cout << "The interest is: " << interest << endl;
_getch;
return 0;
}
QUESTION 10
#include <iostream>
using namespace std;
int main()
{
// variable declaration
float num1, num2, num3, num4, num5, average, sum;
// input
cout << "Enter 5 decimal numbers separated by a space : ";
cin >> num1 >> num2 >> num3 >> num4 >> num5;
// process
sum = num1 + num2 + num3 + num4 + num5;
average = sum / 5;
// output
cout << "The average of the 5 number : " << average << endl;
cout << "sum is: " << sum << endl;
return 0;
QUESTION 11
#include <iostream>
#include <conio.h>
int main() {
// variable declaration
double length_in_centimeter, width_in_centimeter;
// input
cout << "insert length: ";
cin >> length_in_centimeter;
// process
width_in_centimeter = length_in_centimeter / 1.5;
//output
cout << "the width is: " << width_in_centimeter << "cm" << endl;
cout << "the lenght is: " << length_in_centimeter << "cm" << en
_getch;
return 0;
}
QUESTION 12
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main() {
// variable declaration
string itemCode, description;
float itemPrice, discountRate, newSalePrice;
// input
cout << "enter item code : ";
cin >> itemCode;
cout << "enter description : ";
cin >> description;
cout << "enter item price (MYR) : ";
cin >> itemPrice;
// process
discountRate = (0.05 * itemPrice) / 100;
newSalePrice = itemPrice - discountRate;
//output
_getch;
return 0;
Question 13
#include <iostream>
#include <string>
#include <conio.h>
int main() {
// variable declaration
string name;
float feet, inches, height, weight, bmi;
//input
cout << "Enter your name: ";
cin >> name;
cout << "Enter your height in feet and inches (Separate feet and inches by a space): ";
cin >> feet >> inches;
cout << "Enter your weight in kg: ";
cin >> weight;
//process
height = (feet * 0.3048) + (inches * 0.0254);
bmi = weight / (height * height);
//output
cout << "Name: " << name << endl;
cout << "Height: " << height << "m" << endl;
cout << "Weight: " << weight << "kg" << endl;
cout << "BMI: " << bmi << endl;
_getch;
return 0;
}