- Write a single statement to accomplish each of following tasks:
- Use a stream manipulator to ensure that floating-point values print in scientific notation for when using cout .
- Use a stream manipulator to set the fill character to * for printing in field widths larger than the values being output using cout .
- Print 6789 right justified in an 8-digit field.
- Write a C++ statement that uses the manipulator setfill to output a line containing 40
pound signs, i.e., ######################################## .
- Identify error(s), if any, in the following array declarations. If a statement is incorrect, provide the correct statement.
- double weights[100];
- int age[0..80];
- int100 list[];
- double[50] salaries;
- Correct the following code so that it correctly sets the value of each element of myList to the index of the element.
int myList[10];
for (int i = 1; i <= 10; i) myList[i] = [i];
- What is stored in list after the following C++ code executes?
int list[10];
list[0] = 2; list[1] = 3;
for (int i = 2; i < 10; i++)
{ list[i] = list[i 1] + list[i 2]; if (i > 7) list[i] = 2 * list[i] list[i 2];
}
- Determine whether the following array declarations are valid. If a declaration is valid, determine the size of the array.
- int list[] = {18, 13, 14, 16};
- int x[10] = {1,7,5,3,2,8};
- double y[4] = { 2.0, 5.0, 8.0, 11.0, 14.0} ;
- int list[7] = {12, 13, , 14, 16, , 8};
- Write a single statement for each of the following one-dimensional array operations:
- Initialize the 10 elements of integer array counts to zero.
- Add 1 to each of the 15 elements of the integer array bonus .
- Read 12 values for double array scores from the keyboard.
- Write a code segment that finds the minimum and maximum values contained in a
99-element double array w .
- Write a code segment that finds the minimum and maximum values contained in a 4-by-6 int array t . (The declaration for t is int t[4][6]; )
10.Consider the following C++ code:
string str1; string str2; char ch; int index; cin >> str1; cin >> str2; cin >> index; ch = str1[index]; str1[index] = str2[index]; str2[index] = ch;
cout << str1 << << str2 << endl;
Answer the following questions:
- What is the output if the input is Hello There 2 ?
- What is the output if the input is Diamond Gold 0 ?
- What is the output if the input is C++ Java 1 ?
11.What is the output of the following C++ code?
string str1 = Trip to Hawaii; string str2 = Summer or Fall; string newStr;
newStr = str2 + + str1;
cout << newStr << endl;
cout << str1 + in + str2 << endl; cout << newStr.length() << endl; cout << str1.find(H) << endl; cout << str2.find(or) << endl; cout << newStr.substr(10, 19) << endl;
cout << newStr.replace(23, 6, ******) << endl;
string str = C++ Programming; cout << str << endl;
cout << str.length() << endl;
str[0] = J;
str[2] = $;
cout << str << endl;
12.Find the error(s) in each of the following, and explain how to correct it (them):
- string string1( 28 ); // construct string1
- string string2( z ); // construct string2
Reviews
There are no reviews yet.