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
Correct my mistake in my C++ code please! Here is the questin and my code is below as well. (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. Code; #include <iostream> using namespace std; int main(){ int arr[100]={0};int temp,i;for( i=0;i<20;i++){    cout<<"Enter an Integer : ";    cin>>temp;    arr[temp]++;}for( i=0;i<100;i++)  if(arr[i]==1)    cout<<i<<" ";  return 0;}
Write C++ statements to do the following:i.Declare an empty array DATA to hold 7 double floating values.ii.Assign value 5.7 to the last element in the array.iii.Display the sum of the first two elements without using extra memory variable.iv.Write a while-loop that computes the sum of all elements in the array.v.Write a while-loop that finds the minimum element in the array.vi.Randomly generate an index and display the element at this (randomly generated) index in the array.vii.Use an array initializer to declare another array with initial values 5.78, 12.69, 10.45, and19.0
USE C++ (Display matrix of 0s and 1s) Write a function that displays an n-by-n matrix using the following header: void printMatrix(int n) Each element is 0 or 1, which is generated randomly. Write a test program that prompts the user to enter n and displays an n-by-n matrix. Here is a sample run:

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
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