#include <iostream.h>
|
|
|
|
| cin >> i; |
|
i = 32 |
| cin >> i >> j; |
|
i = 4, j = 60 |
| cin >> i >> ch
>> x; |
|
i = 25, ch = 'A', x = 16.9 |
| cin >> i >> ch
>> x; |
|
i = 25, ch = 'A', x = 16.9 |
| cin >> i >> ch
>> x; |
|
i = 25, ch = 'A', x = 16.9 |
| cin >> i >> j
>> x; |
|
i = 12, j = 8, waiting
for next input |
| cin >> i >> x; |
|
i = 46, x = 32.4, 15 held
for next input statement |
|
|
|
|
| cin >> ch1;
cin >> ch2; cin >> ch3 |
|
ch1 = 'A', ch2 = 'B', ch3 = 'C' |
| cin.get(ch1);
cin.get(ch2); cin.get(ch3); |
|
ch1 = 'A', ch2 = ' ', ch3 = 'B' |
cin.ignore(200, '\n');
The first parameter is the maximum number of characters
to skip. The second parameter is the skip-to character. The above statement
will cause C++ to skip up to 200 characters in the input stream until a
newline, /n, character
is encountered.
totalPrice = unitPrice * quantity;
cout << "The total price for " <<
quantity
<< " items
of part number " << partNumber << endl
<< "at
$" << setprecision(2) << unitPrice
<< " each
is $" << totalPrice << '.' << endl;
would have the following
output to the screen. The blue characters were typed
by the user.
Enter the part number: 4671
Enter
the quantity: 10
Enter
the unit price: 27.25
The
total price for 10 items of part number 4671
at $27.25
each is $272.50.
int main()
{
float amt1;
// Number of gallons for fillup 1
float amt2;
// Number of gallons for fillup 2
float amt3;
// Number of gallons for fillup 3
float amt4;
// Number of gallons for fillup 4
float startMiles;
// Starting mileage
float endMiles;
// Ending mileage
float mpg;
// Computed miles per gallon
ifstream inMPG;
// Holds gallon amounts and mileages
ofstream outMPG;
// Holds miles per gallon output
// Open the files
inMPG.open("inmpg.dat");
outMPG.open("outmpg.dat");
// Get data
inMPG >> amt1 >> amt2 >> amt3 >>
amt4
>> startMiles >> endMiles;
// Compute miles per gallon
mpg = (endMiles - startMiles)
/ (amt1 + amt2 + amt3 + amt4);
// Output results
outMPG << "For the gallon
amounts" << endl;
outMPG << amt1 <<
' ' << amt2 << ' '
<< amt3 << ' ' << amt4 << endl;
outMPG << "and a starting
mileage of " << startMiles
<< endl;
outMPG << "and an ending
mileage of " << endMiles << endl;
outMPG << "the mileage per
gallon is " << mpg << endl;
return 0;
}