Question: 1. Write C++ statements: write a statement for each of the following: a. Print integer 40000 left justified in a 15-digit field. b. Read a

1. Write C++ statements: write a statement for each of the following:

a. Print integer 40000 left justified in a 15-digit field.

b. Read a string into character array variable state.

c. Print 200 with and without a sign.

d. Print the decimal value 100 in hexadecimal form preceded by 0x.

e. 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 p from the input stream, and discard it.

f. Print 1.234 in a 9-digit field with preceding zeros.

2. Write a program that converts integer Fahrenheit temperatures from 0 to 212 degrees to floating-point Celsius temperatures with3 digits of precision. Use the formula

celsius = 5.0 / 9.0 * (fahrenheit 32);

3. Write a program that accomplishes each of the following:

a. Create a user-defined class Point that contains the private integer data members xCoordinate and yCoordinate and declares stream insertion (<<) and stream extraction (>>) over-loaded operator functions as friends of the class.

b. Define the stream insertion and stream extraction operator functions. The stream extraction operator function should determine whether the data entered is valid, and, if not, it should set the failbit to indicate improper input.

input.setstate(std::ios::failbit);

The stream insertion operator should not be able to display the point after an input error occurred.

c. Write a main function that tests input and output of user-defined class Point, using the overloaded stream extraction and stream insertion operators.

d. See Fig 10.3 to Fig 10.5 for examples, page 456-457 of the C++ book

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!