### need help with a few homework problems

 ``12345678910`` ``````The output produced by the following statement: ______ cout << left << setw(6) << "X:" << setprecision(3) << right << setw(7) << 1.2345 << ':'; NOTE: You MUST use the caret (^) to indicate a space. Example: FAT CAT must be written FAT^^CAT. ``````

`// I have tried the answers: "X:^^^^^^1.24:" && "X:^^^^^1.235:" `

 ``1234567891011121314`` ``````Consider the code segment: char Sentence[15]; cin >> Sentence >> Sentence; cout << Sentence; Consider the input: FAT CAT RAN SLOWLY The output produced is _____________________ . NOTE: You MUST use the caret (^) to indicate a space. Example: FAT CAT must be written FAT^^CAT.``````

` // Ive tried: "FAT^CAT^RAN^SLOFAT^CAT^RAN^SLO" `

 ``1234567891011121314151617`` ``````Consider the code segment: #include ... int main() { int Num; char infileName[25]; ifstream inF; ... inF.open("myInputs.dat"); ... //-| Read value for Num. ___________________________________ }``````

` // Ive tried answers: "ifstream num;" , "ifstream inf;" && "ifstream inf;" `

For the first one, you left justify and set width to 6, so there will be 4 spaces after X:. Then you set the precision to 3, meaning that 3 numbers will be shown (note that they are NOT rounded as you are doing), right justify and set width to 7. The output is 1.23, which takes up 4 spaces, leaving 3 in the front, for a total of 7 spaces between the two outputs. Next just slap a ':' on the end of it and you're set.

Edit: For the second one, after cin >> Sentence >> Sentence; executes, all that is left in Sentence is CAT. This is because cin >> Sentence stops at the first whitespace, in this case the space between FAT and CAT. At this point, the contents of Sentence is "FAT". Then the next call, >> Sentence, stops at the space between CAT and RAN. This overwrites the previous contents of Sentence, leaving just "CAT". "RAN SLOWLY" is never seen by the program. That should be enough for you to get this one.

Edit2: For the third one, I don't really know what it is asking. Does it want you to input data from the file into Num? If so, you do this by treating the input file stream just like the console input stream (inF >> Num;).
Last edited on
thanks man you helped alot. and on the third one that is exactly what he wanted. the answer was inf >> num;
Topic archived. No new replies allowed.