C How to Program (8th Edition)
C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 21, Problem 21.6E

(Write C++ Statements) Write a statement for each of the following:

  1. Print integer 40000 left justified in a 15-digit field.
  2. Read a string into character array variable state.
  3. Print 200 with and without a sign.
  4. Print the decimal value 100 in hexadecimal form preceded by 0x.
  5. Read characters into array charArray until the character ‘p’ is encountered, up to a limit of 10 characters (including the terminating null character). Extract the delimiter from the input stream, and discard it.
  6. Print 1.234 in a 9-digit field with preceding zeros.

a.

Expert Solution
Check Mark
Program Plan Intro

To print integer 4000 left justified in a 15-digit field.

Explanation of Solution

The function setw() is used in C++ to adjust the field width for output.

intleftalign=4000;

cout<<setw(15)<<leftalign;

b.

Expert Solution
Check Mark
Program Plan Intro

To read a string into character array variable state.

Explanation of Solution

Following statement will read as string into character array variable state.

cin>>state;

c.

Expert Solution
Check Mark
Program Plan Intro

To print 200 with and without a sign.

Explanation of Solution

Following statement will print the number 200 with sign

cout<< “+200”;

Following statement will print the number 200 without sign

cout<< “200”;

d.

Expert Solution
Check Mark
Program Plan Intro

To print the decimal value 100 in hexadecimal form preceded by 0x.

Explanation of Solution

Following set of statement will print the decimal value 100 as specified.

cout<<”Print the value decimal value 100 in hexadecimal format”;

inttoHex = 100;

cout<<”The decimal number 100 converted to hexadecimal =”;

e.

Expert Solution
Check Mark
Program Plan Intro

To read the characters into array charArray until the character ‘p’ is encountered, upto a limit of 10 characters (including the terminating null character). To extract the delimiter from the input stream and discard it.

Explanation of Solution

char array[10];
for( int i=0;i<10; i++)
{
	if(array[i]!=‘p’)
	{
cout<<array[i];
}
else break;
}
array[--i] = “”;

f.

Expert Solution
Check Mark
Program Plan Intro

To print 1.234 in a 9-digit field with preceding zeros.

Explanation of Solution

Following statement will print 1.234 with 9 digit field with preceding zeros.

cout<<setfill('0')<<setw(9)<<1.234;

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
Answer in C++ code please! (Duplicate Elimination with array) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, validate it and store it in the array only if it isn't a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Provide for the 'worst case' in which all 20 numbers are different. Use the smallest possible array to solve this problem.
Decide which of the following statements is either true or false and re-correct the false ones. 5. do … while repetition statement gives full control on the code block to be repeated. 6. All binary operators except for the assignment operators are evaluated from Left to Right 7. A ragged 2D array is a 2D array in which each column may contain different number of rows. 8. Each row in a 2D array could be dealt with as 1D array. 9. The following statement creates and initializes the array x: int x[] = {10, 20, 30, 40, 50}; 10. A Java program may contain more than one method with the same signature.
Exercise 2. (Pascal's Triangle) Pascal's triangle Pn is a triangular array with n+1 rows, each listing the coefficients of the binomial expansion (x+ y)', where 0 _ "/workspace/project3 рython3 pавса1.ру 10 1 1 1 1 2 1 1 33 1 1 4 6 4 1 1 5 10 10 5 1 16 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1 1 10 45 120 210 252 210 120 45 10 1 В равса1.ру import stdarray import stdio іпрort вys # Accept n (int) as command -line argument. ... # Setup a 2D ragged list a of integers. The list must have n + 1 rovs, vith the ith (0 <= i # <= n) row a[i] having i + 1 elements , each initialized to 1. For example, if n = 3, a should be # initialized to [[1], [1, 1], [1, 1, 1], [1, 1, 1, 1]]. a =... for i in range (...): ... # Fill the ragged list a using the formula for Pascal's triangle 1] [j - 1) + a[i - 1] [j] a [i][j] = a[i - 1] [j - 1] + a[i - 1] [j] #3 # vhere o <- i <- n and 1 <= j < i. for i in range (...): for j in range (...): ... # Write a to standard…

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
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
1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation; Author: Jenny's lectures CS/IT NET&JRF;https://www.youtube.com/watch?v=AT14lCXuMKI;License: Standard YouTube License, CC-BY
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License