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
Derive the run time of the following code
- in this exercise, please do not include and use string class. The function is using only array notation and manipulation.- string functions such as strlen is not allowed.- it should not have multiple return statements in the same function- there should be no global variable.- the function should not traverse the arrays more than once (e.g. looping through the array once only) A C++ PROGRAM named "changeCase" that takes an array of characters terminating by NULL character (C-string) and a boolean flag of toUpper. If the toUpper flag is true, it will go through the array and convert all lowercase characters to uppercase. Otherwise, it will convert all uppercase to lowercase. For example, if the array is {'H', 'e', 'l', 'l', 'o', '\0'} and the flag is true, then the array will become{'H', 'E', 'L', 'L', 'O', '\0'}. And if the flag is false, the array will become{'h', 'e', 'l', 'l', 'o', '\0'}
What’s the output of the following programs?

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.
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
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