The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
here's next assignmentsÂ
chapter 11
chapter 12
Â
thanks
Chapter 11Create 5 files.Driver.cpp, f.h, f.cpp, g.h, g.cpp.f and g should implement a function called hello.Drivershould call hello from f and g.Example Output:hello from fhello from gPress any key to continue . . .Zip your source files before submitting.
Chapter 12Make a program that can write advice to a file.Your program should not require a data file to be presentwhen it is run.If a file needs to be created, your program should do so.According to ANSI standards, all compilers should operate the same way.Naturally they do not.DavidBusch one of my Spring 2011 students, managed to come up with code that worked with both MSVC++and DevC++.In MSVC++ his code:inStream.open("advice.txt");When no file is present, passes the test:// Does this file exist?if(!inStream.fail())// file exists...Because MS has decided to create a file if none exists.I believe this is not ANSI standard but is moreconvenient for a programmer.For DevC++, his code:if (!inStream.fail()){// file exists…here is code to read in the orginal advice.Of course in MSVC++ the file is empty.}else{// This file does NOT exist.inStream.close(); // close the input file streaminOutStream.open("advice.txt", ios::in | ios::out | ios::trunc);// create new file}Handles the case where no file exists and one must be created. I suggest using this approach since it iscompiler independent.Important:Note that there are 3 types of file streams, an ofstream only does output, an ifstream onlydoes input.If you want input and output on the same file you use an fstream.inStream.open("advice.txt",ios::app);will always cause an error if you declaredifstream inStream;Unfortunately, it will compile but will always fail at run time because you are trying to append to an inputstream.Example Output:First Run (Dev C++):Could not open Advice File.Assumption: first run - creating a new file...Enter your phrase for the next user:Never take advice from a programmer.Press any key to continue . . .Second Run(Dev C++)Found Advice File.Old Advice:Never take advice from a programmer.Enter your phrase for the next user:Ok I never will!Ooops, I just did.Press any key to continue . . .
Attachments: