0% found this document useful (0 votes)
23 views6 pages

126 Tuto 2

This document contains sample code and questions related to a CSC126 tutorial. It includes 13 multiple choice and coding questions on topics like variable naming rules, data types, operators, input/output, and basic programs calculating area, discounts, BMI, etc. The questions are answered in a step-by-step format with labeled sections for the question, code, and output.

Uploaded by

2021854164
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

126 Tuto 2

This document contains sample code and questions related to a CSC126 tutorial. It includes 13 multiple choice and coding questions on topics like variable naming rules, data types, operators, input/output, and basic programs calculating area, discounts, BMI, etc. The questions are answered in a step-by-step format with labeled sections for the question, code, and output.

Uploaded by

2021854164
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

CSC126 TUTO 2 – AQMA AZWA BINTI JAMALUDIN

SITI HUSNA NAJIHA BINTI SUHAIMI

QUESTION 1

1. Consist of letters, digits, underscore


2. Begin with letter or underscore

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)

d) (5 + 6) * 3.5= 38.5 (possible)

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

d) 20 / 4.0 + 15 % 4 - 3.5 = 1.5

QUESTION 8

1. int num1, num2, sum;


2. double pounds, kilogram;
3. double radius, diameter, circumference;
4. int salary;
5. int numOfSub; double fee;
QUESTION 9

Sequence example1
#include <iostream>
#include <conio.h>

using namespace std;

int main() {

// variable declaration

double circleArea, radius;

// input
cout << "insert radius: ";
cin >> radius;

// process

circleArea = 3.1416 * radius * radius;

// output
cout << "The circle area is: " << circleArea << endl;

_getch;
return 0;
}

Sequence example2

#include <iostream>
#include <conio.h>

using namespace std;

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>

using namespace std;

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

cout << "item code : " << itemCode << endl;


cout << "description : " << description << endl;
cout << "new sale price :RM " << newSalePrice << endl;

_getch;
return 0;

Question 13
#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

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;
}

You might also like