Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
ifstream fin("foo.txt");
int count = 0;
char c = 'x';
while(fin)
{
if (c == '?')
count = count + 1;
fin >> c;
}
cout << count << endl;
ifstream fin("data.text");
int n = 5;
double x = 1.5;
char c = 'R';
| expression | type |
cin | |
fin | |
cin >> x | |
cin >> c && c != '.' | |
fin >> n ? n*0.5 : n*0.75 |
string fname;
cout << "Enter file name: ";
cin >> fname;
ifstream fin(fname);
int sum = 0, next;
while(fin >> next)
{
sum = sum + next;
}
cout << sum << endl;
If the
file named by the user consisted solely of the line
13,4,15what would the above program (once fixed!) output ?
Brown 71.8 Green 93.8 Jones 82.4 Smith 86.2 Worth 91.2Your program should work for any file in the same format, though you may hard-code the filename, rather than read it in from the user if you prefer.