Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Identify and correct the errors in the code segments in Exercises a) through f) a) fstream myfile(info.dat); if(myfile) { cout < < Error in file

Identify and correct the errors in the code segments in Exercises a) through f)

a)

fstream myfile("info.dat");

if(myfile)

{

cout << "Error in file opening.";

exit(1);

}

b)

ifstream fstr;

fstr.open("A:\info.dat", ios::out);

c)

ofstream fout("comparts.dat");

if(fout.fail())

{

cerr<<"Error in file opening.";

exit(1);

}

fout.seekp(-2*sizeof(compart), ios::end);

fout.read((char*)&part.sizeof(compart));

d)

ifstream fin("info.dat", ios::app);

fin<

fin.close();

e)

ofstream fstr("info.dat");

fstr>>x>>y;

fstr.close();

f)

fout.seekg(n*sizeof(int),ios::cur);

fout<

2. State the output produced by the following program

#include

#include

using namespace std;

int main()

{

char *course="OOP USING C++", ch;

ofstream ftest1("test.dat");

ftest1<

ftest1.close();

ifstream ftest2("test.dat");

ftest2.seekg(-8, ios::end);

ch=ftest2.get(); //reads a character

cout<

ftest2.seekg(2, ios::cur);

ch=ftest2.get(); //reads a character

cout<

return 0;

}

3. True or char c1, c2, c3, c4;

1. We use the infile function to read input from the keyboard.

2. We use the infile function to read input from a file.

3. You must create a link between an external disk file and an

ifstream object before you can read your input data

4. It is good practice to close an input file when you need no

further access to the file.

5. It is not possible to make input errors with the

sophisticated C++ I/O system.

4. True or false, assuming

1. Space (ASCII value 32) can be treated as a char.

2. We must put space between characters when we type them in at

the keyboard.

3. If we have cin>>c1>>c2>>c3>>c4; and type in only three

characters, our program will crash.

4. All computers recognize ASCII code.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions