Programming Sheet
Programming Sheet
Q1
1- int feet = 0, inches = 0;
2- int feet(0), inches(0);
Q2
int count = 0;
double distance = 1.5;
Q3
sum = n1 + n2;
Q4
length += 8.3;
Q5
product = n * n;
Q6
#include <iostream>
using namespace std;
int main() {
int a, b, c, d, e, f; // declared but not
initialized
cout << a + b + c + d + e + f << endl;
return 0;
}
Q7
a: carSpeed
b: hourlyPayRate
c: highestExamScore
Q8
cout << "The answer to the question of\
nLife, the Universe, and Everything is 42."
<< endl;
Q9
cout << "Enter a whole number: ";
cin >> _number;
Q10
cout << fixed << setprecision(3);
Q11
#include <iostream>
using namespace std;
int main() {
cout << "Hello world";
return 0;
}
Q12
#include <iostream>
using namespace std;
int main() {
int num1, num2;
cout << "Enter two numbers: ";
cin >> num1 >> num2;
cout << "The sum is: " << num1 + num2
<< endl;
return 0;
}
Q13
#include <iostream>
using namespace std;
int main() {
int num1, num2;
cout << "Enter two numbers: ";
cin >> num1 >> num2;
cout << "The sum is: " << num1 + num2
<< endl;
return 0;
}
Q14
#include <iostream>
#include <iomanip> // For formatting
output
return 0;
}
Q15
3*x
→3*x+y
→ (x + y) / 7
→ (3 * x + y) / (z + 2)
Q16
a = 'b';
b = 'c';
c = a;
cout << a << b << c << 'c';
Q16
a = 'b';
b = 'c';
c = a;
cout << a << b << c << 'c';
Q17
int number = (1 / 3) * 3;
cout << "(1/3) * 3 is equal to " << number;
Q18
#include <iostream>
using namespace std;
int main() {
int num1, num2;
cout << "Enter two numbers: ";
cin >> num1 >> num2;
return 0;
}