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
Modular Program Structure. Analysis of Structured Programming Examples. Ways to Reduce Coupling. Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsin⁡x Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.
Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsin⁡x Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.
Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsin⁡x Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.

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
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
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