1. Which of the following variable declarations are correct? If a variable decla
ID: 667805 • Letter: 1
Question
1. Which of the following variable declarations are correct? If a variable declaration is not correct, give the reason(s) and provide the correct variable declaration.
double conversion = 2.5; //Line 1
char grade = 'B+'; //Line 2
double 28.5 = num //Line 3
string message = ''First C++ course'; //Line 4
int age = 18 years //Line 5
int perfectSquare; //Line 6
float x, y, decimal; //Line 7
2. What actions must be taken before a variable can be used in a program?
3. Which of the following are valid C++ identifiers?
a.new-Assignment
b._nextQuiz
c.3rdProject
d.$twoHundred
e.CPP_Project
f.OneInchIs2.2Centimeters
g.Weekly Quiz
h.Jack'sHomework
i.first#
j.overPayment
4. Which of the following is a reserved word in C++?
a.main
b.#include
c.double
d.Const
e.cin
f.bool
5. What is the difference between a reserved word and a user-defined identifier?
6. Are the identifiers quizNo1 and quizno1 the same?
7. Give meaningful identifiers for the following variables and write a proper C++ declaration and initialization to a reasonable value.
a.A variable to store the first name of a student.
b.A variable to store the discounted price of an item.
c.A variable to store the number of juice bottles.
d.A variable to store the number of miles traveled.
e.A variable to store the highest test score.
8. Given:
int num1, num2, newNum;
double x, y;
Which of the following assignments are valid? If an assignment is not valid, state the reason.
a.num1 = 35;
b.newNum = num1 – num2;
c.num1 = 5; num2 = 2 + num1; num1 = num2 / 3;
d.num1 * num2 = newNum;
e.x = 12 * num1 - 15.3;
f.num1 * 2 = newNum + num2;
g.x / y = x * y;
h.num2 = num1 % 2.0;
i.newNum = static_cast<int> (x) % 5;
j.x = x + y - 5;
k.newNum = num1 + static_cast<int> (4.6 / 2);
9. Suppose that x, y, z, w, and t are int variables. What is stored in x, y, z, w, and t after the following statements execute?
x = 5;
y = x + 2;
z = x % (y - 2) + 4;
w = (x * y) / z - 5;
t = z + (x + y + 2) % w;
10. Which of the following are valid C++ assignment statements? Assume that i is an int variable, and x and percent are double variables.
a.i - 5 = x;
b.i = i++;
c.x = x * percent / 100;
d.percent = 0.05%;
Explanation / Answer
This question has multiple subparts. I have answered first 6. please post one more question.
1)
line 3 is not correct.
double num=28.5;//Line 3
line 4 is not correct.
string message = "First C++ course"; //Line 4
line 6 is not correct.
int age = 18;
2)
it must be declared
3)
b c h i j
4)
cin
5)
reserved word cannot be defined again.user defined are the shortcuts used by user
6)
no they are different
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.