C++ Assume these declarations for Question 3: int a; double b; char c; string na
ID: 3704655 • Letter: C
Question
C++
Assume these declarations for Question 3:
int a;
double b;
char c;
string name;
55 45.36<newline>Smith<newline>Jones.....
3. Indicate the contents of these variables after each of the following input operations is performed. Assume the file accessed by indata consists of the data shown and that each lettered group of operations occurs at the beginning of a program before any other data have been taken from the file.
a. indata >> a >> b >> name;
b. indata >> b >> a >> name;
c. indata >> a >> name >> c;
d. indata >> a;
getline ( indata, name );
Explanation / Answer
Answer is as follows :
In the given sample data
We have following values :
a = 55
b = 45.36
c = S , c is of char type and it will occupy only first letter of string Smith
name = Jones
so the answers of given parts are
a) indata >> a >> b >> name;
a = 55
b = 45.36
name = Jones
b) indata >> b >> a >> name;
b = 45.36
a = 55
name = Jones
a = 55
name = Jones
c = S
d)
indata >> a;
getline ( indata, name );
Here first we get a = 55
and with getline function access name from file indata
i.e. Jones
if there is any query please ask in comments...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.