Write C++ statements for each of the following: a) Write two ways to put comment
ID: 2247252 • Letter: W
Question
Write C++ statements for each of the following: a) Write two ways to put comments in C++. b) Declare a named constant RATE and assign a value of 25 to it. c) Declare a float variable x, and provide prompt (using cout) to enter a value for x and then read a floating point number from keyboard into x. d) Given a variable d = 1.555E2, write a statement to display this in decimal format with a precision of 2. e) Write an output statement to print the number of characters in the title of our text book. Declare and initialize the Text first, and then use string operations. f) Declare a char variable char 1 and then prompt the user to read a value for the variable char 1 from the keyboard. g) Given an input stream (keyboard entry): Hello To All Write an appropriate statement to read this value into a variable named string I h) Write an output statement to print out the title of our text book (Programming and Problem Solving in C++) i) Write a C++ expression that compares the int variable number to the constant 15 and yields true if number is greater than or equal to 15 Given: int a = 7, b = 3, c = 5, p = 2, q = 3: j) What are the values of the following expression (i) a/b (ii) a % b (iii) a++ (iv) a == b (v) p+q ! = c (b) What are the values of the following expressions. (i) a*(c - b)/p (ii) p + b% c - q (iii) b/a + c Give a valid example for each of the following: a) Identifier b) Data TypeExplanation / Answer
5.
a)Single-line comments : It starts with // and continue until the end of the line. If the last character in a comment line is a the comment will continue in the next line.
Multi-line comments : It starts with /* and ends with */.
b)Using #define Preprocessor
#define RATE 25
or by using const keyword
const double RATE=25;
c)float x;
d)It can be written as 1.555×10^2=1.555×100
=155.5
with precision 2 it cam be written as 155.50
therefore statement will be
float d=155.50;
e)
f)
h)
i)
int number;
const int n= 15;
cout << "Please enter any integer value: ";
cin >> number;
if (number>=n)
cout <<"true";
return 0;
6)Assumption all the answers are in integers since in integer decimal value is ignored like in division 7/2 will give 3 and not 3.5 if result is in integer.And also if the denominator is not in double or float then also an integer value is stored in result.Here every value is having integer data type so reult will be in integer only and decimal value will be ignored.
Answers
a) i) 2
ii) 1(% returns remainder left after division)
iii) 8 (a++= >a=a+1)
iv) false( comparison always return either true or false)
v)false
b) i) 7*2/2= 7
ii) 2+1-3=0
iii) 3/7+5 =0+5=5
7. valid example
a)number1
ex. int number1= 8;
b)int
ex int a=4;
extra explanation for 7a) there are rules for naming an identifier they are
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.