C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
bartleby

Videos

Textbook Question
Book Icon
Chapter 2, Problem 1TF

Mark the following statements as true or false.

  1. An identifier must start with a letter and can be any sequence of characters. (1)

  2. In C++, there is no difference between a reserved word and a predefined identifier. (1)

  3. A C++ identifier cannot start with a digit. (1)

  4. The collating sequence of a character is its preset number in the character data set. (2)

  5. Only one of the operands of the modulus operator needs to be of type int. (3)

  6. If a = 4 ; and b = 3 ;, then after the statement a = b ; the value of b is erased. (6)

  7. If the input is 7 and x is a variable of type int, then the statement c i n > > x ; assigns the value 7 to x. (6)

  8. In an output statement, the newline character may be a part of the string. (10)

  9. In C++, all variables must be initialized when they are declared. (7)

  10. In a mixed expression, all the operands are converted to floating-point numbers. (4)

  11. Suppose x = 5 . After the statement y = x + + ; executes, y is 5 and x is 6. (9)

  12. Suppose a = 5 . After the statement + + a ; executes, the value of a is still 5 because the value of the expression is not saved in another variable. (9)

a.

Expert Solution
Check Mark
Program Plan Intro

Identifiers is one of the category of tokens. Identifiers are names of things that appear in programs, such as variables, constants, and functions and must obey C++’s rules for identifiers.

Program Description Answer

An identifier can begin with underscore also. Hence, the given statement is “False”.

Explanation of Solution

A C++ identifier consists of letters, digits, and the underscore character (_) and must begin with a letter or underscore.

b.

Expert Solution
Check Mark
Program Plan Intro

Reserved words and predefined identifiers are both categories of tokens. Reserved words are also called keywords. The letters that make up a reserved word are always lowercase. Identifiers are names of things that appear in programs, such as variables, constants, and functions.

Program Description Answer

In C++ reserved words and predefined identifiers are different. Hence, the given statement is “False”.

Explanation of Solution

Predefined identifiers can be re-defined whereas reserved words cannot be. Reserved words are always lower case whereas identifiers can be both lower and upper case.

c.

Expert Solution
Check Mark
Program Plan Intro

Identifiers is one of the category of tokens. Identifiers are names of things that appear in programs, such as variables, constants, and functions and must obey C++’s rules for identifiers.

Program Description Answer

In C++ an identifier cannot start with a digit. Hence, the given statement is “True”.

Explanation of Solution

A C++ identifier must begin with a letter or underscore. So beginning with digit not allowed.

d.

Expert Solution
Check Mark
Program Plan Intro

The data type char is mainly used to represent single characters—that is, letters, digits, and special symbols. Thus, the char data type can represent every key on your keyboard. Several different character data sets are currently in use. The most common are the American Standard Code for Information Interchange (ASCII) and Extended Binary- Coded Decimal Interchange Code (EBCDIC). Each of the 128 values of the ASCII character set represents a different character. For example, the value 65 represents 'A', and the value 43 represents '+'. Thus, each character has a predefined ordering represented by the numeric value associated with the character.

Program Description Answer

The collating sequence of a character is its preset number in the character data set. Hence, the given statement is “True”.

Explanation of Solution

In a character set each character has a predefined ordering represented by the numeric value associated with the character. This ordering is called a collating sequence, in the set. The collating sequence is used when you compare characters. For example, the value representing 'A' is 65 and value representing 'B' is 66, so 'A' is smaller than 'B'.

e.

Expert Solution
Check Mark
Program Plan Intro

You use modulus operator with only the integral data type, to find the remainder in ordinary division.

Program Description Answer

You use modulus operator with only the integral data type, to find the remainder in ordinary division. Hence, the given statement is “False”.

Explanation of Solution

You use modulus operator with only the integral data type, to find the remainder in ordinary division. Hence both the operands need to be of integral type.

f.

Expert Solution
Check Mark
Program Plan Intro

An assignment statement takes the following form:

variable = expression;

In an assignment statement, the value of the expression should match the data type of the variable. The expression on the right side is evaluated, and its value is assigned to the variable (and thus to a memory location) on the left side. = is called the assignment operator.

Program Description Answer

If a = 4; and b = 3; then after the statement a = b; the value of b is not erased. Hence, the given statement is “False”.

Explanation of Solution

If a = 4; and b = 3; then after the statement a = b; the value of b is not erased. a and b are names of two different memory locations initially storing the values 4 and 3 respectively. After the assignment statement a = b; a is made to point to the same memory location as pointed to by the variable named b. Hence, the value pointed to by both a and b now is 3. In other words the value of the variables a and b is the same, which is 3.

g.

Expert Solution
Check Mark
Program Plan Intro

Putting data into variables from the standard input device is accomplished via the use of cin and the operator >>. This is called an input (read) statement. In C++, >> is called the stream extraction operator.

Program Description Answer

If the input is 7 and x is a variable of type int, then the statement cin >> x; assigns the value 7 to x. Hence, the given statement is “True”.

Explanation of Solution

The statement cin >> x; causes the computer to get the input, which is 7, from the standard input device and store it in the variable x. That is, after this statement executes, the value of the variable x is 7.

h.

Expert Solution
Check Mark
Program Plan Intro

The newline character is '\n' causes the insertion point to move to the beginning of the next line before printing there. \n may appear anywhere in the string. When \n appears in a string in an output statement, it causes the insertion point to move to the beginning of the next line on the output device.

Program Description Answer

In an output statement, the newline character may be a part of the string. Hence, the given statement is “True”.

Explanation of Solution

Since the newline character can appear anywhere in the string in an output statement, it implies that it may be part of the string which is to be sent to the output.

i.

Expert Solution
Check Mark
Program Plan Intro

After declaring a variable, you can use an assignment statement to initialize it. It is possible to initialize and declare variables at the same time. When a variable is declared, C++ may not automatically initialize variables. When a variable is declared, memory is allocated for it and if you only declare a variable and do not instruct the computer to put data into the variable, the value of that variable is garbage.

Program Description Answer

In C++, all variables may not be initialized when they are declared. Hence, the given statement is “False”.

Explanation of Solution

It is possible to declare a variable but not initialize it. The declaration and initialisation can be split into two statements. In the first statement the variable is declared and in a subsequent statement the variable is initialized using an assignment operator as follows:

int first;

first = 10;

j.

Expert Solution
Check Mark
Program Plan Intro

When evaluating an operator in a mixed expression if the operator has the same types of operands (that is, either both integers or both floating-point numbers), the operator is evaluated according to the type of operands. If the operator has both types of operands (that is, one is an integer and the other is a floating-point number), then during evaluation, the integer is changed to a floating-point number with the decimal part of zero and the operator is evaluated. The result is a floating-point number.

Program Description Answer

In a mixed expression, all the operands are not always converted to floating point numbers. Hence, the given statement is “False”.

Explanation of Solution

In a mixed expression if an operator has the same types of operands and they happen to be both integers then the operator is evaluated into an integer type. In this case the operands are not converted to floating point numbers.

k.

Expert Solution
Check Mark
Program Plan Intro

Increment operators each have two forms, pre and post. The syntax of the increment operator is:

Pre-increment: ++variable

Post-increment: variable++

Increment and decrement operators are built into C++, the value of the variable is quickly incremented or decremented without having to use the long form of an assignment statement. Both the pre-and post-increment operators increment the value of the variable by 1.

Program Description Answer

Suppose x = 5. After the statement y = x++; executes, y is 5 and x is 6. Hence, the given statement is “True”.

Explanation of Solution

As before, the first statement assigns 5 to x. In the second statement, the post- increment operator is applied to x. In the second statement, first the value of x, which is 5, is used to evaluate the expression, and then the value of x is incremented to 6. Eventually, the value of the expression, which is 5, is stored in y. Hence after the second statement executes, the value of x is 6, and the value of y is 5. This execution is equivalent to the following set of statements:

  x = 5;

  y = x;

  x = x + 1;

l.

Expert Solution
Check Mark
Program Plan Intro

Increment operators each have two forms, pre and post. The syntax of the increment operator is:

Pre-increment: ++variable

Post-increment: variable++

Increment and decrement operators are built into C++, the value of the variable is quickly incremented or decremented without having to use the long form of an assignment statement. Both the pre-and post-increment operators increment the value of the variable by 1.

Program Description Answer

Suppose a = 5. After the statement ++a; executes, the value of a is 6 and not 5 although the value of the expression is not saved in another variable. Hence, the given statement is “False”.

Explanation of Solution

The statement ++a; is equivalent to the following assignment statement:

a = a+ 1;

Hence after the execution of the statements a = 5; ++a; the value of a is 6 as the incremented value of a is implicitly assigned back to the original variable a.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Write a C++ program of the following statements: part a: Write a C++ program that takes 4 integer variables and prints its addresses. Part b: Write a C++ Program to assign data to members of a structure variable and display it.
Write difference between C struct and C++ struct
I need solution for these in c++ language in selection statments topic

Chapter 2 Solutions

C++ Programming: From Problem Analysis to Program Design

Ch. 2 - Which of the following are valid C++ assignment...Ch. 2 - Write C++ statements that accomplish the...Ch. 2 - Write each of the following as a C++ expression....Ch. 2 - Prob. 14SACh. 2 - Suppose x, y, and z are int variables and wandt...Ch. 2 - 16. Suppose x, y, and z are int variables and x =...Ch. 2 - Suppose a and b are int variables, c is a double...Ch. 2 - 18. Write C++ statements that accomplish the...Ch. 2 - Which of the following are correct C++ statements?...Ch. 2 - Give meaningful identifiers for the following...Ch. 2 - 21. Write C++ statements to do the following....Ch. 2 - Prob. 22SACh. 2 - The following program has syntax errors. Correct...Ch. 2 - Prob. 24SACh. 2 - Prob. 25SACh. 2 - Preprocessor directives begin with which of the...Ch. 2 - 27. Write equivalent compound statements if...Ch. 2 - 28. Write the following compound statements as...Ch. 2 - 29. Suppose a, b, and c are int variables and a =...Ch. 2 - Suppose a, b, and sum are int variables and c is a...Ch. 2 - Prob. 31SACh. 2 - Prob. 32SACh. 2 - Prob. 33SACh. 2 - Prob. 34SACh. 2 - 1. Write a program that produces the following...Ch. 2 - Prob. 2PECh. 2 - Prob. 3PECh. 2 - 4. Repeat Programming Exercise 3 by declaring...Ch. 2 - Prob. 5PECh. 2 - Prob. 6PECh. 2 - 7. Write a program that prompts the user to input...Ch. 2 - Prob. 8PECh. 2 - 9. Write a program that prompts the user to enter...Ch. 2 - 10. Write a program that prompts the user to input...Ch. 2 - 11. Write a program that prompts the capacity, in...Ch. 2 - 12. Write a C++ program that prompts the user to...Ch. 2 - 13. To make a profit, a local store marks up the...Ch. 2 - 14. (Hard drive storage capacity) If you buy a 40...Ch. 2 - 15. Write a program to implement and test the...Ch. 2 - 16. A milk carton can hold 3.78 liters of milk....Ch. 2 - 17. Redo Programming Exercise 16 so that the user...Ch. 2 - Prob. 18PECh. 2 - 19. Write a program that prompts the user to input...Ch. 2 - 20. For each used car a salesperson sells, the...Ch. 2 - 21. Newton's law states that the force, , between...Ch. 2 - 22. One metric ton is approximately 2,205 pounds....Ch. 2 - 23. Cindy uses the services of a brokerage firm to...Ch. 2 - 24. A piece of wire is to be bent in the form of a...Ch. 2 - 25. Repeat Programming Exercise 24, but the wire...Ch. 2 - 26. A room has one door, two windows, and a...Ch. 2 - Prob. 27PECh. 2 - 28. In an elementary school, a mixture of equal...Ch. 2 - 29. A contractor orders, say, 30 cubic yards of...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Algebraic Expressions – Algebra Basics; Author: TabletClass Math;https://www.youtube.com/watch?v=U-7nq7OG18s;License: Standard YouTube License, CC-BY
Python Tutorial for Beginners 3 - Basic Math, Mathematical Operators and Python Expressions; Author: ProgrammingKnowledge;https://www.youtube.com/watch?v=Os4gZUI1ZlM;License: Standard Youtube License