Chapter 1 4 Progbook
Chapter 1 4 Progbook
CHAPTER 1
1.
A. FALSE
B. FALSE
C. FALSE
D. TRUE
E. TRUE
F. FALSE
G. TRUE
H. TRUE
I. FALSE
J. TRUE
K. FALSE
2. A, C, D and E
3. NO, THEY ARE NOT THE SAME
4. If x=5, y=6, z=4, and w=3.5, evaluate each of the following statements, possible, if is not
possible, state the reason.
A. Possible
B. Modulus operator are not applicable to float
C. Modulus operator are not applicable to float
D. Possible
E. Possible
F. Possible
G. Possible
H. Possible
5. A = 3;
B = 4;
C = (a%b)*6; = 18
D = c/b; = 4
E = (a+b+c+d)/4; = 7
7.
A. 32*a
B. char resultA= '8'
C. char a[100] = "Julie Nelson"
D. (b * b - 4 * a * c) / (2 * a)
E. ((a + b) / (c * e * f)) - (g * h * (b + (b * b - 4 * a * c)) / (2 * a))
8.
x = 20
z=6
w = 11.5
t = 4.5
9. a = .5
b = 24.5
c = it’s error it should be cout<<a/static_cast<double>(b)+2<<endl; to get 4.6
d = 8.3
e = 10
f = 38.75
10. A and C
CHAPTER 2
1. FUNCTION
2. MODULUS
3. RELATIONAL OPERATOR
4. ARITHMETIC OPERATOR
5. What separates employing an increment or decrement operator as a prefix and postfix in
expression evaluation is the timing of the value change. The precise moment of the value
change is considered in expression assessment. When (++x or --x) is used as a prefix, the
value is incremented or decremented first, and the modified value is utilized in the
expression. The expression starts with the current value and then modifies it by adding or
subtracting it when it appears as a postfix (x++ or x--).
6.
A. = 56
B. =1
C. =8
D. =7
E. Floating-point exception
7.
i = j++ - -- k = -4
i = k * -- i = 24
i = j * i++ = 5
8.
#include <iostream>
int main() {
cir = 2*pie*rad;
return 0;
9.
#include <iostream>
int main() {
int num_grade;
int grade;
else
return 0;
10.
#include <iostream>
int main() {
int num_grade;
int grade;
if (grade <= 3)
}
else
return 0;
Chapter 3.
4. DENTIFY THE ERROR(S), IF ANY, IN THE FOLLOWING PROGRAMS AND WRITE THEM
IN CORRECT FORMAT
a) #include <iostream>
int main() {
int a, b, Max;
if (a > b)
{
Max = a;
return 0;
b) #include <iostream>
int main() {
int x, y;
cin >> x;
if (x==y)
else
return 0;
6. ANY INTEGER IS INPUT BY THE USER. WRITE A PROGRAM TO FIND OUT WHETHER
IT IS AN ODD OR EVEN NUMBER.
#include <iostream>
int main() {
int num;
if (num % 2 == 1) {
cout << "The number " << num << " is odd." << endl;
} else {
cout << "The number " << num << " is even." << endl;
7. Prime or Not
#include <iostream>
using namespace std;
int main() {
int number;
bool prime = true;
cout << "Input integer: ";
cin >> number;
if (number <= 1) {
prime = false;
} else {
for (int i = 2; i * i <= number; i++) {
if (number % i == 0) {
prime = false;
break;
}
}
} if (prime) {
cout << "The number " << number << " is a prime number." << endl;
} else {
cout << "The number " << number << " is not a prime number." << endl;
}
}
8.
#include <iostream>
using namespace std;
int main() {
float quiz, mid, fin, ave;
char finalgrade;
if (ave >= 90.0) {
finalgrade = 'A';
} else if (ave >= 70.0) {
finalgrade = 'B';
} else if (ave >= 50.0) {
finalgrade = 'C';
} else {
finalgrade = 'F';
}
int main() {
int number;
10.
#include <iostream>
using namespace std;
int main() {
float num1, num2;
char op;
Chapter 4
1. WHAT IS THE DIFFERENCE BETWEEN A WHILE STATEMENT AND A DO-WHILE
STATEMENT?
When a certain Boolean condition is met, code can be continuously executed using a
control flow statement known as a while loop. A do-while loop, on the other hand, is a
control flow statement that terminates the loop or repeats the code block. The do while
construct is composed of a process symbol and a condition. The block's code is executed
first.
}
3. write a c++ program that asks the user for an integer and then prints out all its factors
in increasing order. Example input is 150, it should print:
2
3
4
5
5
#include <iostream>
using namespace std;
int main() {
int number;
cout << "Enter a number: ";
cin >> number;
if (number <= 0) {
cout << "Please enter a positive integer." << std::endl;
return 1;
}
cout << "Factors of " << number << " are: ";
for (int i = 1; i <= number; i++) {
if (number % i == 0) {
cout << i << " ";
}
}
cout << endl;
return 0;
}
4. Create a program in c++ that asks the user to enter 10 integers and write the number of
occurrence of the biggest value
#include <iostream>
using namespace std;
int main() {
int number[9];
int count = 0;
return 0;
}
5. Debug this program that aims to display the reverse the integer input. Write the exact
screen output when num is 12345
#include<iostream>
#include<stdlib.h
using namespace std;
main()
(
int num, rem;
cout<<”Enter a number: ”;
cin<<num;
do
{
rem=num%10;
num=num/100;
}
while(num)
cout<<”is the reverse:”<<endl;
system(pause);
}
Answer:
#include <iostream>
using namespace std;
int main() {
int num, re;
int rev = 0;
cout << "The reverse is: " << rev << endl;
}
return 0;
}
#include <iostream>
int main() {
int n;
cin >> n;
if (i == 1) {
continue;
if (i == 2) {
continue;
}
term1 = term2;
term2 = nextTerm;
return 0;
7. Create a c++ program that will accept a positive integer and display it's factorial.
#include <iostream>
using namespace std;
int main() {
int number;
if (number <= 0) {
cout << "Please enter a positive integer." << std::endl;
return 1;
}
cout << "Factors of " << number << " are: ";
for (int i = 1; i <= number; i++) {
if (number % i == 0) {
cout << i << " ";
}
}
cout << endl;
return 0;
}
int main() {
while(dig > 0)
dig /= 10;
cout <<endl<<ans;
return 0;
Answer: