1 |
h06 |
CS16 F17 |
Name: | ||||
---|---|---|---|---|
(as it would appear on official course roster) | ||||
Umail address: | @umail.ucsb.edu | |||
Optional: name you wish to be called if different from name above. | ||||
Optional: name of "homework buddy" (leaving this blank signifies "I worked alone") |
h06: File I/O and String Manipulation
ready? | assigned | due | points |
---|---|---|---|
true | Thu 11/02 02:00PM | Thu 11/09 02:00PM |
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
MAY ONLY BE TURNED IN IN THE LECTURE LISTED ABOVE AS THE DUE DATE. There is NO MAKEUP for missed assignments.
PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL!
-
1.(2 pts) What is the most important rule to remember if I want to use a function to read or write a file?
2.(3 pts) If I wanted my double type variables to be displayed in scientific notation, with a precision of 4 decimal places, and always have a plus (+) sign in front of positive numbers, what code should I include in my program before issuing a cout statement?
3.(5 pts) Show the output produced - be precise! - when the following line is executed (assume library
cout << "*" << setw(3) << 12345 << setw(3) << "*" << endl;
int pr_number(8);
for (int i = 0; i < 5; i++)
{
cout << "Project" << setw(2);
cout << pr_number++ << endl;
}
ifstream tin;
char c;
tin.open("t.txt");
tin.get(c);
while (!tin.eof())
{
if ( (c != 'e') && (c != 'C') ) cout << c;
tin.get(c);
} // end while
string name = "Porcupine Tree";
cout << "NAME = " + name << endl;
cout << name.length() << endl;
name.erase(8, 6);
cout << name << endl;
name.append("Dean WD Morgan");
cout << name << endl;
name.insert(22, "@TWD");
cout << name << endl;
name.replace(23, 3, "The WD");
cout << name << endl;
cout << name.find("WD") << endl;
cout << name.rfind("WD") << endl;
cout << name.rfind("cupi") << endl;
for (int i = name.length(); i > 20; i--)
cout << name[i-1];
cout << endl;